-
Notifications
You must be signed in to change notification settings - Fork 18k
syscall/js: illegal invocation error on (js.Value).Call
#26143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
CC @neelance |
(CC @cherrymui) |
It looks to me the problem is that for each Javascript object that returns to Go as a js.Value, we associate the ref id to it, but if that ref id is copied or inherited to other object, getting value by ref id would get the wrong object. In this particular case, it first gets in prototype in init, which gets a ref id associate to it. The ref id then gets inherited by the context object. |
Change https://golang.org/cl/121835 mentions this issue: |
Thank you taking care of this. The root cause was a JavaScript behavior that: const m = new Map();
const a = Object.prototype;
m[a] = 'This is a'
const b = {};
console.log(m[b]); shows 'This is a' in JavaScript? I didn't know that... |
@hajimehoshi The code you wrote above is equivalent to: const m = new Map();
const a = Object.prototype;
m[String(a)] = 'This is a'
const b = {};
console.log(m[String(b)]); and |
Yes thank you, |
Rather, the root cause of this issue is const _refProp = Symbol();
Object.prototype[_refProp] = 1;
console.log({}[_refProp]); // Shows 1 ? |
Yes, properties on a prototype show on its instances. The CL above will fix this. |
Thank you for clarifying. JavaScript is hard... |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
With
misc/wasm/wasm_exec.js
in the commit 8997ec1, prepareindex.html
and
test.wasm
fromtest.go
and see
index.html
via an HTTP server.What did you expect to see?
No error.
What did you see instead?
Bisecting says that 8997ec1 is the culprit.
EDIT: Interestingly, the error doesn't happen (and deadlock error happens instead) without
init
function.The text was updated successfully, but these errors were encountered: