bugs.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //-------------------------------------------------------------------------------------------------------
  2. // Copyright (C) Microsoft Corporation and contributors. All rights reserved.
  3. // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
  4. //-------------------------------------------------------------------------------------------------------
  5. WScript.Flag("-wasmI64");
  6. WScript.Flag("-wasmcheckversion-");
  7. function createView(bytes) {
  8. const buffer = new ArrayBuffer(bytes.length);
  9. const view = new Uint8Array(buffer);
  10. for (let i = 0; i < bytes.length; ++i) {
  11. view[i] = bytes.charCodeAt(i);
  12. }
  13. return view;
  14. }
  15. async function main() {
  16. const {instance: {exports: {foo, bar}}} = await WebAssembly.instantiate(WebAssembly.wabt.convertWast2Wasm(`
  17. (module
  18. (func (export "foo") (result i64) (i64.extend_u/i32 (i32.const 0x80000000)))
  19. (func (export "bar") (result i64) (i64.extend_u/i32 (i32.const 0xabcdef12)))
  20. )`));
  21. foo();
  22. bar();
  23. try {
  24. new WebAssembly.Module(createView(`\x00asm\x01\x00\x00\x00\x3f\xff\xff\xff\x7f\x00\x00\x00`));
  25. console.log("Should have had an error");
  26. } catch (e) {
  27. if (!(e instanceof WebAssembly.CompileError && e.message.includes("Invalid known section opcode"))) {
  28. throw e;
  29. }
  30. }
  31. try {
  32. new WebAssembly.Module(createView(`\x00asm\x01\x00\x00\x00\x7f\x00\x00\x00`));
  33. console.log("Should have had an error");
  34. } catch (e) {
  35. if (!(e instanceof WebAssembly.CompileError && e.message.includes("Invalid known section opcode"))) {
  36. throw e;
  37. }
  38. }
  39. {
  40. const mod = new WebAssembly.Module(WebAssembly.wabt.convertWast2Wasm(`
  41. (module
  42. (func (export "foo") (result i32) (i32.const 0))
  43. )`));
  44. const instance1 = new WebAssembly.Instance(mod);
  45. const instance2 = new WebAssembly.Instance(mod);
  46. // Change the type of the function on the first instance
  47. instance1.exports.foo.asdf = 5;
  48. instance1.exports.foo();
  49. // Make sure the entrypoint has been correctly updated on the second instance
  50. instance2.exports.foo();
  51. }
  52. }
  53. main().then(() => console.log("PASSED"), err => {
  54. console.log(err.stack);
  55. });