SharedArrayBuffer and Atomics tests (#839)

This commit is contained in:
Shu-yu Guo 2017-02-07 08:17:31 -08:00 committed by Leo Balter
parent 204266794c
commit a72ee6d912
240 changed files with 7200 additions and 0 deletions

View File

@ -60,6 +60,33 @@ properties of the global scope prior to test execution.
- **`global`** - a reference to the global object on which `$` was initially
defined
- **`agent`** - an ordinary object with the following properties:
- **`start`** - a function that takes a script source string and runs
the script in a concurrent agent. Will block until that agent is
running. The agent has no representation. The agent script will be
run in an environment that has an object `$` with a property `agent`
with the following properties:
- **`receiveBroadcast`** - a function that takes a function and
calls the function when it has received a broadcast from the parent,
passing it the broadcast as two arguments, a SharedArrayBuffer and
an Int32. This function may return before a broadcast is received
(eg to return to an event loop to await a message) and no code should
follow the call to this function.
- **`report`** - a function that takes a string and places it in a
transmit queue whence the parent will retrieve it. Messages
should be short.
- **`sleep`** - a function that takes a millisecond argument and
sleeps the agent for approximately that duration.
- **`leaving`** - a function that signals that the agent is done and
may be terminated (if possible).
- **`broadcast`** - a function that takes a SharedArrayBuffer and an Int32
and broadcasts the two values to all concurrent agents. The function
blocks until all agents have retrieved the message. Note, this assumes
that all agents that were started are still running.
- **`getReport`** - a function that reads an incoming string from any agent,
and returns it if it exists, or returns `null` otherwise.
- **`sleep`** - a function that takes a millisecond argument and
sleeps the execution for approximately that duration.
### Strict Mode

4
harness/atomicsHelper.js Normal file
View File

@ -0,0 +1,4 @@
// The amount of slack allowed for testing time-related Atomics methods (i.e.
// wait and wake). The absolute value of the difference of the observed time
// and the expected time must be epsilon-close.
var $ATOMICS_MAX_TIME_EPSILON = 100;

110
harness/testAtomics.js Normal file
View File

@ -0,0 +1,110 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/**
* Calls the provided function for a each bad index that should throw a
* RangeError when passed to an Atomics method on a SAB-backed view where
* index 125 is out of range.
*
* @param f - the function to call for each bad index.
*/
function testWithAtomicsOutOfBoundsIndices(f) {
var bad_indices = [
(view) => -1,
(view) => view.length,
(view) => view.length*2,
(view) => undefined,
(view) => Number.NaN,
(view) => Number.POSITIVE_INFINITY,
(view) => Number.NEGATIVE_INFINITY,
(view) => '3.5',
(view) => 3.5,
(view) => { password: "qumquat" },
(view) => ({ valueOf: () => 125 }),
(view) => ({ toString: () => '125', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
for (let IdxGen of bad_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
}
}
/**
* Calls the provided function for each good index that should not throw when
* passed to an Atomics method on a SAB-backed view.
*
* @param f - the function to call for each good index.
*/
function testWithAtomicsInBoundsIndices(f) {
var good_indices = [
(view) => 0/-1, // -0
(view) => '-0',
(view) => view.length - 1,
(view) => ({ valueOf: () => 0 }),
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
for (let IdxGen of good_indices) {
try {
f(IdxGen);
} catch (e) {
e.message += " (Testing with index gen " + IdxGen + ".)";
throw e;
}
}
}
/**
* Calls the provided function for each value that should throw a TypeError
* when passed to an Atomics method as a view.
*
* @param f - the function to call for each non-view value.
*/
function testWithAtomicsNonViewValues(f) {
var values = [
null,
undefined,
true,
false,
new Boolean(true),
10,
3.14,
new Number(4),
"Hi there",
new Date,
/a*utomaton/g,
{ password: "qumquat" },
new DataView(new ArrayBuffer(10)),
new ArrayBuffer(128),
new SharedArrayBuffer(128),
new Error("Ouch"),
[1,1,2,3,5,8],
((x) => -x),
new Map(),
new Set(),
new WeakMap(),
new WeakSet(),
Symbol("halleluja"),
// TODO: Proxy?
Object,
Int32Array,
Date,
Math,
Atomics
];
for (let nonView of values) {
try {
f(nonView);
} catch (e) {
e.message += " (Testing with non-view value " + nonView + ".)";
throw e;
}
}
}

View File

@ -0,0 +1,16 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-get-arraybuffer.prototype.bytelength
description: Throws a TypeError exception when `this` is a SharedArrayBuffer
---*/
var getter = Object.getOwnPropertyDescriptor(
ArrayBuffer.prototype, "byteLength"
).get;
assert.throws(TypeError, function() {
var sab = new SharedArrayBuffer(4);
getter.call(sab);
}, "`this` cannot be a SharedArrayBuffer");

View File

@ -0,0 +1,13 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-arraybuffer.prototype.slice
description: >
Throws a TypeError if `this` is a SharedArrayBuffer
---*/
assert.throws(TypeError, function() {
var sab = new SharedArrayBuffer(0);
ArrayBuffer.prototype.slice.call(sab);
}, "`this` value cannot be a SharedArrayBuffer");

View File

@ -0,0 +1,20 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
`Symbol.toStringTag` property descriptor on Atomics
info: >
The initial value of the @@toStringTag property is the String value
"Atomics".
This property has the attributes { [[Writable]]: false, [[Enumerable]]:
false, [[Configurable]]: true }.
includes: [propertyHelper.js]
features: [Symbol.toStringTag]
---*/
assert.sameValue(Atomics[Symbol.toStringTag], 'Atomics');
verifyNotEnumerable(Atomics, Symbol.toStringTag);
verifyNotWritable(Atomics, Symbol.toStringTag);
verifyConfigurable(Atomics, Symbol.toStringTag);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.add on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.add(view, Idx, 10));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.add
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "add");
verifyNotEnumerable(Atomics, "add");
verifyConfigurable(Atomics, "add");

View File

@ -0,0 +1,53 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.add on arrays that allow atomic operations.
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
// Add positive number
view[8] = 0;
assert.sameValue(Atomics.add(view, 8, 10), 0);
assert.sameValue(view[8], 10);
// Add negative number
assert.sameValue(Atomics.add(view, 8, -5), 10);
assert.sameValue(view[8], 5);
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is negative and subject to coercion");
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is subject to chopping");
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.add(view, 3, 0), control[0],
"Result is subject to chopping");
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.add(view, Idx, 0), 37);
});
}, int_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.add.length is 3.
info: >
Atomics.add ( ia, index, val )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.add.length, 3);
verifyNotEnumerable(Atomics.add, "length");
verifyNotWritable(Atomics.add, "length");
verifyConfigurable(Atomics.add, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.add.name is "add".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.add.name, "add");
verifyNotEnumerable(Atomics.add, "name");
verifyNotWritable(Atomics.add, "name");
verifyConfigurable(Atomics.add, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.add on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.add(view, 0, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.add on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.add(view, 0, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.add on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.add(view, 0, 0)));
}, other_views);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.and on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.and(view, Idx, 10));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.and
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "and");
verifyNotEnumerable(Atomics, "and");
verifyConfigurable(Atomics, "and");

