-
Notifications
You must be signed in to change notification settings - Fork 459
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SharedArrayBuffer and Atomics tests #839
Merged
Merged
Changes from 11 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b07a01e
Add SharedArrayBuffer and Atomics tests
d1fccaa
Add Atomics[@@toStringTag] test
syg 40bb0d2
Fix new SAB tests' copyright lines to say Mozilla
syg 6e2b2e5
Refactor Atomics tests
syg 9d97d3c
Fix style in SharedArrayBuffer.prototype.slice tests
syg 49ab6c5
Remove features: [Symbol] from SharedArrayBuffer tests
syg 291563d
Split out SharedArrayBuffer versions of TypedArrays/buffer-arg-* tests
syg 388466d
Revert buffer-arg tests to only test ArrayBuffer
syg ab2ca76
Split out SharedArrayBuffer DataView tests
syg 1297867
Revert DataView tests to only test ArrayBuffer
syg 89a0f73
Remove agent_spidermonkey.js for merging
syg c55033e
Revert "Fix new SAB tests' copyright lines to say Mozilla"
syg 32ba9c0
Append Mozilla copyright instead of replacing original copyright in m…
syg b970a8d
Copy more analogous ArrayBuffer tests to SharedArrayBuffer
syg 03e19ad
Adding missing testTypedArray.js include in Atomics tests
syg 2d74325
Refactor 100 to $ATOMICS_MAX_TIME_EPSILON in atomicsHelper.js
syg 28abb1d
Combine two features: lines
syg adae9e8
Add tests for [Shared]ArrayBuffer.prototype.{byteLength,slice} being …
syg 70e2166
Add test for new %TypedArray%(new %TypedArray%(SAB))
syg f076541
Add versions of %TypedArray%.prototype.set on SharedArrayBuffer-backe…
syg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. once again an assertion message here indicating the used index |
||
}); | ||
}, int_views); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright (C) 2017 André Bargull. 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// Copyright (C) 2017 André Bargull. 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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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))); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: > | ||
Test Atomics.add on non-shared integer TypedArrays | ||
---*/ | ||
|
||
var ab = new ArrayBuffer(16); | ||
|
||
var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; | ||
|
||
testWithTypedArrayConstructors(function(View) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing include for testTypedArray.js (also applies to other files). |
||
var view = new View(ab); | ||
|
||
assert.throws(TypeError, (() => Atomics.add(view, 0, 0))); | ||
}, int_views); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: > | ||
Test Atomics.add on shared non-integer TypedArrays | ||
---*/ | ||
|
||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// 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"); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there's already a harness helper that can be used to loop on different TypedArray constructors, even on specific constructors...
testWithTypedArrayConstructors(fn(View) { let view = new View(sab); ... }, views)
can be used as it also tells where the error is if an assertion fail.