diff options
author | Richard Musiol <mail@richard-musiol.de> | 2018-12-11 14:23:17 +0100 |
---|---|---|
committer | Brad Fitzpatrick <bradfitz@golang.org> | 2018-12-13 18:34:01 +0000 |
commit | 7d9649bf0d3acb8b83d966afa945db7f2188b753 (patch) | |
tree | 1a553c153f8c9d0ac0e3dac7669f6ba38bb27c95 /misc/wasm | |
parent | f95578cd5fa6035e2b253bcb1af3a18ad7352251 (diff) | |
download | go-7d9649bf0d3acb8b83d966afa945db7f2188b753.tar.gz go-7d9649bf0d3acb8b83d966afa945db7f2188b753.zip |
syscall/js: rename js.Callback to js.Func
The name "Callback" does not fit to all use cases of js.Callback.
This commit changes its name to Func. Accordingly NewCallback
gets renamed to FuncOf, which matches ValueOf and TypedArrayOf.
The package syscall/js is currently exempt from Go's compatibility
promise and js.Callback is already affected by a breaking change in
this release cycle. See #28711 for details.
Fixes #28711
Change-Id: I2c380970c3822bed6a3893909672c15d0cbe9da3
Reviewed-on: https://go-review.googlesource.com/c/153559
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Diffstat (limited to 'misc/wasm')
-rw-r--r-- | misc/wasm/wasm_exec.js | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js index 743eaf70b2..165d567750 100644 --- a/misc/wasm/wasm_exec.js +++ b/misc/wasm/wasm_exec.js @@ -87,8 +87,8 @@ this._exitPromise = new Promise((resolve) => { this._resolveExitPromise = resolve; }); - this._pendingCallback = null; - this._callbackTimeouts = new Map(); + this._pendingEvent = null; + this._scheduledTimeouts = new Map(); this._nextCallbackTimeoutID = 1; const mem = () => { @@ -204,7 +204,7 @@ this.importObject = { go: { // Go's SP does not change as long as no Go code is running. Some operations (e.g. calls, getters and setters) - // may trigger a synchronous callback to Go. This makes Go code get executed in the middle of the imported + // may synchronously trigger a Go event handler. This makes Go code get executed in the middle of the imported // function. A goroutine can switch to a new stack if the current stack is too small (see morestack function). // This changes the SP, thus we have to update the SP used by the imported function. @@ -238,22 +238,22 @@ mem().setInt32(sp + 16, (msec % 1000) * 1000000, true); }, - // func scheduleCallback(delay int64) int32 - "runtime.scheduleCallback": (sp) => { + // func scheduleTimeoutEvent(delay int64) int32 + "runtime.scheduleTimeoutEvent": (sp) => { const id = this._nextCallbackTimeoutID; this._nextCallbackTimeoutID++; - this._callbackTimeouts.set(id, setTimeout( + this._scheduledTimeouts.set(id, setTimeout( () => { this._resume(); }, getInt64(sp + 8) + 1, // setTimeout has been seen to fire up to 1 millisecond early )); mem().setInt32(sp + 16, id, true); }, - // func clearScheduledCallback(id int32) - "runtime.clearScheduledCallback": (sp) => { + // func clearTimeoutEvent(id int32) + "runtime.clearTimeoutEvent": (sp) => { const id = mem().getInt32(sp + 8, true); - clearTimeout(this._callbackTimeouts.get(id)); - this._callbackTimeouts.delete(id); + clearTimeout(this._scheduledTimeouts.get(id)); + this._scheduledTimeouts.delete(id); }, // func getRandomData(r []byte) @@ -420,7 +420,7 @@ _resume() { if (this.exited) { - throw new Error("bad callback: Go program has already exited"); + throw new Error("Go program has already exited"); } this._inst.exports.resume(); if (this.exited) { @@ -428,13 +428,13 @@ } } - _makeCallbackHelper(id) { + _makeFuncWrapper(id) { const go = this; return function () { - const cb = { id: id, this: this, args: arguments }; - go._pendingCallback = cb; + const event = { id: id, this: this, args: arguments }; + go._pendingEvent = event; go._resume(); - return cb.result; + return event.result; }; } } @@ -450,10 +450,10 @@ go.env = Object.assign({ TMPDIR: require("os").tmpdir() }, process.env); go.exit = process.exit; WebAssembly.instantiate(fs.readFileSync(process.argv[2]), go.importObject).then((result) => { - process.on("exit", (code) => { // Node.js exits if no callback is pending + process.on("exit", (code) => { // Node.js exits if no event handler is pending if (code === 0 && !go.exited) { // deadlock, make Go print error and stack traces - go._pendingCallback = { id: 0 }; + go._pendingEvent = { id: 0 }; go._resume(); } }); |