atomics_test.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  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 makeSharedArrayBuffer(length) {
  6. const pages = ((length / (64 * 1024))|0) + 1;
  7. const mem = new WebAssembly.Memory({initial: pages, maximum: pages, shared: true});
  8. if (!(mem.buffer instanceof SharedArrayBuffer)) {
  9. throw new Error("WebAssembly.Memory::buffer is not a SharedArrayBuffer");
  10. }
  11. return mem.buffer;
  12. }
  13. function modifyTests(tests) {
  14. return tests.map(test => {
  15. if (test.name !== "Atomics.wait index test") {
  16. return test;
  17. }
  18. test.body = () => {
  19. const length = ((64 * 1024)|0) / 4;
  20. var view = new Int32Array(makeSharedArrayBuffer(1));
  21. assert.doesNotThrow(() => Atomics.wait(view, 0, 0, 0), "Atomics.wait is allowed on the index 0, where the view's length is 2");
  22. assert.doesNotThrow(() => Atomics.wait(view, "0", 0, 0), "ToNumber : Atomics.wait is allowed on the index 0, where the view's length is 2");
  23. assert.throws(() => Atomics.wait(view, length, 0, 0), RangeError, "Index is greater than the view's length", "Access index is out of range");
  24. assert.throws(() => Atomics.wait(view, -1, 0, 0), RangeError, "Negative index is not allowed", "Access index is out of range");
  25. };
  26. return test;
  27. });
  28. }
  29. // Test to make sure we are able to create the WebAssemblySharedArrayBuffer
  30. makeSharedArrayBuffer(0);
  31. WScript.LoadScriptFile("../es7/atomics_test.js");