Skip to content

Commit 28f9b88

Browse files
committed
misc/wasm: make sure value ref id is unique
For each Javascript object that returns to Go as a js.Value, we associate the ref id to it. But if this ref id is copied or inherited to other object, it would mess up the ref-object mapping. In storeValue, make sure the object is indeed the one we are storing. Otherwise allocate a new ref id. Fixes #26143. Change-Id: Ie60bb2f8d1533da1bbe6f46045866515ec2af5a9 Reviewed-on: https://go-review.googlesource.com/121835 Run-TryBot: Cherry Zhang <cherryyz@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Richard Musiol <neelance@gmail.com>
1 parent 6780042 commit 28f9b88

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

misc/wasm/wasm_exec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@
141141
}
142142

143143
let ref = v[this._refProp];
144-
if (ref === undefined) {
144+
if (ref === undefined || this._values[ref] !== v) {
145145
ref = this._values.length;
146146
this._values.push(v);
147147
v[this._refProp] = ref;

src/syscall/js/js_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,13 @@ func TestObject(t *testing.T) {
107107
if dummys.Get("someArray") != dummys.Get("someArray") {
108108
t.Errorf("same value not equal")
109109
}
110+
111+
// An object and its prototype should not be equal.
112+
proto := js.Global().Get("Object").Get("prototype")
113+
o := js.Global().Call("eval", "new Object()")
114+
if proto == o {
115+
t.Errorf("object equals to its prototype")
116+
}
110117
}
111118

112119
func TestTypedArrayOf(t *testing.T) {

0 commit comments

Comments
 (0)