aboutsummaryrefslogtreecommitdiff
path: root/misc/wasm
diff options
context:
space:
mode:
authorRichard Musiol <mail@richard-musiol.de>2018-10-18 15:53:38 +0200
committerRichard Musiol <neelance@gmail.com>2018-10-18 15:20:30 +0000
commit138bfc28090ccf03450cf02cb24f06b60f57cd3b (patch)
tree75745a6050a3086851e5c26b2c6410f973475ca6 /misc/wasm
parent8ccafb1ac732ab7994acb3c40786a0b943974554 (diff)
downloadgo-138bfc28090ccf03450cf02cb24f06b60f57cd3b.tar.gz
go-138bfc28090ccf03450cf02cb24f06b60f57cd3b.zip
syscall/js: make zero js.Value represent "undefined"
This commit changes the encoding of js.Value so that the zero js.Value represents the JavaScript value "undefined". This is what users intuitively expect. Specifically, the encodings of "undefined" and the number zero have been swapped. Fixes #27592. Change-Id: Icfc832c8cdf7a8a78bd69d20e00a04dbed0ccd10 Reviewed-on: https://go-review.googlesource.com/c/143137 Run-TryBot: Richard Musiol <neelance@gmail.com> 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.js17
1 files changed, 12 insertions, 5 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js
index 815b3fbeff..bd9754e53a 100644
--- a/misc/wasm/wasm_exec.js
+++ b/misc/wasm/wasm_exec.js
@@ -95,6 +95,9 @@
const loadValue = (addr) => {
const f = mem().getFloat64(addr, true);
+ if (f === 0) {
+ return undefined;
+ }
if (!isNaN(f)) {
return f;
}
@@ -112,14 +115,18 @@
mem().setUint32(addr, 0, true);
return;
}
+ if (v === 0) {
+ mem().setUint32(addr + 4, nanHead, true);
+ mem().setUint32(addr, 1, true);
+ return;
+ }
mem().setFloat64(addr, v, true);
return;
}
switch (v) {
case undefined:
- mem().setUint32(addr + 4, nanHead, true);
- mem().setUint32(addr, 1, true);
+ mem().setFloat64(addr, 0, true);
return;
case null:
mem().setUint32(addr + 4, nanHead, true);
@@ -334,7 +341,7 @@
this._inst = instance;
this._values = [ // TODO: garbage collection
NaN,
- undefined,
+ 0,
null,
true,
false,
@@ -396,14 +403,14 @@
}
static _makeCallbackHelper(id, pendingCallbacks, go) {
- return function() {
+ return function () {
pendingCallbacks.push({ id: id, args: arguments });
go._resolveCallbackPromise();
};
}
static _makeEventCallbackHelper(preventDefault, stopPropagation, stopImmediatePropagation, fn) {
- return function(event) {
+ return function (event) {
if (preventDefault) {
event.preventDefault();
}