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
misc/wasm: possible bug in InstanceOf #36561
Comments
It's also possible this is a quirk of the TypeScript compiler and the code is correct. The TypeScript compiler seems to think the signature for setUint8(byteOffset: number, value: number): void |
Can you just add a ternary to appease TypeScript? diff --git a/misc/wasm/wasm_exec.js b/misc/wasm/wasm_exec.js
index bb66cf254d..5ac4032993 100644
--- a/misc/wasm/wasm_exec.js
+++ b/misc/wasm/wasm_exec.js
@@ -440,7 +440,7 @@
// func valueInstanceOf(v ref, t ref) bool
"syscall/js.valueInstanceOf": (sp) => {
- this.mem.setUint8(sp + 24, loadValue(sp + 8) instanceof loadValue(sp + 16));
+ this.mem.setUint8(sp + 24, (loadValue(sp + 8) instanceof loadValue(sp + 16)) ? 1 : 0);
},
// func copyBytesToGo(dst []byte, src ref) (int, bool) |
Change https://golang.org/cl/214944 mentions this issue: |
@bradfitz Thanks for the reply. Ah I see. Seems like you were relying on type coercion to convert Still, it is generally considered bad practice in JavaScript to rely on this behavior, and there's a reason the TypeScript compiler complains about it. I was going to suggest a change, but I already see there's a proposed CL to fix it. Feel free to close this issue if you want. |
@albrow, I'll submit my change when the Go 1.15 tree opens. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes, judging by the contents of the
master
branch.What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
I am converting wasm_exec.js to TypeScript for bundling in a TypeScript library. I noticed this compiler error:
What did you expect to see?
I don't expect this file to compile since it wasn't written with TypeScript in mind. I was surprised by this particular error because it looks like a type mismatch.
I think there might be a mistake on this line. I believe it is supposed to be written as:(Update: Sorry, I realized my suggestion is probably not correct).
What did you see instead?
The code doesn't compile in TypeScript, I think due to a mismatched parentheses. If that's true, I believe this would result in a bug/incorrect behavior in
syscall/js.InstanceOf
.The text was updated successfully, but these errors were encountered: