-
Notifications
You must be signed in to change notification settings - Fork 30k
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
wasi.start() throws type error #33415
Comments
Jest runs your code in a VM sandbox (think When your code calls out to the outer context, the I think that check and the Do you want to open a PR? It should come with tests in |
Glad I wasn't crazy. I had to implement a very hacky workaround for my testing software involving obtaining all the symbols directly and calling the setMemory function directly. I suppose I could submit a lib/wasi.js fix for this. Might need some help with making the tests. |
@bnoordhuis , I'm a first time contributer. Is there any chance I could get some help with starting my pull request? Edit: Actually, my computer has only about 3 gigs worth of space left on it, and compiling all the test modules seems to eat it all up. I'm currently doing most of my dev work on a microsoft surface, so I won't be able to contribute to fix this. |
Instances coming from different VM contexts don't pass `instanceof` type checks because each context has its own copy of the built-in globals. After review of the relevant code it seems like it should be safe to relax the type check and that is what this commit does: `wasi.start()` now accepts any input that walks and quacks like a WebAssembly.Instance or WebAssembly.Memory instance. Fixes: nodejs#33415
No problem. I've opened #33431. |
Workaround is not fun, but it's doable. wasi.start = jest.fn((instance) => {
const symbols = Object.getOwnPropertySymbols(wasi);
const kStartedSymbol = symbols.filter((symbol) =>
symbol.toString().includes("kStarted"),
)[0];
const setMemorySymbol = symbols.filter((symbol) =>
symbol.toString().includes("setMemory"),
)[0];
wasi[setMemorySymbol](instance.exports.memory);
wasi[kStartedSymbol] = true;
instance.exports._start();
}); I hope this helps someone in the meantime. |
Instances coming from different VM contexts don't pass `instanceof` type checks because each context has its own copy of the built-in globals. After review of the relevant code it seems like it should be safe to relax the type check and that is what this commit does: `wasi.start()` now accepts any input that walks and quacks like a WebAssembly.Instance or WebAssembly.Memory instance. Fixes: #33415 PR-URL: #33431 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Instances coming from different VM contexts don't pass `instanceof` type checks because each context has its own copy of the built-in globals. After review of the relevant code it seems like it should be safe to relax the type check and that is what this commit does: `wasi.start()` now accepts any input that walks and quacks like a WebAssembly.Instance or WebAssembly.Memory instance. Fixes: #33415 PR-URL: #33431 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Instances coming from different VM contexts don't pass `instanceof` type checks because each context has its own copy of the built-in globals. After review of the relevant code it seems like it should be safe to relax the type check and that is what this commit does: `wasi.start()` now accepts any input that walks and quacks like a WebAssembly.Instance or WebAssembly.Memory instance. Fixes: #33415 PR-URL: #33431 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
Instances coming from different VM contexts don't pass `instanceof` type checks because each context has its own copy of the built-in globals. After review of the relevant code it seems like it should be safe to relax the type check and that is what this commit does: `wasi.start()` now accepts any input that walks and quacks like a WebAssembly.Instance or WebAssembly.Memory instance. Fixes: #33415 PR-URL: #33431 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]>
What steps will reproduce the bug?
I am not sure exactly how to reproduce this bug, but when I use
jest
, I run the following code.How often does it reproduce? Is there a required condition?
I doubt this is jest related, and it looks like
wasi
seems to have a different version ofWebAssembly.Instance
, because it logs true.Related question: Is it possible that
jest
would modify theWebAssembly
class?What is the expected behavior?
I suppose that the module shouldn't throw an error, because it appears to be an instance of an
Instance
.What do you see instead?
Additional information
I will be happy to help debug this, but it's currently 3am. Will update this with an appropriate script to replicate this without jest.
EDIT: Removed postfix
!
operators because they are typescript related. Whoops.The text was updated successfully, but these errors were encountered: