aboutsummaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorHajime Hoshi <hajimehoshi@gmail.com>2020-05-06 23:00:58 +0900
committerHajime Hoshi <hajimehoshi@gmail.com>2020-05-12 15:01:56 +0000
commita0698a6b60952f80e2136df0699325b657ea0def (patch)
treeb79f15bf02fcfe68161061ccdf4a419adb50bf0c /misc
parent8c1db77a92b1d17d3fe07999c5f20602a2080be9 (diff)
downloadgo-a0698a6b60952f80e2136df0699325b657ea0def.tar.gz
go-a0698a6b60952f80e2136df0699325b657ea0def.zip
syscall/js: prepare IDs for the preset objects
Fixes #38899 Change-Id: Ib8131c3078c60dc3fe2cf0eaac45b25a4f6e4649 Reviewed-on: https://go-review.googlesource.com/c/go/+/232518 Run-TryBot: Hajime Hoshi <hajimehoshi@gmail.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Richard Musiol <neelance@gmail.com>
Diffstat (limited to 'misc')
-rw-r--r--misc/wasm/wasm_exec.js48
1 files changed, 21 insertions, 27 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js
index a99aaeda07..8501ae7cd8 100644
--- a/misc/wasm/wasm_exec.js
+++ b/misc/wasm/wasm_exec.js
@@ -175,37 +175,19 @@
const storeValue = (addr, v) => {
const nanHead = 0x7FF80000;
- if (typeof v === "number") {
+ if (typeof v === "number" && v !== 0) {
if (isNaN(v)) {
this.mem.setUint32(addr + 4, nanHead, true);
this.mem.setUint32(addr, 0, true);
return;
}
- if (v === 0) {
- this.mem.setUint32(addr + 4, nanHead, true);
- this.mem.setUint32(addr, 1, true);
- return;
- }
this.mem.setFloat64(addr, v, true);
return;
}
- switch (v) {
- case undefined:
- this.mem.setFloat64(addr, 0, true);
- return;
- case null:
- this.mem.setUint32(addr + 4, nanHead, true);
- this.mem.setUint32(addr, 2, true);
- return;
- case true:
- this.mem.setUint32(addr + 4, nanHead, true);
- this.mem.setUint32(addr, 3, true);
- return;
- case false:
- this.mem.setUint32(addr + 4, nanHead, true);
- this.mem.setUint32(addr, 4, true);
- return;
+ if (v === undefined) {
+ this.mem.setFloat64(addr, 0, true);
+ return;
}
let id = this._ids.get(v);
@@ -219,8 +201,13 @@
this._ids.set(v, id);
}
this._goRefCounts[id]++;
- let typeFlag = 1;
+ let typeFlag = 0;
switch (typeof v) {
+ case "object":
+ if (v !== null) {
+ typeFlag = 1;
+ }
+ break;
case "string":
typeFlag = 2;
break;
@@ -493,10 +480,17 @@
global,
this,
];
- this._goRefCounts = []; // number of references that Go has to a JS value, indexed by reference id
- this._ids = new Map(); // mapping from JS values to reference ids
- this._idPool = []; // unused ids that have been garbage collected
- this.exited = false; // whether the Go program has exited
+ this._goRefCounts = new Array(this._values.length).fill(Infinity); // number of references that Go has to a JS value, indexed by reference id
+ this._ids = new Map([ // mapping from JS values to reference ids
+ [0, 1],
+ [null, 2],
+ [true, 3],
+ [false, 4],
+ [global, 5],
+ [this, 6],
+ ]);
+ this._idPool = []; // unused ids that have been garbage collected
+ this.exited = false; // whether the Go program has exited
// Pass command line arguments and environment variables to WebAssembly by writing them to the linear memory.
let offset = 4096;