arraybuffer_transfer.js 1.2 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 assertEquals(expected, actual) {
  6. if (expected != actual) {
  7. throw `Expected ${expected}, received ${actual}`;
  8. }
  9. }
  10. function arrayBufferAllocAndTransfer(initSize) {
  11. const UNDER_1GB = 0x3FFF0000;
  12. let buffers = [];
  13. const n = 10;
  14. for (let i = 0; i < n; i++) {
  15. try {
  16. const b = new Uint8Array(initSize);
  17. ArrayBuffer.transfer(b.buffer, UNDER_1GB);
  18. buffers.push(b);
  19. } catch (e) {
  20. return e;
  21. }
  22. }
  23. return new Error('OOM Expected');
  24. }
  25. assertEquals(1, WScript.Arguments.length);
  26. const INITIAL_SIZE = parseInt(WScript.Arguments[0]);
  27. let {name, message } = arrayBufferAllocAndTransfer(INITIAL_SIZE);
  28. assertEquals("Out of memory", message); //message check comes first to render test failures more intuitive
  29. assertEquals("Error", name);
  30. print ("PASSED");