bugs.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. function createView(bytes) {
  7. const buffer = new ArrayBuffer(bytes.length);
  8. const view = new Uint8Array(buffer);
  9. for (let i = 0; i < bytes.length; ++i) {
  10. view[i] = bytes.charCodeAt(i);
  11. }
  12. return view;
  13. }
  14. async function main() {
  15. const {instance: {exports: {foo}}} = await WebAssembly.instantiate(readbuffer("binaries/bug_fitsdword.wasm"));
  16. foo();
  17. try {
  18. new WebAssembly.Module(createView(`\x00asm\x0d\x00\x00\x00\xff\xff\xff\xff\x7f\x00\x00\x00`));
  19. console.log("Should have had an error");
  20. } catch (e) {
  21. if (!(e instanceof WebAssembly.CompileError)) {
  22. throw e;
  23. }
  24. }
  25. try {
  26. new WebAssembly.Module(createView(`\x00asm\x0d\x00\x00\x00\x7f\x00\x00\x00`));
  27. console.log("Should have had an error");
  28. } catch (e) {
  29. if (!(e instanceof WebAssembly.CompileError)) {
  30. throw e;
  31. }
  32. }
  33. {
  34. const mod = new WebAssembly.Module(readbuffer("binaries/bugDeferred.wasm"));
  35. const instance1 = new WebAssembly.Instance(mod);
  36. const instance2 = new WebAssembly.Instance(mod);
  37. // Change the type of the function on the first instance
  38. instance1.exports.foo.asdf = 5;
  39. instance1.exports.foo();
  40. // Make sure the entrypoint has been correctly updated on the second instance
  41. instance2.exports.foo();
  42. }
  43. }
  44. main().then(() => console.log("PASSED"), console.log);