aboutsummaryrefslogtreecommitdiff
path: root/misc/wasm/wasm_exec.js
diff options
context:
space:
mode:
authorPaul Jolly <paul@myitcv.io>2018-07-02 08:08:14 +0100
committerPaul Jolly <paul@myitcv.org.uk>2018-07-03 20:45:17 +0000
commitabaf53fb8e7dfbb9d513745e8280488b159ceb1e (patch)
treec07042ee0bdfb8c20c0102d601f292c4570b4813 /misc/wasm/wasm_exec.js
parent5d4f0474ecb322135612813eadf22db78309b33f (diff)
downloadgo-abaf53fb8e7dfbb9d513745e8280488b159ceb1e.tar.xz
misc/wasm: use single map for string, symbol and object id mapping.
Currently we use a globally unique symbol property on objects that get passed from JavaScript to Go to store a unique ID that Go then uses when referring back to the JavaScript object (via js.Value.ref). This approach fails however when a JavaScript object cannot be modified, i.e. cannot have new properties added or is frozen. The test that is added as part of this commit currently fails with: Cannot add property Symbol(), object is not extensible Instead we consolidate the string, symbol and object unique ID mapping into a single map. Map key equality is determined via strict equality, which is the semantic we want in this situation. Change-Id: Ieb2b50fc36d3c30e148aa7a41557f3c59cd33766 Reviewed-on: https://go-review.googlesource.com/121799 Run-TryBot: Paul Jolly <paul@myitcv.org.uk> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Richard Musiol <neelance@gmail.com>
Diffstat (limited to 'misc/wasm/wasm_exec.js')
-rw-r--r--misc/wasm/wasm_exec.js32
1 files changed, 4 insertions, 28 deletions
diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js
index 3617c49866..7246d7bc71 100644
--- a/misc/wasm/wasm_exec.js
+++ b/misc/wasm/wasm_exec.js
@@ -118,33 +118,11 @@
return;
}
- if (typeof v === "string") {
- let ref = this._stringRefs.get(v);
- if (ref === undefined) {
- ref = this._values.length;
- this._values.push(v);
- this._stringRefs.set(v, ref);
- }
- mem().setUint32(addr, ref, true);
- return;
- }
-
- if (typeof v === "symbol") {
- let ref = this._symbolRefs.get(v);
- if (ref === undefined) {
- ref = this._values.length;
- this._values.push(v);
- this._symbolRefs.set(v, ref);
- }
- mem().setUint32(addr, ref, true);
- return;
- }
-
- let ref = v[this._refProp];
- if (ref === undefined || this._values[ref] !== v) {
+ let ref = this._refs.get(v);
+ if (ref === undefined) {
ref = this._values.length;
this._values.push(v);
- v[this._refProp] = ref;
+ this._refs.set(v, ref);
}
mem().setUint32(addr, ref, true);
}
@@ -335,9 +313,7 @@
setTimeout(this._resolveCallbackPromise, 0); // make sure it is asynchronous
},
];
- this._stringRefs = new Map();
- this._symbolRefs = new Map();
- this._refProp = Symbol();
+ this._refs = new Map();
this.exited = false;
const mem = new DataView(this._inst.exports.mem.buffer)