oom.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 assertEquals(expected, actual) {
  6. if (expected != actual) {
  7. throw `Expected ${expected}, received ${actual}`;
  8. }
  9. }
  10. function wasmAlloc(initialSize, newSize) {
  11. let memories = [];
  12. const n = 5;
  13. for (let i = 0; i < n; i++) {
  14. try {
  15. let m = new WebAssembly.Memory({initial:initialSize});
  16. assertEquals(initialSize * (1 << 16) /*64K*/, m.buffer.byteLength);
  17. m.grow(newSize);
  18. memories.push(m);
  19. } catch (e) {
  20. return e;
  21. }
  22. }
  23. return new Error('OOM Expected');
  24. }
  25. assertEquals(2, WScript.Arguments.length);
  26. const INITIAL_SIZE = parseInt(WScript.Arguments[0]);
  27. const GROW_SIZE = parseInt(WScript.Arguments[1]);
  28. let {name, message } = wasmAlloc(INITIAL_SIZE, GROW_SIZE);
  29. assertEquals("argument out of range", message); //message check comes first to render test failures more intuitive
  30. assertEquals("RangeError", name);
  31. print ("PASSED");