View File

@ -0,0 +1,60 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.and on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
view[8] = 0x33333333;
control[0] = 0x33333333;
assert.sameValue(Atomics.and(view, 8, 0x55555555), control[0],
"Result is subject to chopping");
control[0] = 0x11111111;
assert.sameValue(view[8], control[0]);
assert.sameValue(Atomics.and(view, 8, 0xF0F0F0F0), control[0],
"Result is subject to chopping");
control[0] = 0x10101010;
assert.sameValue(view[8], control[0]);
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.and(view, 3, 0), control[0],
"Result is negative and subject to coercion");
assert.sameValue(view[3], 0);
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.and(view, 3, 0), control[0],
"Result is subjective to chopping");
assert.sameValue(view[3], 0);
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.and(view, 3, 0), control[0],
"Result is subjective to chopping");
assert.sameValue(view[3], 0);
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.and(view, Idx, 0), 37);
});
}, int_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.and.length is 3.
info: >
Atomics.and ( ia, index, val )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.and.length, 3);
verifyNotEnumerable(Atomics.and, "length");
verifyNotWritable(Atomics.and, "length");
verifyConfigurable(Atomics.and, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.and.name is "and".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.and.name, "and");
verifyNotEnumerable(Atomics.and, "name");
verifyNotWritable(Atomics.and, "name");
verifyConfigurable(Atomics.and, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.and on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.and(view, 0, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.and on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.and(view, 0, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.and on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.and(view, 0, 0)));
}, other_views);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.compareExchange on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.compareExchange(view, Idx, 10, 0));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.compareExchange
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "compareExchange");
verifyNotEnumerable(Atomics, "compareExchange");
verifyConfigurable(Atomics, "compareExchange");

View File

@ -0,0 +1,72 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.compareExchange on arrays that allow atomic operations.
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
var good_indices = [ (view) => 0/-1, // -0
(view) => '-0',
(view) => view.length - 1,
(view) => ({ valueOf: () => 0 }),
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
// Performs the exchange
view[8] = 0;
assert.sameValue(Atomics.compareExchange(view, 8, 0, 10), 0);
assert.sameValue(view[8], 10);
view[8] = 0;
assert.sameValue(Atomics.compareExchange(view, 8, 1, 10), 0,
"Does not perform the exchange");
assert.sameValue(view[8], 0);
view[8] = 0;
assert.sameValue(Atomics.compareExchange(view, 8, 0, -5), 0,
"Performs the exchange, coercing the value being stored");
control[0] = -5;
assert.sameValue(view[8], control[0]);
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.compareExchange(view, 3, -5, 0), control[0],
"Performs the exchange, coercing the value being tested");
assert.sameValue(view[3], 0);
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.compareExchange(view, 3, 12345, 0), control[0],
"Performs the exchange, chopping the value being tested");
assert.sameValue(view[3], 0);
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.compareExchange(view, 3, 123456789, 0), control[0],
"Performs the exchange, chopping the value being tested");
assert.sameValue(view[3], 0);
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.compareExchange(view, Idx, 37, 0), 37);
});
}, int_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.compareExchange.length is 4.
info: >
Atomics.compareExchange ( ia, index, expect, replace )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.compareExchange.length, 4);
verifyNotEnumerable(Atomics.compareExchange, "length");
verifyNotWritable(Atomics.compareExchange, "length");
verifyConfigurable(Atomics.compareExchange, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.compareExchange.name is "compareExchange".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.compareExchange.name, "compareExchange");
verifyNotEnumerable(Atomics.compareExchange, "name");
verifyNotWritable(Atomics.compareExchange, "name");
verifyConfigurable(Atomics.compareExchange, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.compareExchange on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.compareExchange(view, 0, 0, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.compareExchange on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.compareExchange(view, 0, 0, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.compareExchange on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.compareExchange(view, 0, 0, 0)));
}, other_views);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.exchange on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.exchange(view, Idx, 10, 0));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.exchange
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "exchange");
verifyNotEnumerable(Atomics, "exchange");
verifyConfigurable(Atomics, "exchange");

View File

@ -0,0 +1,54 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.exchange on arrays that allow atomic operations.
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
view[8] = 0;
assert.sameValue(Atomics.exchange(view, 8, 10), 0,
"Exchange returns the value previously in the array");
assert.sameValue(view[8], 10);
assert.sameValue(Atomics.exchange(view, 8, -5), 10,
"Exchange returns the value previously in the array");
control[0] = -5;
assert.sameValue(view[8], control[0]);
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
"Result is subject to coercion");
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
"Result is subject to chopping");
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.exchange(view, 3, 0), control[0],
"Result is subject to chopping");
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.exchange(view, Idx, 0), 37);
});
}, int_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.exchange.length is 3.
info: >
Atomics.exchange ( ia, index, val )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.exchange.length, 3);
verifyNotEnumerable(Atomics.exchange, "length");
verifyNotWritable(Atomics.exchange, "length");
verifyConfigurable(Atomics.exchange, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.exchange.name is "exchange".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.exchange.name, "exchange");
verifyNotEnumerable(Atomics.exchange, "name");
verifyNotWritable(Atomics.exchange, "name");
verifyConfigurable(Atomics.exchange, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.exchange on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.exchange(view, 0, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.exchange on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.exchange(view, 0, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.exchange on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.exchange(view, 0, 0)));
}, other_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test isLockFree on various non-intuitive arguments
---*/
assert.sameValue(false, Atomics.isLockFree(hide(3, Number.NaN)));
assert.sameValue(false, Atomics.isLockFree(hide(3, -1)));
assert.sameValue(false, Atomics.isLockFree(hide(3, 3.14)));
assert.sameValue(false, Atomics.isLockFree(hide(3, 0)));
assert.sameValue(Atomics.isLockFree('1'), Atomics.isLockFree(1));
assert.sameValue(Atomics.isLockFree('3'), Atomics.isLockFree(3));
assert.sameValue(Atomics.isLockFree(true), Atomics.isLockFree(1));
assert.sameValue(Atomics.isLockFree(1), Atomics.isLockFree({valueOf: () => 1}));
assert.sameValue(Atomics.isLockFree(3), Atomics.isLockFree({valueOf: () => 3}));
assert.sameValue(Atomics.isLockFree(1), Atomics.isLockFree({toString: () => '1'}));
assert.sameValue(Atomics.isLockFree(3), Atomics.isLockFree({toString: () => '3'}));
function hide(k, x) {
if (k)
return hide(k-3, x) + x;
return 0;
}

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.add
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "add");
verifyNotEnumerable(Atomics, "add");
verifyConfigurable(Atomics, "add");

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.isLockFree.length is 1.
info: >
Atomics.isLockFree ( x )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.isLockFree.length, 1);
verifyNotEnumerable(Atomics.isLockFree, "length");
verifyNotWritable(Atomics.isLockFree, "length");
verifyConfigurable(Atomics.isLockFree, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.isLockFree.name is "isLockFree".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.isLockFree.name, "isLockFree");
verifyNotEnumerable(Atomics.isLockFree, "name");
verifyNotWritable(Atomics.isLockFree, "name");
verifyConfigurable(Atomics.isLockFree, "name");

View File

@ -0,0 +1,46 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test isLockFree on nonnegative integer arguments
---*/
var sizes = [ 1, 2, 3, 4, 5, 6, 7, 8,
9, 10, 11, 12];
var answers = [ {}, {}, false, true, false, false, false, false,
false, false, false, false];
function testIsLockFree() {
var saved = {};
// This should defeat most optimizations.
for ( var i=0 ; i < sizes.length ; i++ ) {
var v = Atomics.isLockFree(sizes[i]);
var a = answers[i];
assert.sameValue(typeof v, 'boolean');
if (typeof a == 'boolean')
assert.sameValue(v, a);
else
saved[sizes[i]] = v;
}
// This ought to be optimizable. Make sure the answers are the same
// as for the unoptimized case.
assert.sameValue(Atomics.isLockFree(1), saved[1]);
assert.sameValue(Atomics.isLockFree(2), saved[2]);
assert.sameValue(Atomics.isLockFree(3), false);
assert.sameValue(Atomics.isLockFree(4), true);
assert.sameValue(Atomics.isLockFree(5), false);
assert.sameValue(Atomics.isLockFree(6), false);
assert.sameValue(Atomics.isLockFree(7), false);
assert.sameValue(Atomics.isLockFree(8), false);
assert.sameValue(Atomics.isLockFree(9), false);
assert.sameValue(Atomics.isLockFree(10), false);
assert.sameValue(Atomics.isLockFree(11), false);
assert.sameValue(Atomics.isLockFree(12), false);
}
testIsLockFree();

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.load on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.load(view, Idx));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.load
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "load");
verifyNotEnumerable(Atomics, "load");
verifyConfigurable(Atomics, "load");

View File

@ -0,0 +1,44 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.load on arrays that allow atomic operations.
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.load(view, 3), control[0],
"Result is subject to coercion");
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.load(view, 3), control[0],
"Result is subject to chopping");
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.load(view, 3), control[0],
"Result is subject to chopping");
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.load(view, Idx), 37);
});
}, int_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.load.length is 2.
info: >
Atomics.load ( ia, index )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.load.length, 2);
verifyNotEnumerable(Atomics.load, "length");
verifyNotWritable(Atomics.load, "length");
verifyConfigurable(Atomics.load, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.load.name is "load".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.load.name, "load");
verifyNotEnumerable(Atomics.load, "name");
verifyNotWritable(Atomics.load, "name");
verifyConfigurable(Atomics.load, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.load on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.load(view, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.load on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.load(view, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.load on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.load(view, 0)));
}, other_views);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.or on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.or(view, Idx, 10));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.or
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "or");
verifyNotEnumerable(Atomics, "or");
verifyConfigurable(Atomics, "or");

View File

@ -0,0 +1,59 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.or on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
view[8] = 0x33333333;
control[0] = 0x33333333;
assert.sameValue(Atomics.or(view, 8, 0x55555555), control[0],
"Result is subject to chopping");
control[0] = 0x77777777;
assert.sameValue(view[8], control[0]);
assert.sameValue(Atomics.or(view, 8, 0xF0F0F0F0), control[0],
"Result is subject to chopping");
control[0] = 0xF7F7F7F7;
assert.sameValue(view[8], control[0]);
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.or(view, 3, 0), control[0],
"Result is negative and subject to coercion");
assert.sameValue(view[3], control[0]);
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.or(view, 3, 0), control[0],
"Result is subject to chopping");
assert.sameValue(view[3], control[0]);
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.or(view, 3, 0), control[0],
"Result is subject to chopping");
assert.sameValue(view[3], control[0]);
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.or(view, Idx, 0), 37);
});
}, int_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.or.length is 3.
info: >
Atomics.or ( ia, index, val )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.or.length, 3);
verifyNotEnumerable(Atomics.or, "length");
verifyNotWritable(Atomics.or, "length");
verifyConfigurable(Atomics.or, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.or.name is "or".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.or.name, "or");
verifyNotEnumerable(Atomics.or, "name");
verifyNotWritable(Atomics.or, "name");
verifyConfigurable(Atomics.or, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.or on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.or(view, 0, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.or on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.or(view, 0, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.or on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.or(view, 0, 0)));
}, other_views);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Property descriptor of Atomics
info: |
The Atomics Object
[...]
The Atomics object is not a function object. It does not have a [[Construct]]
internal method; it is not possible to use the Atomics object as a constructor
with the new operator. The Atomics object also does not have a [[Call]] internal
method; it is not possible to invoke the Atomics object as a function.
17 ECMAScript Standard Built-in Objects:
Every other data property described in clauses 18 through 26 and in Annex B.2
has the attributes { [[Writable]]: true, [[Enumerable]]: false,
[[Configurable]]: true } unless otherwise specified.
includes: [propertyHelper.js]
---*/
assert.sameValue(typeof Atomics, "object", "no [[Call]]");
assert.throws(TypeError, function() {
new Atomics();
}, "no [[Construct]]");
verifyNotEnumerable(this, "Atomics");
verifyWritable(this, "Atomics");
verifyConfigurable(this, "Atomics");

View File

@ -0,0 +1,16 @@
// Copyright (C) 2016 The V8 Project authors. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
The prototype of Atomics is Object.prototype
info: |
The Atomics Object
The value of the [[Prototype]] internal slot of the Atomics object is the
intrinsic object %ObjectPrototype%.
---*/
var proto = Object.getPrototypeOf(Atomics);
assert.sameValue(proto, Object.prototype);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.store on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.store(view, Idx, 10));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.store
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "store");
verifyNotEnumerable(Atomics, "store");
verifyConfigurable(Atomics, "store");

View File

@ -0,0 +1,54 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.store on arrays that allow atomic operations.
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
for ( let val of [10,
-5,
12345,
123456789,
Math.PI,
"33",
{ valueOf: () => 33 },
undefined] )
{
assert.sameValue(Atomics.store(view, 3, val), ToInteger(val),
"Atomics.store returns its third argument (" + val + ") converted to Integer, not the input value nor the value that was stored");
control[0] = val;
assert.sameValue(view[3], control[0]);
}
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.load(view, Idx), 37);
});
}, int_views);
function ToInteger(v) {
v = +v;
if (isNaN(v))
return 0;
if (v == 0 || !isFinite(v))
return v;
if (v < 0)
return -Math.floor(Math.abs(v));
return Math.floor(v);
}

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.store.length is 3.
info: >
Atomics.store ( ia, index, val )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.store.length, 3);
verifyNotEnumerable(Atomics.store, "length");
verifyNotWritable(Atomics.store, "length");
verifyConfigurable(Atomics.store, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.store.name is "store".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.store.name, "store");
verifyNotEnumerable(Atomics.store, "name");
verifyNotWritable(Atomics.store, "name");
verifyConfigurable(Atomics.store, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.store on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.store(view, 0, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.store on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.store(view, 0, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.store on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.store(view, 0, 0)));
}, other_views);

View File

@ -0,0 +1,19 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.sub on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(4);
var views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
let view = new View(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.sub(view, Idx, 10));
});
}, views);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.sub
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "sub");
verifyNotEnumerable(Atomics, "sub");
verifyConfigurable(Atomics, "sub");

View File

