oom_wasm.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. const n = 5;
  12. const ONE_GB_IN_PAGES = 0x4000;
  13. const instances = [];
  14. const module = new WebAssembly.Module(readbuffer('oom.wasm'));
  15. const sizeInBytes = initialSize * (1 << 16) /*64K*/;
  16. for (let i = 0; i < n; i++) {
  17. let memObj = new WebAssembly.Memory({initial:initialSize, maximum: ONE_GB_IN_PAGES});
  18. assertEquals(sizeInBytes, memObj.buffer.byteLength);
  19. let instance = new WebAssembly.Instance(module, { "dummy" : { "memory" : memObj } }).exports;
  20. assertEquals(initialSize, instance.size());
  21. let result = instance.grow(newSize);
  22. if (result == -1) {
  23. return 0;
  24. }
  25. instances.push(instance);
  26. }
  27. return 1;
  28. }
  29. assertEquals(2, WScript.Arguments.length);
  30. const INITIAL_SIZE = parseInt(WScript.Arguments[0]);
  31. const GROW_SIZE = parseInt(WScript.Arguments[1]);
  32. assertEquals(0, wasmAlloc(INITIAL_SIZE, GROW_SIZE));
  33. print ("PASSED");