fastarray.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  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. function checkTrap(fn) {
  6. try {
  7. fn();
  8. console.log("Should have trapped");
  9. } catch (e) {
  10. if (!(e instanceof WebAssembly.RuntimeError)) {
  11. console.log(e);
  12. }
  13. }
  14. }
  15. function runScenario() {
  16. const module = new WebAssembly.Module(readbuffer("binaries/fastarray.wasm"));
  17. const {exports: {load, store, mem}} = new WebAssembly.Instance(module);
  18. function test() {
  19. checkTrap(() => load(0));
  20. checkTrap(() => load(0xFF));
  21. checkTrap(() => load(0xFFFFFFFF));
  22. checkTrap(() => store(0));
  23. checkTrap(() => store(0xFF));
  24. checkTrap(() => store(0xFFFFFFFF));
  25. }
  26. test();
  27. mem.grow(5);
  28. test();
  29. mem.grow(2);
  30. test();
  31. }
  32. runScenario();
  33. console.log("PASSED");