@ -0,0 +1,53 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: Test Atomics.sub on arrays that allow atomic operations
includes: [testAtomics.js, testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
// Make it interesting - use non-zero byteOffsets and non-zero indexes.
var view = new View(sab, 32, 20);
var control = new View(ab, 0, 2);
view[8] = 100;
assert.sameValue(Atomics.sub(view, 8, 10), 100,
"Subtract positive number");
assert.sameValue(view[8], 90);
assert.sameValue(Atomics.sub(view, 8, -5), 90,
"Subtract negative number, though result remains positive");
assert.sameValue(view[8], 95);
view[3] = -5;
control[0] = -5;
assert.sameValue(Atomics.sub(view, 3, 0), control[0],
"Result is negative and subject to coercion");
control[0] = 12345;
view[3] = 12345;
assert.sameValue(Atomics.sub(view, 3, 0), control[0],
"Result is subject to chopping");
control[0] = 123456789;
view[3] = 123456789;
assert.sameValue(Atomics.sub(view, 3, 0), control[0],
"Result is subject to chopping");
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.sub(view, Idx, 0), 37);
});
}, int_views);

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.sub.length is 3.
info: >
Atomics.sub ( ia, index, val )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.sub.length, 3);
verifyNotEnumerable(Atomics.sub, "length");
verifyNotWritable(Atomics.sub, "length");
verifyConfigurable(Atomics.sub, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.sub.name is "sub".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.sub.name, "sub");
verifyNotEnumerable(Atomics.sub, "name");
verifyNotWritable(Atomics.sub, "name");
verifyConfigurable(Atomics.sub, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.sub on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.sub(view, 0, 0)));
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.sub on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.sub(view, 0, 0)));
}, int_views);

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.sub on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
assert.throws(TypeError, (() => Atomics.sub(view, 0, 0)));
}, other_views);

View File

@ -0,0 +1,16 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.wait on arrays that allow atomic operations
includes: [testAtomics.js]
---*/
var sab = new SharedArrayBuffer(4);
var view = new Int32Array(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.wait(view, Idx, 10, 0)); // Even with zero timeout
});

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.wait
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "wait");
verifyNotEnumerable(Atomics, "wait");
verifyConfigurable(Atomics, "wait");

View File

@ -0,0 +1,33 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test that Atomics.wait returns the right result when it timed out and that
the time to time out is reasonable.
includes: [atomicsHelper.js]
---*/
$.agent.start(
`
$.agent.receiveBroadcast(function (sab, id) {
var ia = new Int32Array(sab);
var then = Date.now();
$.agent.report(Atomics.wait(ia, 0, 0, 500)); // Timeout 500ms
$.agent.report(Date.now() - then);
$.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$.agent.broadcast(ia.buffer);
assert.sameValue(getReport(), "timed-out");
assert.sameValue(Math.abs((getReport()|0) - 500) < $ATOMICS_MAX_TIME_EPSILON, true);
function getReport() {
var r;
while ((r = $.agent.getReport()) == null)
$.agent.sleep(100);
return r;
}

View File

@ -0,0 +1,56 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wait on arrays that allow atomic operations,
in an Agent that is allowed to wait.
---*/
// Let's assume 'wait' is not allowed on the main thread,
// even in the shell.
$.agent.start(
`
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var good_indices = [ (view) => 0/-1, // -0
(view) => '-0',
(view) => view.length - 1,
(view) => ({ valueOf: () => 0 }),
(view) => ({ toString: () => '0', valueOf: false }) // non-callable valueOf triggers invocation of toString
];
var view = new Int32Array(sab, 32, 20);
view[0] = 0;
$.agent.report("A " + Atomics.wait(view, 0, 0, 0))
$.agent.report("B " + Atomics.wait(view, 0, 37, 0));
// In-bounds boundary cases for indexing
for ( let IdxGen of good_indices ) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
$.agent.report("C " + Atomics.wait(view, Idx, 0));
}
$.agent.report("done");
$.agent.leaving();
`)
assert.sameValue(getReport(), "A timed-out");
assert.sameValue(getReport(), "B not-equal"); // Even with zero timeout
var r;
while ((r = getReport()) != "done")
assert.sameValue(r, "C not-equal");
function getReport() {
var r;
while ((r = $.agent.getReport()) == null)
$.agent.sleep(100);
return r;
}

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.wait.length is 4.
info: >
Atomics.wait ( ia, index, expect, timeout )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.wait.length, 4);
verifyNotEnumerable(Atomics.wait, "length");
verifyNotWritable(Atomics.wait, "length");
verifyConfigurable(Atomics.wait, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.wait.name is "wait".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.wait.name, "wait");
verifyNotEnumerable(Atomics.wait, "name");
verifyNotWritable(Atomics.wait, "name");
verifyConfigurable(Atomics.wait, "name");

View File

@ -0,0 +1,31 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test that Atomics.wait does not time out with a NaN timeout
---*/
$.agent.start(
`
$.agent.receiveBroadcast(function (sab, id) {
var ia = new Int32Array(sab);
$.agent.report(Atomics.wait(ia, 0, 0, NaN)); // NaN => Infinity
$.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$.agent.broadcast(ia.buffer);
$.agent.sleep(500); // Ample time
assert.sameValue($.agent.getReport(), null);
Atomics.wake(ia, 0);
assert.sameValue(getReport(), "ok");
function getReport() {
var r;
while ((r = $.agent.getReport()) == null)
$.agent.sleep(100);
return r;
}

View File

@ -0,0 +1,28 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test that Atomics.wait times out with a negative timeout
---*/
$.agent.start(
`
$.agent.receiveBroadcast(function (sab, id) {
var ia = new Int32Array(sab);
$.agent.report(Atomics.wait(ia, 0, 0, -5)); // -5 => 0
$.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$.agent.broadcast(ia.buffer);
assert.sameValue(getReport(), "timed-out");
function getReport() {
var r;
while ((r = $.agent.getReport()) == null)
$.agent.sleep(100);
return r;
}

View File

@ -0,0 +1,37 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test that Atomics.wait actually waits and does not spuriously wake
up when the memory value is changed.
includes: [atomicsHelper.js]
---*/
$.agent.start(
`
$.agent.receiveBroadcast(function (sab, id) {
var ia = new Int32Array(sab);
var then = Date.now();
Atomics.wait(ia, 0, 0);
var diff = Date.now() - then; // Should be about 1000 ms
$.agent.report(diff);
$.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$.agent.broadcast(ia.buffer);
$.agent.sleep(500); // Give the agent a chance to wait
Atomics.store(ia, 0, 1); // Change the value, should not wake the agent
$.agent.sleep(500); // Wait some more so that we can tell
Atomics.wake(ia, 0); // Really wake it up
assert.sameValue(Math.abs((getReport()|0) - 1000) < $ATOMICS_MAX_TIME_EPSILON, true);
function getReport() {
var r;
while ((r = $.agent.getReport()) == null)
$.agent.sleep(100);
return r;
}

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wait on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.wait(view, 0, 0, 0))); // Even with zero timeout
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wait on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.wait(view, 0, 0, 0))); // Should fail even if waiting 0ms
}, int_views);

