diff options
| author | Paul Jolly <paul@myitcv.io> | 2018-07-02 08:08:14 +0100 |
|---|---|---|
| committer | Paul Jolly <paul@myitcv.org.uk> | 2018-07-03 20:45:17 +0000 |
| commit | abaf53fb8e7dfbb9d513745e8280488b159ceb1e (patch) | |
| tree | c07042ee0bdfb8c20c0102d601f292c4570b4813 /src | |
| parent | 5d4f0474ecb322135612813eadf22db78309b33f (diff) | |
| download | go-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 'src')
| -rw-r--r-- | src/syscall/js/js_test.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/syscall/js/js_test.go b/src/syscall/js/js_test.go index c4141c2196..69b5209821 100644 --- a/src/syscall/js/js_test.go +++ b/src/syscall/js/js_test.go @@ -116,6 +116,14 @@ func TestObject(t *testing.T) { } } +func TestFrozenObject(t *testing.T) { + o := js.Global().Call("eval", "(function () { let o = new Object(); o.field = 5; Object.freeze(o); return o; })()") + want := 5 + if got := o.Get("field").Int(); want != got { + t.Errorf("got %#v, want %#v", got, want) + } +} + func TestTypedArrayOf(t *testing.T) { testTypedArrayOf(t, "[]int8", []int8{0, -42, 0}, -42) testTypedArrayOf(t, "[]int16", []int16{0, -42, 0}, -42) |
