summaryrefslogtreecommitdiff
path: root/deps/v8/test/mjsunit/harmony/atomics.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/v8/test/mjsunit/harmony/atomics.js')
-rw-r--r--deps/v8/test/mjsunit/harmony/atomics.js168
1 files changed, 90 insertions, 78 deletions
diff --git a/deps/v8/test/mjsunit/harmony/atomics.js b/deps/v8/test/mjsunit/harmony/atomics.js
index 4b9c9f6c66..bf27eb46d5 100644
--- a/deps/v8/test/mjsunit/harmony/atomics.js
+++ b/deps/v8/test/mjsunit/harmony/atomics.js
@@ -60,83 +60,65 @@ var IntegerTypedArrayConstructors = [
});
})();
-function testAtomicOp(op, ia, index, expectedIndex, name) {
- for (var i = 0; i < ia.length; ++i)
- ia[i] = 22;
-
- ia[expectedIndex] = 0;
- assertEquals(0, op(ia, index, 0, 0), name);
- assertEquals(0, ia[expectedIndex], name);
-
- for (var i = 0; i < ia.length; ++i) {
- if (i == expectedIndex) continue;
- assertEquals(22, ia[i], name);
- }
-}
-
(function TestBadIndex() {
var sab = new SharedArrayBuffer(8);
var si32a = new Int32Array(sab);
var si32a2 = new Int32Array(sab, 4);
- // Non-integer indexes are converted to an integer first, so they should all
- // operate on index 0.
- [undefined, null, false, 'hi', {}].forEach(function(i) {
-
- var name = String(i);
- testAtomicOp(Atomics.compareExchange, si32a, i, 0, name);
- testAtomicOp(Atomics.load, si32a, i, 0, name);
- testAtomicOp(Atomics.store, si32a, i, 0, name);
- testAtomicOp(Atomics.add, si32a, i, 0, name);
- testAtomicOp(Atomics.sub, si32a, i, 0, name);
- testAtomicOp(Atomics.and, si32a, i, 0, name);
- testAtomicOp(Atomics.or, si32a, i, 0, name);
- testAtomicOp(Atomics.xor, si32a, i, 0, name);
- testAtomicOp(Atomics.exchange, si32a, i, 0, name);
- });
-
- // Out-of-bounds indexes should return undefined.
- // TODO(binji): Should these throw RangeError instead?
+ // Non-integer indexes should throw RangeError.
+ var nonInteger = [1.4, '1.4', NaN, -Infinity, Infinity, undefined, 'hi', {}];
+ nonInteger.forEach(function(i) {
+ assertThrows(function() { Atomics.compareExchange(si32a, i, 0); },
+ RangeError);
+ assertThrows(function() { Atomics.load(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.store(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.add(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.sub(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.and(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.or(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.xor(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.exchange(si32a, i, 0); }, RangeError);
+ }, RangeError);
+
+ // Out-of-bounds indexes should throw RangeError.
[-1, 2, 100].forEach(function(i) {
- var name = String(i);
- assertEquals(undefined, Atomics.compareExchange(si32a, i, 0, 0), name);
- assertEquals(undefined, Atomics.load(si32a, i), name);
- assertEquals(undefined, Atomics.store(si32a, i, 0), name);
- assertEquals(undefined, Atomics.add(si32a, i, 0), name);
- assertEquals(undefined, Atomics.sub(si32a, i, 0), name);
- assertEquals(undefined, Atomics.and(si32a, i, 0), name);
- assertEquals(undefined, Atomics.or(si32a, i, 0), name);
- assertEquals(undefined, Atomics.xor(si32a, i, 0), name);
- assertEquals(undefined, Atomics.exchange(si32a, i, 0), name);
- });
-
- // Out-of-bounds indexes for offset-array
+ assertThrows(function() { Atomics.compareExchange(si32a, i, 0, 0); },
+ RangeError);
+ assertThrows(function() { Atomics.load(si32a, i); }, RangeError);
+ assertThrows(function() { Atomics.store(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.add(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.sub(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.and(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.or(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.xor(si32a, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.exchange(si32a, i, 0); }, RangeError);
+ }, RangeError);
+
+ // Out-of-bounds indexes for array with offset should throw RangeError.
[-1, 1, 100].forEach(function(i) {
- var name = String(i);
- assertEquals(undefined, Atomics.compareExchange(si32a2, i, 0, 0), name);
- assertEquals(undefined, Atomics.load(si32a2, i), name);
- assertEquals(undefined, Atomics.store(si32a2, i, 0), name);
- assertEquals(undefined, Atomics.add(si32a2, i, 0), name);
- assertEquals(undefined, Atomics.sub(si32a2, i, 0), name);
- assertEquals(undefined, Atomics.and(si32a2, i, 0), name);
- assertEquals(undefined, Atomics.or(si32a2, i, 0), name);
- assertEquals(undefined, Atomics.xor(si32a2, i, 0), name);
- assertEquals(undefined, Atomics.exchange(si32a2, i, 0), name);
+ assertThrows(function() { Atomics.compareExchange(si32a2, i, 0, 0); });
+ assertThrows(function() { Atomics.load(si32a2, i); }, RangeError);
+ assertThrows(function() { Atomics.store(si32a2, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.add(si32a2, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.sub(si32a2, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.and(si32a2, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.or(si32a2, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.xor(si32a2, i, 0); }, RangeError);
+ assertThrows(function() { Atomics.exchange(si32a2, i, 0); }, RangeError);
});
- // Monkey-patch length and make sure these functions still return undefined.
+ // Monkey-patch length and make sure these functions still throw.
Object.defineProperty(si32a, 'length', {get: function() { return 1000; }});
[2, 100].forEach(function(i) {
- var name = String(i);
- assertEquals(undefined, Atomics.compareExchange(si32a, i, 0, 0), name);
- assertEquals(undefined, Atomics.load(si32a, i), name);
- assertEquals(undefined, Atomics.store(si32a, i, 0), name);
- assertEquals(undefined, Atomics.add(si32a, i, 0), name);
- assertEquals(undefined, Atomics.sub(si32a, i, 0), name);
- assertEquals(undefined, Atomics.and(si32a, i, 0), name);
- assertEquals(undefined, Atomics.or(si32a, i, 0), name);
- assertEquals(undefined, Atomics.xor(si32a, i, 0), name);
- assertEquals(undefined, Atomics.exchange(si32a, i, 0), name);
+ assertThrows(function() { Atomics.compareExchange(si32a, i, 0, 0); });
+ assertThrows(function() { Atomics.load(si32a, i); });
+ assertThrows(function() { Atomics.store(si32a, i, 0); });
+ assertThrows(function() { Atomics.add(si32a, i, 0); });
+ assertThrows(function() { Atomics.sub(si32a, i, 0); });
+ assertThrows(function() { Atomics.and(si32a, i, 0); });
+ assertThrows(function() { Atomics.or(si32a, i, 0); });
+ assertThrows(function() { Atomics.xor(si32a, i, 0); });
+ assertThrows(function() { Atomics.exchange(si32a, i, 0); });
});
})();
@@ -145,22 +127,52 @@ function testAtomicOp(op, ia, index, expectedIndex, name) {
var si32a = new Int32Array(sab);
var si32a2 = new Int32Array(sab, 32);
+ var testOp = function(op, ia, index, expectedIndex, name) {
+ for (var i = 0; i < ia.length; ++i)
+ ia[i] = 22;
+
+ ia[expectedIndex] = 0;
+ assertEquals(0, op(ia, index, 0, 0), name);
+ assertEquals(0, ia[expectedIndex], name);
+
+ for (var i = 0; i < ia.length; ++i) {
+ if (i == expectedIndex) continue;
+ assertEquals(22, ia[i], name);
+ }
+ };
+
+ // These values all map to index 0
+ [-0, 0, 0.0, null, false].forEach(function(i) {
+ var name = String(i);
+ [si32a, si32a2].forEach(function(array) {
+ testOp(Atomics.compareExchange, array, i, 0, name);
+ testOp(Atomics.load, array, i, 0, name);
+ testOp(Atomics.store, array, i, 0, name);
+ testOp(Atomics.add, array, i, 0, name);
+ testOp(Atomics.sub, array, i, 0, name);
+ testOp(Atomics.and, array, i, 0, name);
+ testOp(Atomics.or, array, i, 0, name);
+ testOp(Atomics.xor, array, i, 0, name);
+ testOp(Atomics.exchange, array, i, 0, name);
+ });
+ });
+
+ // These values all map to index 3
var valueOf = {valueOf: function(){ return 3;}};
var toString = {toString: function(){ return '3';}};
-
- [3, 3.5, '3', '3.5', valueOf, toString].forEach(function(i) {
+ [3, 3.0, '3', '3.0', valueOf, toString].forEach(function(i) {
var name = String(i);
[si32a, si32a2].forEach(function(array) {
- testAtomicOp(Atomics.compareExchange, array, i, 3, name);
- testAtomicOp(Atomics.load, array, i, 3, name);
- testAtomicOp(Atomics.store, array, i, 3, name);
- testAtomicOp(Atomics.add, array, i, 3, name);
- testAtomicOp(Atomics.sub, array, i, 3, name);
- testAtomicOp(Atomics.and, array, i, 3, name);
- testAtomicOp(Atomics.or, array, i, 3, name);
- testAtomicOp(Atomics.xor, array, i, 3, name);
- testAtomicOp(Atomics.exchange, array, i, 3, name);
- })
+ testOp(Atomics.compareExchange, array, i, 3, name);
+ testOp(Atomics.load, array, i, 3, name);
+ testOp(Atomics.store, array, i, 3, name);
+ testOp(Atomics.add, array, i, 3, name);
+ testOp(Atomics.sub, array, i, 3, name);
+ testOp(Atomics.and, array, i, 3, name);
+ testOp(Atomics.or, array, i, 3, name);
+ testOp(Atomics.xor, array, i, 3, name);
+ testOp(Atomics.exchange, array, i, 3, name);
+ });
});
})();