View File

@ -0,0 +1,20 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wait on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array,
Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
// Even with timout zero this should fail
assert.throws(TypeError, (() => Atomics.wait(view, 0, 0, 0)));
}, other_views);

View File

@ -0,0 +1,31 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test that Atomics.wait returns the right result when it was awoken.
---*/
$.agent.start(
`
$.agent.receiveBroadcast(function (sab, id) {
var ia = new Int32Array(sab);
$.agent.report(Atomics.wait(ia, 0, 0)); // No timeout => Infinity
$.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT));
$.agent.broadcast(ia.buffer);
$.agent.sleep(500); // Give the agent a chance to wait
Atomics.wake(ia, 0);
assert.sameValue(getReport(), "ok");
function getReport() {
var r;
while ((r = $.agent.getReport()) == null)
$.agent.sleep(100);
return r;
}

View File

@ -0,0 +1,16 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test range checking of Atomics.wake on arrays that allow atomic operations
includes: [testAtomics.js]
---*/
var sab = new SharedArrayBuffer(4);
var view = new Int32Array(sab);
testWithAtomicsOutOfBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
assert.throws(RangeError, () => Atomics.wake(view, Idx, 0)); // Even with waking zero
});

View File

@ -0,0 +1,17 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Allowed boundary cases of the third 'count' argument to Atomics.wake
---*/
var sab = new SharedArrayBuffer(4);
var view = new Int32Array(sab);
assert.sameValue(Atomics.wake(view, 0, -3), 0);
assert.sameValue(Atomics.wake(view, 0, Number.POSITIVE_INFINITY), 0);
assert.sameValue(Atomics.wake(view, 0, undefined), 0);
assert.sameValue(Atomics.wake(view, 0, "33"), 0);
assert.sameValue(Atomics.wake(view, 0, { valueOf: 8 }), 0);
assert.sameValue(Atomics.wake(view, 0), 0);

View File

@ -0,0 +1,12 @@
// Copyright 2015 Microsoft Corporation. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the license found in the LICENSE file.
/*---
description: Testing descriptor property of Atomics.wake
includes: [propertyHelper.js]
---*/
verifyWritable(Atomics, "wake");
verifyNotEnumerable(Atomics, "wake");
verifyConfigurable(Atomics, "wake");

View File

@ -0,0 +1,27 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wait on arrays that allow atomic operations,
in an Agent that is allowed to wait. There is only the one Agent.
includes: [testAtomics.js]
---*/
var sab = new SharedArrayBuffer(1024);
var ab = new ArrayBuffer(16);
var int_views = [Int32Array];
var view = new Int32Array(sab, 32, 20);
view[0] = 0;
assert.sameValue(Atomics.wake(view, 0, 1), 0);
// In-bounds boundary cases for indexing
testWithAtomicsInBoundsIndices(function(IdxGen) {
let Idx = IdxGen(view);
view.fill(0);
// Atomics.store() computes an index from Idx in the same way as other
// Atomics operations, not quite like view[Idx].
Atomics.store(view, Idx, 37);
assert.sameValue(Atomics.wake(view, Idx, 1), 0);
});

View File

@ -0,0 +1,29 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.wake.length is 3.
info: >
Atomics.wake ( ia, index, count )
17 ECMAScript Standard Built-in Objects:
Every built-in Function object, including constructors, has a length
property whose value is an integer. Unless otherwise specified, this
value is equal to the largest number of named arguments shown in the
subclause headings for the function description, including optional
parameters. However, rest parameters shown using the form ...name
are not included in the default argument count.
Unless otherwise specified, the length property of a built-in Function
object has the attributes { [[Writable]]: false, [[Enumerable]]: false,
[[Configurable]]: true }.
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.wake.length, 3);
verifyNotEnumerable(Atomics.wake, "length");
verifyNotWritable(Atomics.wake, "length");
verifyConfigurable(Atomics.wake, "length");

View File

@ -0,0 +1,15 @@
// Copyright (C) 2015 André Bargull. All rights reserved.
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Atomics.wake.name is "wake".
includes: [propertyHelper.js]
---*/
assert.sameValue(Atomics.wake.name, "wake");
verifyNotEnumerable(Atomics.wake, "name");
verifyNotWritable(Atomics.wake, "name");
verifyConfigurable(Atomics.wake, "name");

View File

@ -0,0 +1,12 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wake on view values other than TypedArrays
includes: [testAtomics.js]
---*/
testWithAtomicsNonViewValues(function(view) {
assert.throws(TypeError, (() => Atomics.wake(view, 0, 0))); // Even with count == 0
});

View File

@ -0,0 +1,18 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wake on non-shared integer TypedArrays
includes: [testTypedArray.js]
---*/
var ab = new ArrayBuffer(16);
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(ab);
assert.throws(TypeError, (() => Atomics.wake(view, 0, 0))); // Should fail even if waking zero waiters
}, int_views);

View File

@ -0,0 +1,20 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test Atomics.wake on shared non-integer TypedArrays
includes: [testTypedArray.js]
---*/
var sab = new SharedArrayBuffer(1024);
var other_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Uint32Array,
Uint8ClampedArray, Float32Array, Float64Array];
testWithTypedArrayConstructors(function(View) {
var view = new View(sab);
// Even with timout zero this should fail
assert.throws(TypeError, (() => Atomics.wake(view, 0, 0))); // Even with 0 to wake this should fail
}, other_views);

View File

@ -0,0 +1,47 @@
// Copyright (C) 2017 Mozilla Corporation. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
description: >
Test that Atomics.wake wakes all waiters on a location, but does not
wake waiters on other locations.
---*/
for ( var i=0 ; i < 3 ; i++ ) {
$.agent.start(
`
$.agent.receiveBroadcast(function (sab) {
var ia = new Int32Array(sab);
$.agent.report("A " + Atomics.wait(ia, 0, 0));
$.agent.leaving();
})
`);
}
$.agent.start(
`
$.agent.receiveBroadcast(function (sab) {
var ia = new Int32Array(sab);
$.agent.report("B " + Atomics.wait(ia, 1, 0, 1000)); // We will timeout eventually
$.agent.leaving();
})
`);
var ia = new Int32Array(new SharedArrayBuffer(2*Int32Array.BYTES_PER_ELEMENT));
$.agent.broadcast(ia.buffer);
$.agent.sleep(500); // Give the agents a chance to wait
assert.sameValue(Atomics.wake(ia, 0), 3); // Wake all on location 0
var rs = [getReport(), getReport(), getReport(), getReport()];
// Do not sort the array -- B should timeout much after the others are woken
assert.sameValue(rs[0], "A ok");
assert.sameValue(rs[1], "A ok");
assert.sameValue(rs[2], "A ok");
assert.sameValue(rs[3], "B timed-out");
function getReport() {
var r;
while ((r = $.agent.getReport()) == null)
$.agent.sleep(100);
return r;
}

Some files were not shown because too many files have changed in this diff Show More