diff --git a/INTERPRETING.md b/INTERPRETING.md index 0c4846abc2957302e0a35fe0ce3de27baaed000b..d4c2900a0c32817448ef94326aa16e72c234befe 100644 --- a/INTERPRETING.md +++ b/INTERPRETING.md @@ -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 diff --git a/harness/atomicsHelper.js b/harness/atomicsHelper.js new file mode 100644 index 0000000000000000000000000000000000000000..5854a3630dbce318e9873208d4c56085cceb8b51 --- /dev/null +++ b/harness/atomicsHelper.js @@ -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; diff --git a/harness/testAtomics.js b/harness/testAtomics.js new file mode 100644 index 0000000000000000000000000000000000000000..ce2a34b0d787e9ce733b403d9ecb2df4c0089133 --- /dev/null +++ b/harness/testAtomics.js @@ -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; + } + } +} diff --git a/test/built-ins/ArrayBuffer/prototype/byteLength/this-is-sharedarraybuffer.js b/test/built-ins/ArrayBuffer/prototype/byteLength/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..7cbf278ccdfc798c7402e35aa792adc6517f321f --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/byteLength/this-is-sharedarraybuffer.js @@ -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"); diff --git a/test/built-ins/ArrayBuffer/prototype/slice/this-is-sharedarraybuffer.js b/test/built-ins/ArrayBuffer/prototype/slice/this-is-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..3e9fe66cb1428ee4f5e953d5f981008112ba495e --- /dev/null +++ b/test/built-ins/ArrayBuffer/prototype/slice/this-is-sharedarraybuffer.js @@ -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"); diff --git a/test/built-ins/Atomics/Symbol.toStringTag.js b/test/built-ins/Atomics/Symbol.toStringTag.js new file mode 100644 index 0000000000000000000000000000000000000000..647c657e757402350c3493a4fd2b59fd49445067 --- /dev/null +++ b/test/built-ins/Atomics/Symbol.toStringTag.js @@ -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); diff --git a/test/built-ins/Atomics/add/bad-range.js b/test/built-ins/Atomics/add/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..e7b061de741373ec91609de6d5f3d1a4df0b25f8 --- /dev/null +++ b/test/built-ins/Atomics/add/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/add/descriptor.js b/test/built-ins/Atomics/add/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..822696affd73d44752ad343699cae0a299a3237c --- /dev/null +++ b/test/built-ins/Atomics/add/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/add/good-views.js b/test/built-ins/Atomics/add/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..6dda8b488f7da982990622c4d2dc647be89c9f2b --- /dev/null +++ b/test/built-ins/Atomics/add/good-views.js @@ -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); diff --git a/test/built-ins/Atomics/add/length.js b/test/built-ins/Atomics/add/length.js new file mode 100644 index 0000000000000000000000000000000000000000..34bf294f5cf83acda72863994ddf5077a8c1b2c8 --- /dev/null +++ b/test/built-ins/Atomics/add/length.js @@ -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"); diff --git a/test/built-ins/Atomics/add/name.js b/test/built-ins/Atomics/add/name.js new file mode 100644 index 0000000000000000000000000000000000000000..0280526c6c33a40f83015bebf555f7ddf937312c --- /dev/null +++ b/test/built-ins/Atomics/add/name.js @@ -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"); diff --git a/test/built-ins/Atomics/add/non-views.js b/test/built-ins/Atomics/add/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..baa6ada0f70028421c224f5f2b69c33734ded095 --- /dev/null +++ b/test/built-ins/Atomics/add/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/add/nonshared-int-views.js b/test/built-ins/Atomics/add/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..c385fc30491a0c69ed78635a85b592c9dd58a313 --- /dev/null +++ b/test/built-ins/Atomics/add/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/add/shared-nonint-views.js b/test/built-ins/Atomics/add/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..b643c14e16aed4b281d5932e38d2bda90d4e3814 --- /dev/null +++ b/test/built-ins/Atomics/add/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/and/bad-range.js b/test/built-ins/Atomics/and/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..4e33422318d65c9602e7b9659fbe19405392cc32 --- /dev/null +++ b/test/built-ins/Atomics/and/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/and/descriptor.js b/test/built-ins/Atomics/and/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..113970c38a507aaa4391cb801b7ceaaccd8e504c --- /dev/null +++ b/test/built-ins/Atomics/and/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/and/good-views.js b/test/built-ins/Atomics/and/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..269c495ae9a1480b3ddb7e403d8558b3ca54f89f --- /dev/null +++ b/test/built-ins/Atomics/and/good-views.js @@ -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); diff --git a/test/built-ins/Atomics/and/length.js b/test/built-ins/Atomics/and/length.js new file mode 100644 index 0000000000000000000000000000000000000000..207f605664d219c798d4973f4d909047dd97aa4f --- /dev/null +++ b/test/built-ins/Atomics/and/length.js @@ -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"); diff --git a/test/built-ins/Atomics/and/name.js b/test/built-ins/Atomics/and/name.js new file mode 100644 index 0000000000000000000000000000000000000000..f9dd0ead86b5b4b986f3df8cb40d7241a94dca5f --- /dev/null +++ b/test/built-ins/Atomics/and/name.js @@ -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"); diff --git a/test/built-ins/Atomics/and/non-views.js b/test/built-ins/Atomics/and/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..c7e528ca8bcd09204615eb2749f77e1888f0106b --- /dev/null +++ b/test/built-ins/Atomics/and/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/and/nonshared-int-views.js b/test/built-ins/Atomics/and/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..5c7967c0fab73cf27d32ce400544e9fc3df58f25 --- /dev/null +++ b/test/built-ins/Atomics/and/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/and/shared-nonint-views.js b/test/built-ins/Atomics/and/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..317f20333ee2d53bd29782255da55646fe2a8e6d --- /dev/null +++ b/test/built-ins/Atomics/and/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/compareExchange/bad-range.js b/test/built-ins/Atomics/compareExchange/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..920e90bc3a16b57a1d28ca44a634fb9ec744c396 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/compareExchange/descriptor.js b/test/built-ins/Atomics/compareExchange/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..4acadc454dfbcce49b770d5caab75180b8ea8493 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/compareExchange/good-views.js b/test/built-ins/Atomics/compareExchange/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..cda3c655e4d296d67f1580430bf4f7f66258aba3 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/good-views.js @@ -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); diff --git a/test/built-ins/Atomics/compareExchange/length.js b/test/built-ins/Atomics/compareExchange/length.js new file mode 100644 index 0000000000000000000000000000000000000000..fdb318f7f71f050a0dff1881114baec95a820231 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/length.js @@ -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"); diff --git a/test/built-ins/Atomics/compareExchange/name.js b/test/built-ins/Atomics/compareExchange/name.js new file mode 100644 index 0000000000000000000000000000000000000000..f179b8c499f2256e9bc5a266c1e524f7c2c07f72 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/name.js @@ -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"); diff --git a/test/built-ins/Atomics/compareExchange/non-views.js b/test/built-ins/Atomics/compareExchange/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..c0e6475dfb4aba4979b14922dd7bf337112a3cb7 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/compareExchange/nonshared-int-views.js b/test/built-ins/Atomics/compareExchange/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..94d18b6669cded24c2ced789e49c50b0c26711b5 --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/compareExchange/shared-nonint-views.js b/test/built-ins/Atomics/compareExchange/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..78e12e34d4bcb6d5fec2569d522a47b89f2d917d --- /dev/null +++ b/test/built-ins/Atomics/compareExchange/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/exchange/bad-range.js b/test/built-ins/Atomics/exchange/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..c8be9be25f82a724d4cd2c6945139bb8bee173ab --- /dev/null +++ b/test/built-ins/Atomics/exchange/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/exchange/descriptor.js b/test/built-ins/Atomics/exchange/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..395712cf06193c36f04f0587b749f227c2cac579 --- /dev/null +++ b/test/built-ins/Atomics/exchange/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/exchange/good-views.js b/test/built-ins/Atomics/exchange/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..2961133d80becc3fd47a5347a8bdb6a50c1c8867 --- /dev/null +++ b/test/built-ins/Atomics/exchange/good-views.js @@ -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); diff --git a/test/built-ins/Atomics/exchange/length.js b/test/built-ins/Atomics/exchange/length.js new file mode 100644 index 0000000000000000000000000000000000000000..92b424ad65ad1de4bd8f6572721dedca3f76c990 --- /dev/null +++ b/test/built-ins/Atomics/exchange/length.js @@ -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"); diff --git a/test/built-ins/Atomics/exchange/name.js b/test/built-ins/Atomics/exchange/name.js new file mode 100644 index 0000000000000000000000000000000000000000..f1b29161668a3b03824b9020e178296bf897ba27 --- /dev/null +++ b/test/built-ins/Atomics/exchange/name.js @@ -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"); diff --git a/test/built-ins/Atomics/exchange/non-views.js b/test/built-ins/Atomics/exchange/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..57010262551ca79eb68b13b36a92b3e430d44512 --- /dev/null +++ b/test/built-ins/Atomics/exchange/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/exchange/nonshared-int-views.js b/test/built-ins/Atomics/exchange/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..fa07e5fea6401a806b14927d5aa406aa5432b30f --- /dev/null +++ b/test/built-ins/Atomics/exchange/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/exchange/shared-nonint-views.js b/test/built-ins/Atomics/exchange/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..68f70e2041d7f04c6ac17fa36c4bd6c81baffe10 --- /dev/null +++ b/test/built-ins/Atomics/exchange/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/isLockFree/corner-cases.js b/test/built-ins/Atomics/isLockFree/corner-cases.js new file mode 100644 index 0000000000000000000000000000000000000000..283338ba57817e8a463d455ea75f5d48c0285c69 --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/corner-cases.js @@ -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; +} + diff --git a/test/built-ins/Atomics/isLockFree/descriptor.js b/test/built-ins/Atomics/isLockFree/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..822696affd73d44752ad343699cae0a299a3237c --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/isLockFree/length.js b/test/built-ins/Atomics/isLockFree/length.js new file mode 100644 index 0000000000000000000000000000000000000000..4dc1e6de6239b61c78f26dd3b6d32e1fb75fa97b --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/length.js @@ -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"); diff --git a/test/built-ins/Atomics/isLockFree/name.js b/test/built-ins/Atomics/isLockFree/name.js new file mode 100644 index 0000000000000000000000000000000000000000..e7926b4508a5c03ca428d18c2057e42d4872f57b --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/name.js @@ -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"); diff --git a/test/built-ins/Atomics/isLockFree/value.js b/test/built-ins/Atomics/isLockFree/value.js new file mode 100644 index 0000000000000000000000000000000000000000..93b6bee2b929176d3c10ae9eb36cc2edde838bb9 --- /dev/null +++ b/test/built-ins/Atomics/isLockFree/value.js @@ -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(); diff --git a/test/built-ins/Atomics/load/bad-range.js b/test/built-ins/Atomics/load/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..9f5071780c2f505982c4b39564f405ccbd9793be --- /dev/null +++ b/test/built-ins/Atomics/load/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/load/descriptor.js b/test/built-ins/Atomics/load/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..033a2e89306060250132c5cb85ca4e33830b649b --- /dev/null +++ b/test/built-ins/Atomics/load/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/load/good-views.js b/test/built-ins/Atomics/load/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..cc8e0a15a4a068aaf2d233e5169e72d44a3f57f6 --- /dev/null +++ b/test/built-ins/Atomics/load/good-views.js @@ -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); diff --git a/test/built-ins/Atomics/load/length.js b/test/built-ins/Atomics/load/length.js new file mode 100644 index 0000000000000000000000000000000000000000..f85c87818231d5d41bc851bfb9fdeaae1ff74fa9 --- /dev/null +++ b/test/built-ins/Atomics/load/length.js @@ -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"); diff --git a/test/built-ins/Atomics/load/name.js b/test/built-ins/Atomics/load/name.js new file mode 100644 index 0000000000000000000000000000000000000000..ab212ff121fbec366ad0b61a5e3deca994b5ac21 --- /dev/null +++ b/test/built-ins/Atomics/load/name.js @@ -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"); diff --git a/test/built-ins/Atomics/load/non-views.js b/test/built-ins/Atomics/load/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..96dcb156265f46562d5a3d55f6788ac5316aaa68 --- /dev/null +++ b/test/built-ins/Atomics/load/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/load/nonshared-int-views.js b/test/built-ins/Atomics/load/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..1d722c4147dae1799fb102593e750c6d0fe6746c --- /dev/null +++ b/test/built-ins/Atomics/load/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/load/shared-nonint-views.js b/test/built-ins/Atomics/load/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..4384170dd26b62867bb649587910aa7f6f7889fc --- /dev/null +++ b/test/built-ins/Atomics/load/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/or/bad-range.js b/test/built-ins/Atomics/or/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..f4b1feb5a0d994ae6e76dad6ec55ef53d0dfd3ac --- /dev/null +++ b/test/built-ins/Atomics/or/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/or/descriptor.js b/test/built-ins/Atomics/or/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..9e8db569f0167929c3bbbd3f279325498b3c2655 --- /dev/null +++ b/test/built-ins/Atomics/or/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/or/good-views.js b/test/built-ins/Atomics/or/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..9e5da28ec6e2977dbdc3f45aebfa1651b69ef9fd --- /dev/null +++ b/test/built-ins/Atomics/or/good-views.js @@ -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); diff --git a/test/built-ins/Atomics/or/length.js b/test/built-ins/Atomics/or/length.js new file mode 100644 index 0000000000000000000000000000000000000000..4dce3049c5c4e3212e242a21a8ad0892e62bd33a --- /dev/null +++ b/test/built-ins/Atomics/or/length.js @@ -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"); diff --git a/test/built-ins/Atomics/or/name.js b/test/built-ins/Atomics/or/name.js new file mode 100644 index 0000000000000000000000000000000000000000..5881777052bde975111894931282fc25d6c30f9d --- /dev/null +++ b/test/built-ins/Atomics/or/name.js @@ -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"); diff --git a/test/built-ins/Atomics/or/non-views.js b/test/built-ins/Atomics/or/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..ad0b820428dde1be5714773e9a7fd694a31d252a --- /dev/null +++ b/test/built-ins/Atomics/or/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/or/nonshared-int-views.js b/test/built-ins/Atomics/or/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..ae11cf4aaa5c949ac4076ef2b5df5c3fe5f88f6f --- /dev/null +++ b/test/built-ins/Atomics/or/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/or/shared-nonint-views.js b/test/built-ins/Atomics/or/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..2b7fdb1b07f3aba7b00c0dab600e94fbc52d183d --- /dev/null +++ b/test/built-ins/Atomics/or/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/prop-desc.js b/test/built-ins/Atomics/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..220433d02e16467b84835f27955f11d1b278758b --- /dev/null +++ b/test/built-ins/Atomics/prop-desc.js @@ -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"); diff --git a/test/built-ins/Atomics/proto.js b/test/built-ins/Atomics/proto.js new file mode 100644 index 0000000000000000000000000000000000000000..47e96ec28a380dc657b85f8d1187484ca65f18cf --- /dev/null +++ b/test/built-ins/Atomics/proto.js @@ -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); diff --git a/test/built-ins/Atomics/store/bad-range.js b/test/built-ins/Atomics/store/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..90cd3d2cdf5a1046d8e6c08d7da213c3020002c6 --- /dev/null +++ b/test/built-ins/Atomics/store/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/store/descriptor.js b/test/built-ins/Atomics/store/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..df883fa8cbbe4fb9aa922e0336223f62ee8c72e8 --- /dev/null +++ b/test/built-ins/Atomics/store/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/store/good-views.js b/test/built-ins/Atomics/store/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..511493e170d5362d80a8a6f211e7a113582beaf7 --- /dev/null +++ b/test/built-ins/Atomics/store/good-views.js @@ -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); +} diff --git a/test/built-ins/Atomics/store/length.js b/test/built-ins/Atomics/store/length.js new file mode 100644 index 0000000000000000000000000000000000000000..871ef0a2b9cf45ea9cb19ad9ff54747bc81bd275 --- /dev/null +++ b/test/built-ins/Atomics/store/length.js @@ -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"); diff --git a/test/built-ins/Atomics/store/name.js b/test/built-ins/Atomics/store/name.js new file mode 100644 index 0000000000000000000000000000000000000000..442ecc58af486f0539e2a91eac1f73c210ba8d2c --- /dev/null +++ b/test/built-ins/Atomics/store/name.js @@ -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"); diff --git a/test/built-ins/Atomics/store/non-views.js b/test/built-ins/Atomics/store/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..ec1fd7b393aad21fe15fbcf3099219a208e3d273 --- /dev/null +++ b/test/built-ins/Atomics/store/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/store/nonshared-int-views.js b/test/built-ins/Atomics/store/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..a71b57dde79827d1fee1d557f5851c2fb4a74e82 --- /dev/null +++ b/test/built-ins/Atomics/store/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/store/shared-nonint-views.js b/test/built-ins/Atomics/store/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..81a4c7ae46a5e9d02fd58e8a591c3788de498baa --- /dev/null +++ b/test/built-ins/Atomics/store/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/sub/bad-range.js b/test/built-ins/Atomics/sub/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..902bb21740919c06435284f781a9ad1ab9edcb18 --- /dev/null +++ b/test/built-ins/Atomics/sub/bad-range.js @@ -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); diff --git a/test/built-ins/Atomics/sub/descriptor.js b/test/built-ins/Atomics/sub/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..e9ca6f92765d8372c36f140383dd0181a2da5fef --- /dev/null +++ b/test/built-ins/Atomics/sub/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/sub/good-views.js b/test/built-ins/Atomics/sub/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..cdbe4b22c2be4b0d99eb140f350f019820e1ccfa --- /dev/null +++ b/test/built-ins/Atomics/sub/good-views.js @@ -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); diff --git a/test/built-ins/Atomics/sub/length.js b/test/built-ins/Atomics/sub/length.js new file mode 100644 index 0000000000000000000000000000000000000000..12e070c1399f757543d45c511bb9357356267595 --- /dev/null +++ b/test/built-ins/Atomics/sub/length.js @@ -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"); diff --git a/test/built-ins/Atomics/sub/name.js b/test/built-ins/Atomics/sub/name.js new file mode 100644 index 0000000000000000000000000000000000000000..665a6e0ae0afffb1071bfe03ebe0e7a695ea0a7c --- /dev/null +++ b/test/built-ins/Atomics/sub/name.js @@ -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"); diff --git a/test/built-ins/Atomics/sub/non-views.js b/test/built-ins/Atomics/sub/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..700074f9cd86e0a745c3955a6650f1b86b7d9196 --- /dev/null +++ b/test/built-ins/Atomics/sub/non-views.js @@ -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))); +}); diff --git a/test/built-ins/Atomics/sub/nonshared-int-views.js b/test/built-ins/Atomics/sub/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..f73d0469df995ecf3a75287ae8960251d4586b0d --- /dev/null +++ b/test/built-ins/Atomics/sub/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/sub/shared-nonint-views.js b/test/built-ins/Atomics/sub/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..da38d5bfdce969c9cee2e592d75d3a3735af25de --- /dev/null +++ b/test/built-ins/Atomics/sub/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/wait/bad-range.js b/test/built-ins/Atomics/wait/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..cd75b283619243bcf8ee2eeb0a5052704df0edec --- /dev/null +++ b/test/built-ins/Atomics/wait/bad-range.js @@ -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 +}); diff --git a/test/built-ins/Atomics/wait/descriptor.js b/test/built-ins/Atomics/wait/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..c01712cbe8d9df42cdd6c5c0b405929e9d43d312 --- /dev/null +++ b/test/built-ins/Atomics/wait/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/wait/did-timeout.js b/test/built-ins/Atomics/wait/did-timeout.js new file mode 100644 index 0000000000000000000000000000000000000000..b642ee8e1c449bfc527f225b817b5a521e901697 --- /dev/null +++ b/test/built-ins/Atomics/wait/did-timeout.js @@ -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; +} diff --git a/test/built-ins/Atomics/wait/good-views.js b/test/built-ins/Atomics/wait/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..9776b67b80299d7a83144510d7717201194eb0a8 --- /dev/null +++ b/test/built-ins/Atomics/wait/good-views.js @@ -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; +} diff --git a/test/built-ins/Atomics/wait/length.js b/test/built-ins/Atomics/wait/length.js new file mode 100644 index 0000000000000000000000000000000000000000..00a26d53d6aece23081a305d334f06dc245883de --- /dev/null +++ b/test/built-ins/Atomics/wait/length.js @@ -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"); diff --git a/test/built-ins/Atomics/wait/name.js b/test/built-ins/Atomics/wait/name.js new file mode 100644 index 0000000000000000000000000000000000000000..0fd9d30c9188d7c20d93ebdd3991ce047016748f --- /dev/null +++ b/test/built-ins/Atomics/wait/name.js @@ -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"); diff --git a/test/built-ins/Atomics/wait/nan-timeout.js b/test/built-ins/Atomics/wait/nan-timeout.js new file mode 100644 index 0000000000000000000000000000000000000000..1e3f6e4aa2ae9777057e005a499482dba84540c9 --- /dev/null +++ b/test/built-ins/Atomics/wait/nan-timeout.js @@ -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; +} diff --git a/test/built-ins/Atomics/wait/negative-timeout.js b/test/built-ins/Atomics/wait/negative-timeout.js new file mode 100644 index 0000000000000000000000000000000000000000..521c2244083199ccbd76d004f2bc4230a24c76a3 --- /dev/null +++ b/test/built-ins/Atomics/wait/negative-timeout.js @@ -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; +} diff --git a/test/built-ins/Atomics/wait/no-spurious-wakeup.js b/test/built-ins/Atomics/wait/no-spurious-wakeup.js new file mode 100644 index 0000000000000000000000000000000000000000..a8cd0cb2e25b9fb148340f396cb973f9722bbd1c --- /dev/null +++ b/test/built-ins/Atomics/wait/no-spurious-wakeup.js @@ -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; +} diff --git a/test/built-ins/Atomics/wait/non-views.js b/test/built-ins/Atomics/wait/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..22504528ac840b096cd322b9d811ca52f5086fe1 --- /dev/null +++ b/test/built-ins/Atomics/wait/non-views.js @@ -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 +}); diff --git a/test/built-ins/Atomics/wait/nonshared-int-views.js b/test/built-ins/Atomics/wait/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..e058d9efc07ec11121649e5b73195549e6ce64d4 --- /dev/null +++ b/test/built-ins/Atomics/wait/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/wait/shared-nonint-views.js b/test/built-ins/Atomics/wait/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..bfc9b34a00b0bfee6b4f987db53c2512b584dcdc --- /dev/null +++ b/test/built-ins/Atomics/wait/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/wait/was-woken.js b/test/built-ins/Atomics/wait/was-woken.js new file mode 100644 index 0000000000000000000000000000000000000000..b424aec5a837ab3f0c9f643f22cc1799def46ce4 --- /dev/null +++ b/test/built-ins/Atomics/wait/was-woken.js @@ -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; +} + diff --git a/test/built-ins/Atomics/wake/bad-range.js b/test/built-ins/Atomics/wake/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..a8085f29ed55fec79a4b7ff2655a96ab66f7c36a --- /dev/null +++ b/test/built-ins/Atomics/wake/bad-range.js @@ -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 +}); diff --git a/test/built-ins/Atomics/wake/counts.js b/test/built-ins/Atomics/wake/counts.js new file mode 100644 index 0000000000000000000000000000000000000000..732fa92d90ec399b7beb3c97011264c9f66606ed --- /dev/null +++ b/test/built-ins/Atomics/wake/counts.js @@ -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); diff --git a/test/built-ins/Atomics/wake/descriptor.js b/test/built-ins/Atomics/wake/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..006433b09172acf3e94ffec334e9cfac338ab107 --- /dev/null +++ b/test/built-ins/Atomics/wake/descriptor.js @@ -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"); diff --git a/test/built-ins/Atomics/wake/good-views.js b/test/built-ins/Atomics/wake/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..cb051c4eeb6adcebc094a24f0910e2fd2f01e5d0 --- /dev/null +++ b/test/built-ins/Atomics/wake/good-views.js @@ -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); +}); diff --git a/test/built-ins/Atomics/wake/length.js b/test/built-ins/Atomics/wake/length.js new file mode 100644 index 0000000000000000000000000000000000000000..9706bec1a2c1c2e7c5a7b3c207867319e1f1ef36 --- /dev/null +++ b/test/built-ins/Atomics/wake/length.js @@ -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"); diff --git a/test/built-ins/Atomics/wake/name.js b/test/built-ins/Atomics/wake/name.js new file mode 100644 index 0000000000000000000000000000000000000000..8a875a5fa14b72f92c9d0738fcc4a89da125664c --- /dev/null +++ b/test/built-ins/Atomics/wake/name.js @@ -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"); diff --git a/test/built-ins/Atomics/wake/non-views.js b/test/built-ins/Atomics/wake/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..be17dda2662351d79206448f895968e6742d6192 --- /dev/null +++ b/test/built-ins/Atomics/wake/non-views.js @@ -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 +}); diff --git a/test/built-ins/Atomics/wake/nonshared-int-views.js b/test/built-ins/Atomics/wake/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..51fea5db4ed5bbd34743812e6723e6835fb4f070 --- /dev/null +++ b/test/built-ins/Atomics/wake/nonshared-int-views.js @@ -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); diff --git a/test/built-ins/Atomics/wake/shared-nonint-views.js b/test/built-ins/Atomics/wake/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..02b2074c58a3972367a890f58abbee41cd66c6c2 --- /dev/null +++ b/test/built-ins/Atomics/wake/shared-nonint-views.js @@ -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); diff --git a/test/built-ins/Atomics/wake/wake-all-on-loc.js b/test/built-ins/Atomics/wake/wake-all-on-loc.js new file mode 100644 index 0000000000000000000000000000000000000000..e403df15270ce76b599abe91acbd4efb3c4b609f --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-all-on-loc.js @@ -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; +} diff --git a/test/built-ins/Atomics/wake/wake-all.js b/test/built-ins/Atomics/wake/wake-all.js new file mode 100644 index 0000000000000000000000000000000000000000..d08d49be01aa1731a83ced98f3f57dbeb39fae9f --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-all.js @@ -0,0 +1,36 @@ +// 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 if that's what the count is. +---*/ + +for ( var i=0 ; i < 3 ; i++ ) { +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + $.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We may timeout eventually + $.agent.leaving(); +}) +`); +} + +var ia = new Int32Array(new SharedArrayBuffer(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 +var rs = [getReport(), getReport(), getReport()]; +rs.sort(); +assert.sameValue(rs[0], "ok"); +assert.sameValue(rs[1], "ok"); +assert.sameValue(rs[2], "ok"); + +function getReport() { + var r; + while ((r = $.agent.getReport()) == null) + $.agent.sleep(100); + return r; +} diff --git a/test/built-ins/Atomics/wake/wake-in-order.js b/test/built-ins/Atomics/wake/wake-in-order.js new file mode 100644 index 0000000000000000000000000000000000000000..92025633f4058ac34be714c82c57177f2173ea08 --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-in-order.js @@ -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 agents in the order they are waiting. +---*/ + +// Create workers and start them all spinning. We set atomic slots to make +// them go into a wait, thus controlling the waiting order. Then we wake them +// one by one and observe the wakeup order. + +for ( var i=0 ; i < 3 ; i++ ) { +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + while (Atomics.load(ia, ${i+1}) == 0); + $.agent.report(${i} + Atomics.wait(ia, 0, 0)); + $.agent.leaving(); +}) +`); +} + +var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT*4)); +$.agent.broadcast(ia.buffer); + +// Make them sleep in order 0 1 2 on ia[0] +for ( var i=0 ; i < 3 ; i++ ) { + Atomics.store(ia, i+1, 1); + $.agent.sleep(500); +} + +// Wake them up one at a time and check the order is 0 1 2 +for ( var i=0 ; i < 3 ; i++ ) { + assert.sameValue(Atomics.wake(ia, 0, 1), 1); + assert.sameValue(getReport(), i + "ok"); +} + +function getReport() { + var r; + while ((r = $.agent.getReport()) == null) + $.agent.sleep(100); + return r; +} + + diff --git a/test/built-ins/Atomics/wake/wake-nan.js b/test/built-ins/Atomics/wake/wake-nan.js new file mode 100644 index 0000000000000000000000000000000000000000..945f503ffb95b72fb8fa7a8d028ad3bb546c9d56 --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-nan.js @@ -0,0 +1,30 @@ +// 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 zero waiters if the count is NaN +---*/ + +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + $.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We will timeout eventually + $.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 +assert.sameValue(Atomics.wake(ia, 0, NaN), 0); // Don't actually wake it +assert.sameValue(getReport(), "timed-out"); + +function getReport() { + var r; + while ((r = $.agent.getReport()) == null) + $.agent.sleep(100); + return r; +} diff --git a/test/built-ins/Atomics/wake/wake-negative.js b/test/built-ins/Atomics/wake/wake-negative.js new file mode 100644 index 0000000000000000000000000000000000000000..56755aece73e6e2c8ecb2fdabb993cd4fa3e31e6 --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-negative.js @@ -0,0 +1,30 @@ +// 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 zero waiters if the count is negative +---*/ + +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + $.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We will timeout eventually + $.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 +assert.sameValue(Atomics.wake(ia, 0, -1), 0); // Don't actually wake it +assert.sameValue(getReport(), "timed-out"); + +function getReport() { + var r; + while ((r = $.agent.getReport()) == null) + $.agent.sleep(100); + return r; +} diff --git a/test/built-ins/Atomics/wake/wake-one.js b/test/built-ins/Atomics/wake/wake-one.js new file mode 100644 index 0000000000000000000000000000000000000000..1b4ab094bb74261b8f7a73fd2d477f4643e600cb --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-one.js @@ -0,0 +1,42 @@ +// 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 one waiter if that's what the count is. +---*/ + +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + $.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We may timeout eventually + $.agent.leaving(); +}) +`); + +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + $.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We may timeout eventually + $.agent.leaving(); +}) +`); + +var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); + +$.agent.broadcast(ia.buffer); +$.agent.sleep(500); // Give the agents a chance to wait +assert.sameValue(Atomics.wake(ia, 0, 1), 1); // Wake one +var rs = [getReport(), getReport()]; +rs.sort(); +assert.sameValue(rs[0], "ok"); +assert.sameValue(rs[1], "timed-out"); + +function getReport() { + var r; + while ((r = $.agent.getReport()) == null) + $.agent.sleep(100); + return r; +} diff --git a/test/built-ins/Atomics/wake/wake-two.js b/test/built-ins/Atomics/wake/wake-two.js new file mode 100644 index 0000000000000000000000000000000000000000..b7d970f27c44361e94c86f03a98171ee81980af3 --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-two.js @@ -0,0 +1,36 @@ +// 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 two waiters if that's what the count is. +---*/ + +for ( var i=0 ; i < 3 ; i++ ) { +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + $.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We may timeout eventually + $.agent.leaving(); +}) +`); +} + +var ia = new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)); + +$.agent.broadcast(ia.buffer); +$.agent.sleep(500); // Give the agents a chance to wait +assert.sameValue(Atomics.wake(ia, 0, 2), 2); // Wake two +var rs = [getReport(), getReport(), getReport()]; +rs.sort(); +assert.sameValue(rs[0], "ok"); +assert.sameValue(rs[1], "ok"); +assert.sameValue(rs[2], "timed-out"); + +function getReport() { + var r; + while ((r = $.agent.getReport()) == null) + $.agent.sleep(100); + return r; +} diff --git a/test/built-ins/Atomics/wake/wake-zero.js b/test/built-ins/Atomics/wake/wake-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..6b00dd2a4c3860c23290f262f8e2cc2ce5569365 --- /dev/null +++ b/test/built-ins/Atomics/wake/wake-zero.js @@ -0,0 +1,30 @@ +// 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 zero waiters if that's what the count is. +---*/ + +$.agent.start( +` +$.agent.receiveBroadcast(function (sab) { + var ia = new Int32Array(sab); + $.agent.report(Atomics.wait(ia, 0, 0, 1000)); // We will timeout eventually + $.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 +assert.sameValue(Atomics.wake(ia, 0, 0), 0); // Don't actually wake it +assert.sameValue(getReport(), "timed-out"); + +function getReport() { + var r; + while ((r = $.agent.getReport()) == null) + $.agent.sleep(100); + return r; +} diff --git a/test/built-ins/Atomics/xor/bad-range.js b/test/built-ins/Atomics/xor/bad-range.js new file mode 100644 index 0000000000000000000000000000000000000000..ed19315b955047aa79bd10770521eb95bb6a242b --- /dev/null +++ b/test/built-ins/Atomics/xor/bad-range.js @@ -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.xor 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.xor(view, Idx, 0)); + }); +}, views); diff --git a/test/built-ins/Atomics/xor/descriptor.js b/test/built-ins/Atomics/xor/descriptor.js new file mode 100644 index 0000000000000000000000000000000000000000..8bd1aaa8b3b9bfcb8d8df4ab81fcaf134da7e8a6 --- /dev/null +++ b/test/built-ins/Atomics/xor/descriptor.js @@ -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.xor +includes: [propertyHelper.js] +---*/ + +verifyWritable(Atomics, "xor"); +verifyNotEnumerable(Atomics, "xor"); +verifyConfigurable(Atomics, "xor"); diff --git a/test/built-ins/Atomics/xor/good-views.js b/test/built-ins/Atomics/xor/good-views.js new file mode 100644 index 0000000000000000000000000000000000000000..3e10d25a8d3e3493513a372ab1e7d6519254a3a7 --- /dev/null +++ b/test/built-ins/Atomics/xor/good-views.js @@ -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.xor 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.xor(view, 8, 0x55555555), control[0], + "Result is subject to chopping"); + + control[0] = 0x66666666; + assert.sameValue(view[8], control[0]); + assert.sameValue(Atomics.xor(view, 8, 0xF0F0F0F0), control[0], + "Result is subject to chopping"); + + control[0] = 0x96969696; + assert.sameValue(view[8], control[0]); + + view[3] = -5; + control[0] = -5; + assert.sameValue(Atomics.xor(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.xor(view, 3, 0), control[0], + "Result is subject to chopping"); + assert.sameValue(view[3], control[0]); + + // And again + control[0] = 123456789; + view[3] = 123456789; + assert.sameValue(Atomics.xor(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.xor(view, Idx, 0), 37); + }); +}, int_views); diff --git a/test/built-ins/Atomics/xor/length.js b/test/built-ins/Atomics/xor/length.js new file mode 100644 index 0000000000000000000000000000000000000000..65bf3df885a1be5ed44f0466b2bb28a57a5e7407 --- /dev/null +++ b/test/built-ins/Atomics/xor/length.js @@ -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.xor.length is 3. +info: > + Atomics.xor ( 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.xor.length, 3); + +verifyNotEnumerable(Atomics.xor, "length"); +verifyNotWritable(Atomics.xor, "length"); +verifyConfigurable(Atomics.xor, "length"); diff --git a/test/built-ins/Atomics/xor/name.js b/test/built-ins/Atomics/xor/name.js new file mode 100644 index 0000000000000000000000000000000000000000..720f5ac7d1e7a7766322716af4a7662da01a19f5 --- /dev/null +++ b/test/built-ins/Atomics/xor/name.js @@ -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.xor.name is "xor". +includes: [propertyHelper.js] +---*/ + +assert.sameValue(Atomics.xor.name, "xor"); + +verifyNotEnumerable(Atomics.xor, "name"); +verifyNotWritable(Atomics.xor, "name"); +verifyConfigurable(Atomics.xor, "name"); diff --git a/test/built-ins/Atomics/xor/non-views.js b/test/built-ins/Atomics/xor/non-views.js new file mode 100644 index 0000000000000000000000000000000000000000..59293b75be0c3f7b038aa375cbd9a31772e01ab1 --- /dev/null +++ b/test/built-ins/Atomics/xor/non-views.js @@ -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.xor on view values other than TypedArrays +includes: [testAtomics.js] +---*/ + +testWithAtomicsNonViewValues(function(view) { + assert.throws(TypeError, (() => Atomics.xor(view, 0, 0))); +}); diff --git a/test/built-ins/Atomics/xor/nonshared-int-views.js b/test/built-ins/Atomics/xor/nonshared-int-views.js new file mode 100644 index 0000000000000000000000000000000000000000..a3652b229f9553557318d9555795e535be048a2d --- /dev/null +++ b/test/built-ins/Atomics/xor/nonshared-int-views.js @@ -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.xor 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.xor(view, 0, 0))); +}, int_views); diff --git a/test/built-ins/Atomics/xor/shared-nonint-views.js b/test/built-ins/Atomics/xor/shared-nonint-views.js new file mode 100644 index 0000000000000000000000000000000000000000..af5d8910aa862a641c8eb25776902f2548d554d7 --- /dev/null +++ b/test/built-ins/Atomics/xor/shared-nonint-views.js @@ -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.xor 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.xor(view, 0, 0))); +}, other_views); diff --git a/test/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws-sab.js b/test/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..0edf058f6269e8d6c2dc0e9dc573e46468f37f94 --- /dev/null +++ b/test/built-ins/DataView/buffer-does-not-have-arraybuffer-data-throws-sab.js @@ -0,0 +1,43 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if buffer does not have [[ArrayBufferData]] +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 2. If Type(buffer) is not Object, throw a TypeError exception. + 3. If buffer does not have an [[ArrayBufferData]] internal slot, throw a + TypeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("buffer should be verified before byteOffset"); + } +}; + +assert.throws(TypeError, function() { + new DataView({}, obj); +}, "{}"); + +assert.throws(TypeError, function() { + new DataView([], obj); +}, "[]"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + new DataView(ta, obj); +}, "typedArray instance"); + +var other = new DataView(new SharedArrayBuffer(1), 0); +assert.throws(TypeError, function() { + new DataView(other, obj); +}, "dataView instance"); diff --git a/test/built-ins/DataView/buffer-reference-sab.js b/test/built-ins/DataView/buffer-reference-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..e1b8b3855b8ee09a9ca72a44044c28d56f62a37d --- /dev/null +++ b/test/built-ins/DataView/buffer-reference-sab.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Reuse buffer argument instead of making a new clone +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 14. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var dv1 = new DataView(buffer, 0); +var dv2 = new DataView(buffer, 0); + +assert.sameValue(dv1.buffer, buffer); +assert.sameValue(dv2.buffer, buffer); diff --git a/test/built-ins/DataView/byteoffset-is-negative-throws-sab.js b/test/built-ins/DataView/byteoffset-is-negative-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..98dc9faa5396cbbcdb54f9bc857766a626b6a5bf --- /dev/null +++ b/test/built-ins/DataView/byteoffset-is-negative-throws-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + 5. Let offset be ToInteger(numberOffset). + 6. If numberOffset ≠offset or offset < 0, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var ab = new SharedArrayBuffer(42); + +assert.throws(RangeError, function() { + new DataView(ab, -1); +}, "-1"); + +assert.throws(RangeError, function() { + new DataView(ab, -Infinity); +}, "-Infinity"); diff --git a/test/built-ins/DataView/custom-proto-access-throws-sab.js b/test/built-ins/DataView/custom-proto-access-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..fca677f51f340486daf92bed4b4f602d5d0a12e3 --- /dev/null +++ b/test/built-ins/DataView/custom-proto-access-throws-sab.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from newTarget's custom constructor prototype +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect.construct, SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +assert.throws(Test262Error, function() { + Reflect.construct(DataView, [buffer, 0], newTarget); +}); diff --git a/test/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype-sab.js b/test/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..accdd4125d13f9d3385789cd20455867c6f0c530 --- /dev/null +++ b/test/built-ins/DataView/custom-proto-if-not-object-fallbacks-to-default-prototype-sab.js @@ -0,0 +1,47 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Use DataView.prototype if newTarget's prototype is not an Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct, SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/custom-proto-if-object-is-used-sab.js b/test/built-ins/DataView/custom-proto-if-object-is-used-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..732cdc8fa69a7d70200ae94366174fe748816a17 --- /dev/null +++ b/test/built-ins/DataView/custom-proto-if-object-is-used-sab.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Use newTarget's custom constructor prototype if Object +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 2. Let proto be ? GetPrototypeFromConstructor(constructor, + intrinsicDefaultProto). + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. + ... +features: [Reflect.construct, SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +var sample = Reflect.construct(DataView, [buffer, 0], newTarget); + +assert.sameValue(sample.constructor, Object); +assert.sameValue(Object.getPrototypeOf(sample), proto); diff --git a/test/built-ins/DataView/defined-bytelength-and-byteoffset-sab.js b/test/built-ins/DataView/defined-bytelength-and-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..1e5dc9a83d584a28a928210286509a9b819f5bee --- /dev/null +++ b/test/built-ins/DataView/defined-bytelength-and-byteoffset-sab.js @@ -0,0 +1,61 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined length and offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(3); + +sample = new DataView(buffer, 1, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 3); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, 0); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 1); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 0, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer, "sample.buffer"); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/defined-byteoffset-sab.js b/test/built-ins/DataView/defined-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..b15aa54e8d3d15533e4cf9c9dcf166c5f593f5fa --- /dev/null +++ b/test/built-ins/DataView/defined-byteoffset-sab.js @@ -0,0 +1,54 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined offset +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(4); + +sample = new DataView(buffer, 0); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/defined-byteoffset-undefined-bytelength-sab.js b/test/built-ins/DataView/defined-byteoffset-undefined-bytelength-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..1fd6f27f06e0523f39fb70c782e71a2154e1c1aa --- /dev/null +++ b/test/built-ins/DataView/defined-byteoffset-undefined-bytelength-sab.js @@ -0,0 +1,57 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return new instance from defined byteoffset and undefined bytelength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(4); + +sample = new DataView(buffer, 0, undefined); +assert.sameValue(sample.byteLength, 4, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 0, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 1, undefined); +assert.sameValue(sample.byteLength, 3, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 1, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 2, undefined); +assert.sameValue(sample.byteLength, 2, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 2, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 3, undefined); +assert.sameValue(sample.byteLength, 1, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 3, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +sample = new DataView(buffer, 4, undefined); +assert.sameValue(sample.byteLength, 0, "sample.byteLength"); +assert.sameValue(sample.byteOffset, 4, "sample.byteOffset"); +assert.sameValue(sample.buffer, buffer); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/excessive-bytelength-throws-sab.js b/test/built-ins/DataView/excessive-bytelength-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..c0d4f6f8bcd0d564b976d4a437773b8f4afe1cda --- /dev/null +++ b/test/built-ins/DataView/excessive-bytelength-throws-sab.js @@ -0,0 +1,56 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws RangeError if offset + viewByteLength > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + ... + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + b. If offset+viewByteLength > bufferByteLength, throw a RangeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(3); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, 4); +}, "offset: 0, length 4"); + +assert.throws(RangeError, function() { + new DataView(buffer, 1, 3); +}, "offset: 1, length: 3"); + +assert.throws(RangeError, function() { + new DataView(buffer, 2, 2); +}, "offset: 2, length: 2"); + +assert.throws(RangeError, function() { + new DataView(buffer, 3, 1); +}, "offset: 3, length: 1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, 0); +}, "offset: 4, length: 0"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -1); +}, "offset: 4, length: -1"); + +assert.throws(RangeError, function() { + new DataView(buffer, 4, -Infinity); +}, "offset: 4, length: -Infinity"); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, Infinity); +}, "offset: 0, length: Infinity"); diff --git a/test/built-ins/DataView/excessive-byteoffset-throws-sab.js b/test/built-ins/DataView/excessive-byteoffset-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..e66bb7e3ee3410744b793ef12a880d081dcf2752 --- /dev/null +++ b/test/built-ins/DataView/excessive-byteoffset-throws-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if offset > bufferByteLength +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. Let bufferByteLength be the value of buffer's [[ArrayBufferByteLength]] + internal slot. + 9. If offset > bufferByteLength, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var ab = new SharedArrayBuffer(1); + +assert.throws(RangeError, function() { + new DataView(ab, 2); +}, "2"); + +assert.throws(RangeError, function() { + new DataView(ab, Infinity); +}, "Infinity"); diff --git a/test/built-ins/DataView/instance-extensibility-sab.js b/test/built-ins/DataView/instance-extensibility-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..1c583ac96c09b0968b260fa5b167819a9aa7461c --- /dev/null +++ b/test/built-ins/DataView/instance-extensibility-sab.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + The new instance is extensible +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. + + 9.1.13 OrdinaryCreateFromConstructor ( constructor, intrinsicDefaultProto [ , + internalSlotsList ] ) + + ... + 3. Return ObjectCreate(proto, internalSlotsList). + + 9.1.12 ObjectCreate (proto [ , internalSlotsList ]) + + ... + 5. Set the [[Extensible]] internal slot of obj to true. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert(Object.isExtensible(sample)); diff --git a/test/built-ins/DataView/negative-bytelength-throws-sab.js b/test/built-ins/DataView/negative-bytelength-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..52dadc6c1cb08331ec2b27e99b22df6755a3fb74 --- /dev/null +++ b/test/built-ins/DataView/negative-bytelength-throws-sab.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteLength) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 9. Else, + a. Let viewByteLength be ? ToIndex(byteLength). + ... + + ToIndex ( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(2); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, -1); +}, "new DataView(buffer, 0, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 0, -Infinity); +}, "new DataView(buffer, 0, -Infinity);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 1, -1); +}, "new DataView(buffer, 1, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, 2, -Infinity); +}, "new DataView(buffer, 2, -Infinity);"); diff --git a/test/built-ins/DataView/negative-byteoffset-throws-sab.js b/test/built-ins/DataView/negative-byteoffset-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..65b1eda87156113e39417f65edd134f5b01629ff --- /dev/null +++ b/test/built-ins/DataView/negative-byteoffset-throws-sab.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a RangeError if ToInteger(byteOffset) < 0 +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let offset be ? ToIndex(byteOffset). + ... + + ToIndex ( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(2); + +assert.throws(RangeError, function() { + new DataView(buffer, -1); +}, "new DataView(buffer, -1);"); + +assert.throws(RangeError, function() { + new DataView(buffer, -Infinity); +}, "new DataView(buffer, -Infinity);"); diff --git a/test/built-ins/DataView/newtarget-undefined-throws-sab.js b/test/built-ins/DataView/newtarget-undefined-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..cc7d4593f1af8284a61638725024d55209767adb --- /dev/null +++ b/test/built-ins/DataView/newtarget-undefined-throws-sab.js @@ -0,0 +1,28 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Throws a TypeError if NewTarget is undefined. +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error("NewTarget should be verified before byteOffset"); + } +}; + +var buffer = new SharedArrayBuffer(1); + +assert.throws(TypeError, function() { + DataView(buffer, obj); +}); diff --git a/test/built-ins/DataView/proto-from-ctor-realm-sab.js b/test/built-ins/DataView/proto-from-ctor-realm-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..81166659c3ce60f2847c808fd0db6907aa04b0e7 --- /dev/null +++ b/test/built-ins/DataView/proto-from-ctor-realm-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-dataview-buffer-byteoffset-bytelength +es6id: 24.2.2.1 +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, + "%DataViewPrototype%", « [[DataView]], [[ViewedArrayBuffer]], + [[ByteLength]], [[ByteOffset]] »). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [Reflect, SharedArrayBuffer] +---*/ + +var other = $.createRealm().global; +var C = new other.Function(); +C.prototype = null; +var buffer = new SharedArrayBuffer(0); + +var o = Reflect.construct(DataView, [buffer, 0], C); + +assert.sameValue(Object.getPrototypeOf(o), other.DataView.prototype); diff --git a/test/built-ins/DataView/prototype/buffer/return-buffer-sab.js b/test/built-ins/DataView/prototype/buffer/return-buffer-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..9e11cd9307db08e2768b0ef76bf07bbb65e02ba9 --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/return-buffer-sab.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.buffer +es6id: 24.2.4.1 +description: > + Return buffer from [[ViewedArrayBuffer]] internal slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + ... + 5. Let buffer be the value of O's [[ViewedArrayBuffer]] internal slot. + 6. Return buffer. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(1); +var dv = new DataView(buffer, 0); + +assert.sameValue(dv.buffer, buffer); diff --git a/test/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal-sab.js b/test/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..4f3c79b56c7d0c9b7cbb4aabf99430e9a32674f5 --- /dev/null +++ b/test/built-ins/DataView/prototype/buffer/this-has-no-dataview-internal-sab.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.buffer +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.1 get DataView.prototype.buffer + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "buffer" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); diff --git a/test/built-ins/DataView/prototype/byteLength/return-bytelength-sab.js b/test/built-ins/DataView/prototype/byteLength/return-bytelength-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..200c6dbbdf7020983650c8a87fafc4bff8a9dffc --- /dev/null +++ b/test/built-ins/DataView/prototype/byteLength/return-bytelength-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.bytelength +es6id: 24.2.4.2 +description: > + Return value from [[ByteLength]] internal slot +info: | + 24.2.4.2 get DataView.prototype.byteLength + + ... + 7. Let size be the value of O's [[ByteLength]] internal slot. + 8. Return size. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); + +var sample1 = new DataView(buffer, 0); +var sample2 = new DataView(buffer, 4); +var sample3 = new DataView(buffer, 6, 4); +var sample4 = new DataView(buffer, 12); + +assert.sameValue(sample1.byteLength, 12); +assert.sameValue(sample2.byteLength, 8); +assert.sameValue(sample3.byteLength, 4); +assert.sameValue(sample4.byteLength, 0); diff --git a/test/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal-sab.js b/test/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..dd5335260d2bf4d3ba6f7849b351ef8deca1887a --- /dev/null +++ b/test/built-ins/DataView/prototype/byteLength/this-has-no-dataview-internal-sab.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.bytelength +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.2 get DataView.prototype.byteLength + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); diff --git a/test/built-ins/DataView/prototype/byteOffset/return-byteoffset-sab.js b/test/built-ins/DataView/prototype/byteOffset/return-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..b4fb8cfc717fe65f52b7b132ed7598cb6ac25321 --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/return-byteoffset-sab.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.byteoffset +es6id: 24.2.4.3 +description: > + Return value from [[ByteOffset]] internal slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + ... + 7. Let offset be the value of O's [[ByteOffset]] internal slot. + 8. Return offset. +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); + +var sample1 = new DataView(buffer, 0); +var sample2 = new DataView(buffer, 4); +var sample3 = new DataView(buffer, 6, 4); +var sample4 = new DataView(buffer, 12); +var sample5 = new DataView(buffer, 0, 2); + +assert.sameValue(sample1.byteOffset, 0); +assert.sameValue(sample2.byteOffset, 4); +assert.sameValue(sample3.byteOffset, 6); +assert.sameValue(sample4.byteOffset, 12); +assert.sameValue(sample5.byteOffset, 0); diff --git a/test/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal-sab.js b/test/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..6fb2757212fd2291273d0d0bbbfad77d06ac170a --- /dev/null +++ b/test/built-ins/DataView/prototype/byteOffset/this-has-no-dataview-internal-sab.js @@ -0,0 +1,41 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-get-dataview.prototype.byteoffset +description: > + Throws a TypeError exception when `this` does not have a [[DataView]] internal + slot +info: | + 24.2.4.3 get DataView.prototype.byteOffset + + 1. Let O be the this value. + 2. If Type(O) is not Object, throw a TypeError exception. + 3. If O does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + DataView.prototype, "byteOffset" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getter.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(8); +assert.throws(TypeError, function() { + getter.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getter.call(ta); +}, "TypedArray"); diff --git a/test/built-ins/DataView/prototype/getInt32/index-is-out-of-range-sab.js b/test/built-ins/DataView/prototype/getInt32/index-is-out-of-range-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..d70aa75a4d3569269de759c80e2d384e513b9771 --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/index-is-out-of-range-sab.js @@ -0,0 +1,86 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Throws a RangeError if getIndex + elementSize > viewSize +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 10. Let viewOffset be the value of view's [[ByteOffset]] internal slot. + 11. Let viewSize be the value of view's [[ByteLength]] internal slot. + 12. Let elementSize be the Number value of the Element Size value specified in + Table 50 for Element Type type. + 13. If getIndex + elementSize > viewSize, throw a RangeError exception. + ... +features: [SharedArrayBuffer] +---*/ + +var sample; +var buffer = new SharedArrayBuffer(12); + +sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt32(Infinity); +}, "getIndex == Infinity"); + +assert.throws(RangeError, function() { + sample.getInt32(13); +}, "13 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(12); +}, "12 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(11); +}, "11 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(10); +}, "10 + 4 > 12"); + +assert.throws(RangeError, function() { + sample.getInt32(9); +}, "9 + 4 > 12"); + +sample = new DataView(buffer, 8); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (offset)"); + +sample = new DataView(buffer, 9); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (offset)"); + +sample = new DataView(buffer, 0, 4); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (length)"); + +sample = new DataView(buffer, 0, 3); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (length)"); + +sample = new DataView(buffer, 4, 4); +assert.throws(RangeError, function() { + sample.getInt32(1); +}, "1 + 4 > 4 (offset+length)"); + +sample = new DataView(buffer, 4, 3); +assert.throws(RangeError, function() { + sample.getInt32(0); +}, "0 + 4 > 3 (offset+length)"); diff --git a/test/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws-sab.js b/test/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..79fca0de06a4d8edfa4c1b2ef8519676820e4ec3 --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/negative-byteoffset-throws-sab.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Throws a RangeError if getIndex < 0 +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); +var sample = new DataView(buffer, 0); + +assert.throws(RangeError, function() { + sample.getInt32(-1); +}, "-1"); + +assert.throws(RangeError, function() { + sample.getInt32(-Infinity); +}, "-Infinity"); diff --git a/test/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-sab.js b/test/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..2e278691410d3ab855e96e20a208bad6c63e2bd9 --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-sab.js @@ -0,0 +1,46 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var bo1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var bo2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + sample.getInt32(bo1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + sample.getInt32(bo2); +}, "toString"); diff --git a/test/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol-sab.js b/test/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..d87f83f0e9ec0a38ac9965b0d43365898c7111fa --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/return-abrupt-from-tonumber-byteoffset-symbol-sab.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let numberIndex be ? ToNumber(requestIndex). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(1); +var sample = new DataView(buffer, 0); + +var s = Symbol("1"); + +assert.throws(TypeError, function() { + sample.getInt32(s); +}); diff --git a/test/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer-sab.js b/test/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..1f353ccd28c7ac4dd9dd42f78fea77222d27a03f --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/return-value-clean-arraybuffer-sab.js @@ -0,0 +1,45 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Return value from Buffer using a clean ArrayBuffer +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var sample = new DataView(buffer, 0); + +assert.sameValue(sample.getInt32(0, true), 0, "sample.getInt32(0, true)"); +assert.sameValue(sample.getInt32(1, true), 0, "sample.getInt32(1, true)"); +assert.sameValue(sample.getInt32(2, true), 0, "sample.getInt32(2, true)"); +assert.sameValue(sample.getInt32(3, true), 0, "sample.getInt32(3, true)"); +assert.sameValue(sample.getInt32(4, true), 0, "sample.getInt32(4, true)"); +assert.sameValue(sample.getInt32(0, false), 0, "sample.getInt32(0, false)"); +assert.sameValue(sample.getInt32(1, false), 0, "sample.getInt32(1, false)"); +assert.sameValue(sample.getInt32(2, false), 0, "sample.getInt32(2, false)"); +assert.sameValue(sample.getInt32(3, false), 0, "sample.getInt32(3, false)"); +assert.sameValue(sample.getInt32(4, false), 0, "sample.getInt32(4, false)"); diff --git a/test/built-ins/DataView/prototype/getInt32/return-values-custom-offset-sab.js b/test/built-ins/DataView/prototype/getInt32/return-values-custom-offset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..e2ec73cd1c890650c5cbe3c8954a099e2dc1647b --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/return-values-custom-offset-sab.js @@ -0,0 +1,59 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Return values from Buffer using a custom offset +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 39); +sample.setUint8(1, 2); +sample.setUint8(2, 6); +sample.setUint8(3, 2); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 128); +sample.setUint8(7, 1); +sample.setUint8(8, 127); +sample.setUint8(9, 0); +sample.setUint8(10, 127); +sample.setUint8(11, 1); + +sample = new DataView(buffer, 4); + +assert.sameValue(sample.getInt32(0, false), -2147450879, "0, false"); +assert.sameValue(sample.getInt32(1, false), 8388991, "1, false"); +assert.sameValue(sample.getInt32(2, false), -2147385600, "2, false"); +assert.sameValue(sample.getInt32(3, false), 25100415, "3, false"); + +assert.sameValue(sample.getInt32(0, true), 25165952, "0, true"); +assert.sameValue(sample.getInt32(1, true), 2130804736, "1, true"); +assert.sameValue(sample.getInt32(2, true), 8323456, "2, true"); +assert.sameValue(sample.getInt32(3, true), 2130738945, "3, true"); diff --git a/test/built-ins/DataView/prototype/getInt32/return-values-sab.js b/test/built-ins/DataView/prototype/getInt32/return-values-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..87e0427bc3167175b78f7eab49acb61ceddb9171 --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/return-values-sab.js @@ -0,0 +1,67 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Return values from Buffer +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(12); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 0); +sample.setUint8(6, 0); +sample.setUint8(7, 0); +sample.setUint8(8, 1); +sample.setUint8(9, 0); +sample.setUint8(10, 0); +sample.setUint8(11, 0); + +assert.sameValue(sample.getInt32(0, false), 2147483647, "0, false"); // 2**32-1 +assert.sameValue(sample.getInt32(1, false), -128, "1, false"); +assert.sameValue(sample.getInt32(2, false), -32768, "2, false"); +assert.sameValue(sample.getInt32(3, false), -8388608, "3, false"); +assert.sameValue(sample.getInt32(4, false), -2147483648, "4, false"); +assert.sameValue(sample.getInt32(5, false), 1, "5, false"); +assert.sameValue(sample.getInt32(6, false), 256, "6, false"); +assert.sameValue(sample.getInt32(7, false), 65536, "7, false"); +assert.sameValue(sample.getInt32(8, false), 16777216, "8, false"); + +assert.sameValue(sample.getInt32(0, true), -129, "0, true"); +assert.sameValue(sample.getInt32(1, true), -2130706433, "1, true"); +assert.sameValue(sample.getInt32(2, true), 8454143, "2, true"); +assert.sameValue(sample.getInt32(3, true), 33023, "3, true"); +assert.sameValue(sample.getInt32(4, true), 128, "4, true"); +assert.sameValue(sample.getInt32(5, true), 16777216, "5, true"); +assert.sameValue(sample.getInt32(6, true), 65536, "6, true"); +assert.sameValue(sample.getInt32(7, true), 256, "7, true"); +assert.sameValue(sample.getInt32(8, true), 1, "8, true"); diff --git a/test/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal-sab.js b/test/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..c9c1339b7f6922f59040cc6acc15f8ecea764109 --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/this-has-no-dataview-internal-sab.js @@ -0,0 +1,44 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Throws a TypeError if this does not have a [[DataView]] internal slot +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + 1. If Type(view) is not Object, throw a TypeError exception. + 2. If view does not have a [[DataView]] internal slot, throw a TypeError + exception. + ... +features: [SharedArrayBuffer] +---*/ + +var getInt32 = DataView.prototype.getInt32; + +assert.throws(TypeError, function() { + getInt32.call({}); +}, "{}"); + +assert.throws(TypeError, function() { + getInt32.call([]); +}, "[]"); + +var ab = new SharedArrayBuffer(1); +assert.throws(TypeError, function() { + getInt32.call(ab); +}, "ArrayBuffer"); + +var ta = new Int8Array(); +assert.throws(TypeError, function() { + getInt32.call(ta); +}, "TypedArray"); diff --git a/test/built-ins/DataView/prototype/getInt32/to-boolean-littleendian-sab.js b/test/built-ins/DataView/prototype/getInt32/to-boolean-littleendian-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..5e4c3c9ad9eb9826a27ef500c325906444ec3a3e --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/to-boolean-littleendian-sab.js @@ -0,0 +1,52 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +es6id: 24.2.4.9 +description: > + Boolean littleEndian argument coerced in ToBoolean +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 14. Let bufferIndex be getIndex + viewOffset. + 15. Return GetValueFromBuffer(buffer, bufferIndex, type, isLittleEndian). + ... + + 24.1.1.5 GetValueFromBuffer ( arrayBuffer, byteIndex, type [ , isLittleEndian + ] ) + + ... + 8. If isLittleEndian is false, reverse the order of the elements of rawValue. + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(4); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 0); +sample.setUint8(1, 17); +sample.setUint8(2, 4); +sample.setUint8(3, 0); + +// False +assert.sameValue(sample.getInt32(0), 1115136, "no arg"); +assert.sameValue(sample.getInt32(0, undefined), 1115136, "undefined"); +assert.sameValue(sample.getInt32(0, null), 1115136, "null"); +assert.sameValue(sample.getInt32(0, 0), 1115136, "0"); +assert.sameValue(sample.getInt32(0, ""), 1115136, "the empty string"); + +// True +assert.sameValue(sample.getInt32(0, {}), 266496, "{}"); +assert.sameValue(sample.getInt32(0, Symbol("1")), 266496, "symbol"); +assert.sameValue(sample.getInt32(0, 1), 266496, "1"); +assert.sameValue(sample.getInt32(0, "string"), 266496, "string"); diff --git a/test/built-ins/DataView/prototype/getInt32/toindex-byteoffset-sab.js b/test/built-ins/DataView/prototype/getInt32/toindex-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..25d659b23f193a032de3f61017e1a8ca7d74d244 --- /dev/null +++ b/test/built-ins/DataView/prototype/getInt32/toindex-byteoffset-sab.js @@ -0,0 +1,65 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview.prototype.getint32 +description: > + ToIndex conversions on byteOffset +info: | + 24.2.4.9 DataView.prototype.getInt32 ( byteOffset [ , littleEndian ] ) + + 1. Let v be the this value. + 2. If littleEndian is not present, let littleEndian be false. + 3. Return ? GetViewValue(v, byteOffset, littleEndian, "Int32"). + + 24.2.1.1 GetViewValue ( view, requestIndex, isLittleEndian, type ) + + ... + 4. Let getIndex be ? ToIndex(requestIndex). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var sample = new DataView(buffer, 0); + +sample.setUint8(0, 127); +sample.setUint8(1, 255); +sample.setUint8(2, 255); +sample.setUint8(3, 255); +sample.setUint8(4, 128); +sample.setUint8(5, 255); +sample.setUint8(6, 255); +sample.setUint8(7, 255); + +var obj1 = { + valueOf: function() { + return 2; + } +}; + +var obj2 = { + toString: function() { + return 3; + } +}; + +assert.sameValue(sample.getInt32(-0), 2147483647, "-0"); +assert.sameValue(sample.getInt32(obj1), -32513, "object's valueOf"); +assert.sameValue(sample.getInt32(obj2), -8323073, "object's toString"); +assert.sameValue(sample.getInt32(""), 2147483647, "the Empty string"); +assert.sameValue(sample.getInt32("0"), 2147483647, "string '0'"); +assert.sameValue(sample.getInt32("2"), -32513, "string '2'"); +assert.sameValue(sample.getInt32(true), -128, "true"); +assert.sameValue(sample.getInt32(false), 2147483647, "false"); +assert.sameValue(sample.getInt32(NaN), 2147483647, "NaN"); +assert.sameValue(sample.getInt32(null), 2147483647, "null"); +assert.sameValue(sample.getInt32(0.1), 2147483647, "0.1"); +assert.sameValue(sample.getInt32(0.9), 2147483647, "0.9"); +assert.sameValue(sample.getInt32(1.1), -128, "1.1"); +assert.sameValue(sample.getInt32(1.9), -128, "1.9"); +assert.sameValue(sample.getInt32(-0.1), 2147483647, "-0.1"); +assert.sameValue(sample.getInt32(-0.99999), 2147483647, "-0.99999"); +assert.sameValue(sample.getInt32(undefined), 2147483647, "undefined"); +assert.sameValue(sample.getInt32(), 2147483647, "no arg"); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-bytelength-sab.js b/test/built-ins/DataView/return-abrupt-tonumber-bytelength-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..241f0b4e14c427b7d28fe02c88c0fc9a3e0d36d2 --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-bytelength-sab.js @@ -0,0 +1,42 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var obj1 = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var obj2 = { + toString: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj1); +}, "valueOf"); + +assert.throws(Test262Error, function() { + new DataView(buffer, 0, obj2); +}, "toString"); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol-sab.js b/test/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..4c2d3cd9d88833a6474a52aac6ab652475b3f429 --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-bytelength-symbol-sab.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToLength(symbol byteLength) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 10. If byteLength is undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 11. Else, + a. Let viewByteLength be ? ToLength(byteLength). + ... +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var length = Symbol("1"); + +assert.throws(TypeError, function() { + new DataView(buffer, 0, length); +}); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-sab.js b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..9b4e85d60b2ebec7784dedc1068924bc546ebc46 --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +features: [SharedArrayBuffer] +---*/ + +var obj = { + valueOf: function() { + throw new Test262Error(); + } +}; + +var ab = new SharedArrayBuffer(0); + +assert.throws(Test262Error, function() { + new DataView(ab, obj); +}); diff --git a/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol-sab.js b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..c18eba88348b69d1f6d0e928266aa5871d8de28a --- /dev/null +++ b/test/built-ins/DataView/return-abrupt-tonumber-byteoffset-symbol-sab.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Return abrupt from ToNumber(symbol byteOffset) +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 4. Let numberOffset be ? ToNumber(byteOffset). + ... +features: [SharedArrayBuffer] +---*/ + +var s = Symbol("1"); +var ab = new SharedArrayBuffer(0); + +assert.throws(TypeError, function() { + new DataView(ab, s); +}); diff --git a/test/built-ins/DataView/return-instance-sab.js b/test/built-ins/DataView/return-instance-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..b306046e9a169ddf7d2d9bc601026dc968068f95 --- /dev/null +++ b/test/built-ins/DataView/return-instance-sab.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +es6id: 24.2.2.1 +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + Returns new instance +info: | + 24.2.2.1 DataView (buffer, byteOffset, byteLength ) + + ... + 12. Let O be ? OrdinaryCreateFromConstructor(NewTarget, "%DataViewPrototype%", + « [[DataView]], [[ViewedArrayBuffer]], [[ByteLength]], [[ByteOffset]] »). + ... + 17. Return O. +features: [SharedArrayBuffer] +---*/ + +var ab, sample; + +ab = new SharedArrayBuffer(1); +sample = new DataView(ab, 0); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); + +ab = new SharedArrayBuffer(1); +sample = new DataView(ab, 1); +assert.sameValue(sample.constructor, DataView); +assert.sameValue(Object.getPrototypeOf(sample), DataView.prototype); diff --git a/test/built-ins/DataView/toindex-bytelength-sab.js b/test/built-ins/DataView/toindex-bytelength-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..627d313da2adfb689821abb4315a7228f83448b1 --- /dev/null +++ b/test/built-ins/DataView/toindex-bytelength-sab.js @@ -0,0 +1,95 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + ToIndex conversions on byteLength +info: | + 24.2.2.1 DataView ( buffer, byteOffset, byteLength ) + + ... + 8. If byteLength is either not present or undefined, then + a. Let viewByteLength be bufferByteLength - offset. + 9. Else, + a. Let viewByteLength be ? ToIndex(byteLength). + b. If offset + viewByteLength > bufferByteLength, throw a RangeError + exception. + ... + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +features: [SharedArrayBuffer] +---*/ + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +var sample; +var ab = new SharedArrayBuffer(42); + +sample = new DataView(ab, 0, -0); +assert.sameValue(sample.byteLength, 0, "-0"); + +sample = new DataView(ab, 0, obj1); +assert.sameValue(sample.byteLength, 3, "object's valueOf"); + +sample = new DataView(ab, 0, obj2); +assert.sameValue(sample.byteLength, 4, "object's toString"); + +sample = new DataView(ab, 0, ""); +assert.sameValue(sample.byteLength, 0, "the Empty string"); + +sample = new DataView(ab, 0, "0"); +assert.sameValue(sample.byteLength, 0, "string '0'"); + +sample = new DataView(ab, 0, "1"); +assert.sameValue(sample.byteLength, 1, "string '1'"); + +sample = new DataView(ab, 0, true); +assert.sameValue(sample.byteLength, 1, "true"); + +sample = new DataView(ab, 0, false); +assert.sameValue(sample.byteLength, 0, "false"); + +sample = new DataView(ab, 0, NaN); +assert.sameValue(sample.byteLength, 0, "NaN"); + +sample = new DataView(ab, 0, null); +assert.sameValue(sample.byteLength, 0, "null"); + +sample = new DataView(ab, 0, 0.1); +assert.sameValue(sample.byteLength, 0, "0.1"); + +sample = new DataView(ab, 0, 0.9); +assert.sameValue(sample.byteLength, 0, "0.9"); + +sample = new DataView(ab, 0, 1.1); +assert.sameValue(sample.byteLength, 1, "1.1"); + +sample = new DataView(ab, 0, 1.9); +assert.sameValue(sample.byteLength, 1, "1.9"); + +sample = new DataView(ab, 0, -0.1); +assert.sameValue(sample.byteLength, 0, "-0.1"); + +sample = new DataView(ab, 0, -0.99999); +assert.sameValue(sample.byteLength, 0, "-0.99999"); diff --git a/test/built-ins/DataView/toindex-byteoffset-sab.js b/test/built-ins/DataView/toindex-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..ddbb6420caffe51f55637509e5146ba05bf1e4cd --- /dev/null +++ b/test/built-ins/DataView/toindex-byteoffset-sab.js @@ -0,0 +1,93 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-dataview-buffer-byteoffset-bytelength +description: > + ToIndex conversions on byteOffset +info: | + 24.2.2.1 DataView ( buffer, byteOffset, byteLength ) + + ... + 4. Let offset be ? ToIndex(byteOffset). + ... + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +features: [SharedArrayBuffer] +---*/ + +var obj1 = { + valueOf: function() { + return 3; + } +}; + +var obj2 = { + toString: function() { + return 4; + } +}; + +var sample; +var ab = new SharedArrayBuffer(42); + +sample = new DataView(ab, -0); +assert.sameValue(sample.byteOffset, 0, "-0"); + +sample = new DataView(ab, obj1); +assert.sameValue(sample.byteOffset, 3, "object's valueOf"); + +sample = new DataView(ab, obj2); +assert.sameValue(sample.byteOffset, 4, "object's toString"); + +sample = new DataView(ab, ""); +assert.sameValue(sample.byteOffset, 0, "the Empty string"); + +sample = new DataView(ab, "0"); +assert.sameValue(sample.byteOffset, 0, "string '0'"); + +sample = new DataView(ab, "1"); +assert.sameValue(sample.byteOffset, 1, "string '1'"); + +sample = new DataView(ab, true); +assert.sameValue(sample.byteOffset, 1, "true"); + +sample = new DataView(ab, false); +assert.sameValue(sample.byteOffset, 0, "false"); + +sample = new DataView(ab, NaN); +assert.sameValue(sample.byteOffset, 0, "NaN"); + +sample = new DataView(ab, null); +assert.sameValue(sample.byteOffset, 0, "null"); + +sample = new DataView(ab, undefined); +assert.sameValue(sample.byteOffset, 0, "undefined"); + +sample = new DataView(ab, 0.1); +assert.sameValue(sample.byteOffset, 0, "0.1"); + +sample = new DataView(ab, 0.9); +assert.sameValue(sample.byteOffset, 0, "0.9"); + +sample = new DataView(ab, 1.1); +assert.sameValue(sample.byteOffset, 1, "1.1"); + +sample = new DataView(ab, 1.9); +assert.sameValue(sample.byteOffset, 1, "1.9"); + +sample = new DataView(ab, -0.1); +assert.sameValue(sample.byteOffset, 0, "-0.1"); + +sample = new DataView(ab, -0.99999); +assert.sameValue(sample.byteOffset, 0, "-0.99999"); diff --git a/test/built-ins/SharedArrayBuffer/allocation-limit.js b/test/built-ins/SharedArrayBuffer/allocation-limit.js new file mode 100644 index 0000000000000000000000000000000000000000..6326b5ba2e503e56b4973a166629d859d056e348 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/allocation-limit.js @@ -0,0 +1,33 @@ +// 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. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + Throws a RangeError if requested Data Block is too large. +info: > + SharedArrayBuffer( length ) + + ... + 3. Return AllocateSharedArrayBuffer(NewTarget, byteLength). + + 6.2.7.2 CreateSharedByteDataBlock(size) + ... + 2. Let db be a new Shared Data Block value consisting of size + bytes. If it is impossible to create such a Shared Data Block, + throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + new SharedArrayBuffer(7 * 1125899906842624); +}, "`length` parameter is 7 PiB"); + +assert.throws(RangeError, function() { + // Allocating almost 8 PiB should fail with a RangeError. + // Math.pow(2, 53) = 9007199254740992 + new SharedArrayBuffer(9007199254740992 - 1); +}, "`length` parameter is Math.pow(2, 53) - 1"); diff --git a/test/built-ins/SharedArrayBuffer/data-allocation-after-object-creation.js b/test/built-ins/SharedArrayBuffer/data-allocation-after-object-creation.js new file mode 100644 index 0000000000000000000000000000000000000000..a49ff7066dfed9317499a5f2104ab83c0b1a217f --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/data-allocation-after-object-creation.js @@ -0,0 +1,37 @@ +// 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. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + The new SharedArrayBuffer instance is created prior to allocating the Data Block. +info: > + SharedArrayBuffer( length ) + + ... + 3. Return AllocateSharedArrayBuffer(NewTarget, byteLength). + + AllocateSharedArrayBuffer( constructor, byteLength ) + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBufferPrototype%", + «[[ArrayBufferData]], [[ArrayBufferByteLength]]» ). + ... + 3. Let block be ? CreateByteDataBlock(byteLength). + ... +features: [Reflect.construct] +---*/ + +function DummyError() { } + +var newTarget = function(){}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get: function() { + throw new DummyError(); + } +}); + +assert.throws(DummyError, function() { + // Allocating 7 PiB should fail with a RangeError. + // Math.pow(1024, 5) = 1125899906842624 + Reflect.construct(SharedArrayBuffer, [7 * 1125899906842624], newTarget); +}); diff --git a/test/built-ins/SharedArrayBuffer/init-zero.js b/test/built-ins/SharedArrayBuffer/init-zero.js new file mode 100644 index 0000000000000000000000000000000000000000..22d0d26c41337f14548d6e759d3c62eeb12c43a4 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/init-zero.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-createsharedbytedatablock +description: All bytes are initialized to zero +features: [DataView] +---*/ + +var view = new DataView(new SharedArrayBuffer(9)); + +assert.sameValue(view.getUint8(0), 0, 'index 0'); +assert.sameValue(view.getUint8(1), 0, 'index 1'); +assert.sameValue(view.getUint8(2), 0, 'index 2'); +assert.sameValue(view.getUint8(3), 0, 'index 3'); +assert.sameValue(view.getUint8(4), 0, 'index 4'); +assert.sameValue(view.getUint8(5), 0, 'index 5'); +assert.sameValue(view.getUint8(6), 0, 'index 6'); +assert.sameValue(view.getUint8(7), 0, 'index 7'); +assert.sameValue(view.getUint8(8), 0, 'index 8'); diff --git a/test/built-ins/SharedArrayBuffer/length-is-absent.js b/test/built-ins/SharedArrayBuffer/length-is-absent.js new file mode 100644 index 0000000000000000000000000000000000000000..6bf50f21e00465faf62f2c9898df0698251021d1 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/length-is-absent.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 The V8 Project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + Returns an empty instance if length is absent +info: | + SharedArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength). +---*/ + +var buffer = new SharedArrayBuffer(); + +assert.sameValue(buffer.byteLength, 0); diff --git a/test/built-ins/SharedArrayBuffer/length-is-too-large-throws.js b/test/built-ins/SharedArrayBuffer/length-is-too-large-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..fafea0c8777f2b6218e762dc48d0dfff2a54314a --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/length-is-too-large-throws.js @@ -0,0 +1,32 @@ +// 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. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + Throws a RangeError if length >= 2 ** 53 +info: > + SharedArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + // Math.pow(2, 53) = 9007199254740992 + new SharedArrayBuffer(9007199254740992); +}, "`length` parameter is too large"); + +assert.throws(RangeError, function() { + new SharedArrayBuffer(Infinity); +}, "`length` parameter is positive Infinity"); diff --git a/test/built-ins/SharedArrayBuffer/negative-length-throws.js b/test/built-ins/SharedArrayBuffer/negative-length-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..2793751fbc5f75ac695127bc4e22872437a40654 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/negative-length-throws.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 The V8 Project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + Throws a Range Error if length represents an integer < 0 +info: | + SharedArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + ... +---*/ + +assert.throws(RangeError, function() { + new SharedArrayBuffer(-1); +}); + +assert.throws(RangeError, function() { + new SharedArrayBuffer(-1.1); +}); + +assert.throws(RangeError, function() { + new SharedArrayBuffer(-Infinity); +}); diff --git a/test/built-ins/SharedArrayBuffer/newtarget-prototype-is-not-object.js b/test/built-ins/SharedArrayBuffer/newtarget-prototype-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..802b1787cb630e2676475ea53f930fde5d8ac0ac --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/newtarget-prototype-is-not-object.js @@ -0,0 +1,48 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// Copyright (C) 2017 Mozilla Foundation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + [[Prototype]] defaults to %SharedArrayBufferPrototype% if NewTarget.prototype is not an object. +info: > + SharedArrayBuffer( length ) + + SharedArrayBuffer called with argument length performs the following steps: + + ... + 3. Return AllocateSharedArrayBuffer(NewTarget, byteLength). + + AllocateSharedArrayBuffer( constructor, byteLength ) + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBufferPrototype%", + «[[ArrayBufferData]], [[ArrayBufferByteLength]]» ). + ... +features: [Reflect.construct] +---*/ + +function newTarget() { } + +newTarget.prototype = undefined; +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [1], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is undefined"); + +newTarget.prototype = null; +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [2], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is null"); + +newTarget.prototype = true; +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [3], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a Boolean"); + +newTarget.prototype = ""; +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [4], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a String"); + +newTarget.prototype = Symbol(); +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [5], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a Symbol"); + +newTarget.prototype = 1; +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [6], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), SharedArrayBuffer.prototype, "newTarget.prototype is a Number"); diff --git a/test/built-ins/SharedArrayBuffer/proto-from-ctor-realm.js b/test/built-ins/SharedArrayBuffer/proto-from-ctor-realm.js new file mode 100644 index 0000000000000000000000000000000000000000..9b5195ebab26d8784f6b90aa05a3ce0d4fb3de28 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/proto-from-ctor-realm.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-sharedarraybuffer-length +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 3. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength). + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + [...] +features: [Reflect] +---*/ + +var other = $.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +var o = Reflect.construct(SharedArrayBuffer, [], C); + +assert.sameValue(Object.getPrototypeOf(o), other.SharedArrayBuffer.prototype); diff --git a/test/built-ins/SharedArrayBuffer/prototype-from-newtarget.js b/test/built-ins/SharedArrayBuffer/prototype-from-newtarget.js new file mode 100644 index 0000000000000000000000000000000000000000..3a866cce81d38631c5fdafba42c42bcb2909d069 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype-from-newtarget.js @@ -0,0 +1,34 @@ +// 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. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + The [[Prototype]] internal slot is computed from NewTarget. +info: > + SharedArrayBuffer( length ) + + SharedArrayBuffer called with argument length performs the following steps: + + ... + 3. Return AllocateSharedArrayBuffer(NewTarget, byteLength). + + AllocateSharedArrayBuffer( constructor, byteLength ) + 1. Let obj be ? OrdinaryCreateFromConstructor(constructor, "%SharedArrayBufferPrototype%", + «[[ArrayBufferData]], [[ArrayBufferByteLength]]» ). + ... +features: [Reflect.construct] +---*/ + +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [8], Object); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), Object.prototype, "NewTarget is built-in Object constructor"); + +var newTarget = function(){}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get: function() { + return Array.prototype; + } +}); +var arrayBuffer = Reflect.construct(SharedArrayBuffer, [16], newTarget); +assert.sameValue(Object.getPrototypeOf(arrayBuffer), Array.prototype, "NewTarget is BoundFunction with accessor"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/Symbol.toStringTag.js b/test/built-ins/SharedArrayBuffer/prototype/Symbol.toStringTag.js new file mode 100644 index 0000000000000000000000000000000000000000..edbe9e4ccde5a9543095b9dcf24b160c153a22ed --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/Symbol.toStringTag.js @@ -0,0 +1,21 @@ +// Copyright (C) 2015 the V8 project authors. 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: > + `Symbol.toStringTag` property descriptor +info: > + The initial value of the @@toStringTag property is the String value + "SharedArrayBuffer". + + This property has the attributes { [[Writable]]: false, [[Enumerable]]: + false, [[Configurable]]: true }. +includes: [propertyHelper.js] +features: [Symbol.toStringTag] +---*/ + +assert.sameValue(SharedArrayBuffer.prototype[Symbol.toStringTag], 'SharedArrayBuffer'); + +verifyNotEnumerable(SharedArrayBuffer.prototype, Symbol.toStringTag); +verifyNotWritable(SharedArrayBuffer.prototype, Symbol.toStringTag); +verifyConfigurable(SharedArrayBuffer.prototype, Symbol.toStringTag); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/invoked-as-accessor.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/invoked-as-accessor.js new file mode 100644 index 0000000000000000000000000000000000000000..f8a2a1912bc5b29e3bb064e8d1cd5ab4b36eaf72 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/invoked-as-accessor.js @@ -0,0 +1,11 @@ +// Copyright (C) 2016 the V8 project authors. 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: Requires this value to have a [[ArrayBufferData]] internal slot +---*/ + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.byteLength; +}); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/invoked-as-func.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/invoked-as-func.js new file mode 100644 index 0000000000000000000000000000000000000000..7ea7ad638e0b4154159a6efe7b8f30381086a08e --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/invoked-as-func.js @@ -0,0 +1,14 @@ +// Copyright (C) 2016 the V8 project authors. 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: Throws a TypeError exception when invoked as a function +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SharedArrayBuffer.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter(); +}); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/length.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/length.js new file mode 100755 index 0000000000000000000000000000000000000000..82ab36db62e0782379c34419837fa603278a51b1 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/length.js @@ -0,0 +1,17 @@ +// 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: > + get SharedArrayBuffer.prototype.byteLength.length is 0. +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength"); + +assert.sameValue(desc.get.length, 0); + +verifyNotEnumerable(desc.get, "length"); +verifyNotWritable(desc.get, "length"); +verifyConfigurable(desc.get, "length"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/name.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/name.js new file mode 100644 index 0000000000000000000000000000000000000000..42dface3563c1cc420b4c26099c5cc296abbecfa --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/name.js @@ -0,0 +1,22 @@ +// Copyright (C) 2015 the V8 project authors. 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: > + get SharedArrayBuffer.prototype.byteLength + +includes: [propertyHelper.js] +---*/ + +var descriptor = Object.getOwnPropertyDescriptor( + SharedArrayBuffer.prototype, 'byteLength' +); + +assert.sameValue( + descriptor.get.name, 'get byteLength', + 'The value of `descriptor.get.name` is `"get byteLength"`' +); + +verifyNotEnumerable(descriptor.get, 'name'); +verifyNotWritable(descriptor.get, 'name'); +verifyConfigurable(descriptor.get, 'name'); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/prop-desc.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/prop-desc.js new file mode 100644 index 0000000000000000000000000000000000000000..8266192cf236a41d46f2b4c287dfc35ba7c8c48d --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/prop-desc.js @@ -0,0 +1,16 @@ +// Copyright (C) 2016 the V8 project authors. 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: > + "byteLength" property of SharedArrayBuffer.prototype +includes: [propertyHelper.js] +---*/ + +var desc = Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength"); + +assert.sameValue(desc.set, undefined); +assert.sameValue(typeof desc.get, "function"); + +verifyNotEnumerable(SharedArrayBuffer.prototype, "byteLength"); +verifyConfigurable(SharedArrayBuffer.prototype, "byteLength"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/return-bytelength.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/return-bytelength.js new file mode 100644 index 0000000000000000000000000000000000000000..66810df9f912835c1634a27f65b75c5f0351f4aa --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/return-bytelength.js @@ -0,0 +1,12 @@ +// Copyright (C) 2016 the V8 project authors. 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: Return value from [[ByteLength]] internal slot +---*/ + +var ab1 = new SharedArrayBuffer(0); +assert.sameValue(ab1.byteLength, 0); + +var ab2 = new SharedArrayBuffer(42); +assert.sameValue(ab2.byteLength, 42); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js new file mode 100644 index 0000000000000000000000000000000000000000..32fee07cf4e7a3b4d35238da3cc88b318e6adc9d --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-has-no-typedarrayname-internal.js @@ -0,0 +1,31 @@ +// Copyright (C) 2016 the V8 project authors. 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: > + Throws a TypeError exception when `this` does not have a [[ArrayBufferData]] + internal slot +features: [DataView, Int8Array] +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SharedArrayBuffer.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call({}); +}); + +assert.throws(TypeError, function() { + getter.call([]); +}); + +var ta = new Int8Array(new SharedArrayBuffer(8)); +assert.throws(TypeError, function() { + getter.call(ta); +}); + +var dv = new DataView(new SharedArrayBuffer(8), 0); +assert.throws(TypeError, function() { + getter.call(dv); +}); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-is-arraybuffer.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-is-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..f3ae27ebea7d0da0eab458a1de0f4e87c1af09d2 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-is-arraybuffer.js @@ -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-sharedarraybuffer.prototype.bytelength +description: Throws a TypeError exception when `this` is an ArrayBuffer +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SharedArrayBuffer.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + var ab = new ArrayBuffer(4); + getter.call(ab); +}, "`this` cannot be an ArrayBuffer"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-is-not-object.js b/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-is-not-object.js new file mode 100644 index 0000000000000000000000000000000000000000..79e857b75f290a4152175a954a5471b01b0e51d3 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/byteLength/this-is-not-object.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. 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: Throws a TypeError exception when `this` is not Object +---*/ + +var getter = Object.getOwnPropertyDescriptor( + SharedArrayBuffer.prototype, "byteLength" +).get; + +assert.throws(TypeError, function() { + getter.call(undefined); +}, "this is undefined"); + +assert.throws(TypeError, function() { + getter.call(null); +}, "this is null"); + +assert.throws(TypeError, function() { + getter.call(42); +}, "this is 42"); + +assert.throws(TypeError, function() { + getter.call("1"); +}, "this is a string"); + +assert.throws(TypeError, function() { + getter.call(true); +}, "this is true"); + +assert.throws(TypeError, function() { + getter.call(false); +}, "this is false"); + +var s = Symbol("s"); +assert.throws(TypeError, function() { + getter.call(s); +}, "this is a Symbol"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/constructor.js b/test/built-ins/SharedArrayBuffer/prototype/constructor.js new file mode 100755 index 0000000000000000000000000000000000000000..49ca70562dbeb9e2152841e9259c70c0f3416aac --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/constructor.js @@ -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: > + The `SharedArrayBuffer.prototype.constructor` property descriptor. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SharedArrayBuffer.prototype.constructor, SharedArrayBuffer); + +verifyNotEnumerable(SharedArrayBuffer.prototype, "constructor"); +verifyWritable(SharedArrayBuffer.prototype, "constructor"); +verifyConfigurable(SharedArrayBuffer.prototype, "constructor"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js b/test/built-ins/SharedArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js new file mode 100755 index 0000000000000000000000000000000000000000..6f20f2528dd135df1573ae8e4f793295b21b84cd --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/context-is-not-arraybuffer-object.js @@ -0,0 +1,17 @@ +// 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: > + Throws a TypeError if `this` does not have an [[ArrayBufferData]] internal slot. +info: > +---*/ + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call({}); +}, "`this` value is Object"); + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call([]); +}, "`this` value is Array"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/context-is-not-object.js b/test/built-ins/SharedArrayBuffer/prototype/slice/context-is-not-object.js new file mode 100755 index 0000000000000000000000000000000000000000..ce054180b712e51182eaa80af0f0a195c62878c9 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/context-is-not-object.js @@ -0,0 +1,34 @@ +// 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: > + Throws a TypeError if `this` is not an Object. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) +---*/ + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call(undefined); +}, "`this` value is undefined"); + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call(null); +}, "`this` value is null"); + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call(true); +}, "`this` value is Boolean"); + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call(""); +}, "`this` value is String"); + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call(Symbol()); +}, "`this` value is Symbol"); + +assert.throws(TypeError, function() { + SharedArrayBuffer.prototype.slice.call(1); +}, "`this` value is Number"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/descriptor.js b/test/built-ins/SharedArrayBuffer/prototype/slice/descriptor.js new file mode 100755 index 0000000000000000000000000000000000000000..3d0455ab1a3f50906a5849b719425a949c443774 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/descriptor.js @@ -0,0 +1,20 @@ +// 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: > + SharedArrayBuffer.prototype.slice has default data property attributes. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + + 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] +---*/ + +verifyNotEnumerable(SharedArrayBuffer.prototype, "slice"); +verifyWritable(SharedArrayBuffer.prototype, "slice"); +verifyConfigurable(SharedArrayBuffer.prototype, "slice"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/end-default-if-absent.js b/test/built-ins/SharedArrayBuffer/prototype/slice/end-default-if-absent.js new file mode 100755 index 0000000000000000000000000000000000000000..33b3fd41e13a9f6027b0ee45f718a24595751ece --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/end-default-if-absent.js @@ -0,0 +1,17 @@ +// 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: > + The `end` index defaults to [[ArrayBufferByteLength]] if absent. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var start = 6; +var result = arrayBuffer.slice(start); +assert.sameValue(result.byteLength, 2); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/end-default-if-undefined.js b/test/built-ins/SharedArrayBuffer/prototype/slice/end-default-if-undefined.js new file mode 100755 index 0000000000000000000000000000000000000000..3d92aacd743ce6eed7c642a6be4be5ff77134586 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/end-default-if-undefined.js @@ -0,0 +1,17 @@ +// 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: > + The `end` index defaults to [[ArrayBufferByteLength]] if undefined. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var start = 6, end = undefined; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 2); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/end-exceeds-length.js b/test/built-ins/SharedArrayBuffer/prototype/slice/end-exceeds-length.js new file mode 100755 index 0000000000000000000000000000000000000000..b22b1ad37800034b44da862dbcbae13023a03323 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/end-exceeds-length.js @@ -0,0 +1,25 @@ +// 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: > + Large `end` index is clamped to [[ArrayBufferByteLength]]. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var start = 1, end = 12; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 7, "slice(1, 12)"); + +var start = 2, end = 0x100000000; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(2, 0x100000000)"); + +var start = 3, end = +Infinity; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 5, "slice(3, Infinity)"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/extensible.js b/test/built-ins/SharedArrayBuffer/prototype/slice/extensible.js new file mode 100755 index 0000000000000000000000000000000000000000..00d5c8c5ae22e3e912f8f9e01191383d975b0087 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/extensible.js @@ -0,0 +1,16 @@ +// 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: > + SharedArrayBuffer.prototype.slice is extensible. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Unless specified otherwise, the [[Extensible]] internal slot + of a built-in object initially has the value true. +---*/ + +assert(Object.isExtensible(SharedArrayBuffer.prototype.slice)); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/length.js b/test/built-ins/SharedArrayBuffer/prototype/slice/length.js new file mode 100755 index 0000000000000000000000000000000000000000..3d0e8772593deb78502fd5cbe09a4f7088b76bbd --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/length.js @@ -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: > + SharedArrayBuffer.prototype.slice.length is 2. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + + 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(SharedArrayBuffer.prototype.slice.length, 2); + +verifyNotEnumerable(SharedArrayBuffer.prototype.slice, "length"); +verifyNotWritable(SharedArrayBuffer.prototype.slice, "length"); +verifyConfigurable(SharedArrayBuffer.prototype.slice, "length"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/name.js b/test/built-ins/SharedArrayBuffer/prototype/slice/name.js new file mode 100755 index 0000000000000000000000000000000000000000..87438f8d3215ca9d87c3a82d65dcf628745a6ca0 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/name.js @@ -0,0 +1,26 @@ +// 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: > + SharedArrayBuffer.prototype.slice.name is "slice". +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Every built-in Function object, including constructors, that is not + identified as an anonymous function has a name property whose value + is a String. + + Unless otherwise specified, the name property of a built-in Function + object, if it exists, has the attributes { [[Writable]]: false, + [[Enumerable]]: false, [[Configurable]]: true }. +includes: [propertyHelper.js] +---*/ + +assert.sameValue(SharedArrayBuffer.prototype.slice.name, "slice"); + +verifyNotEnumerable(SharedArrayBuffer.prototype.slice, "name"); +verifyNotWritable(SharedArrayBuffer.prototype.slice, "name"); +verifyConfigurable(SharedArrayBuffer.prototype.slice, "name"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/negative-end.js b/test/built-ins/SharedArrayBuffer/prototype/slice/negative-end.js new file mode 100755 index 0000000000000000000000000000000000000000..ac6690ff14c52637603497125c8efb7a627a74a5 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/negative-end.js @@ -0,0 +1,25 @@ +// 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: > + Negative `end` index is relative to [[ArrayBufferByteLength]]. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var start = 2, end = -4; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 2, "slice(2, -4)"); + +var start = 2, end = -10; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(2, -10)"); + +var start = 2, end = -Infinity; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0, "slice(2, -Infinity)"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/negative-start.js b/test/built-ins/SharedArrayBuffer/prototype/slice/negative-start.js new file mode 100755 index 0000000000000000000000000000000000000000..6072265e16841c6b14fca80ede83d8dc531f3b31 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/negative-start.js @@ -0,0 +1,25 @@ +// 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: > + Negative `start` index is relative to [[ArrayBufferByteLength]]. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var start = -5, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 3, "slice(-5, 6)"); + +var start = -12, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(-12, 6)"); + +var start = -Infinity, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6, "slice(-Infinity, 6)"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/nonconstructor.js b/test/built-ins/SharedArrayBuffer/prototype/slice/nonconstructor.js new file mode 100755 index 0000000000000000000000000000000000000000..7b03f743bae865e4c34e243770c4583edde46c70 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/nonconstructor.js @@ -0,0 +1,20 @@ +// 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: > + SharedArrayBuffer.prototype.slice is not a constructor function. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + + 17 ECMAScript Standard Built-in Objects: + Built-in function objects that are not identified as constructors do not + implement the [[Construct]] internal method unless otherwise specified + in the description of a particular function. +---*/ + +assert.sameValue(Object.prototype.hasOwnProperty.call(SharedArrayBuffer.prototype.slice, "prototype"), false); + +var arrayBuffer = new SharedArrayBuffer(8); +assert.throws(TypeError, function() { new arrayBuffer.slice(); }); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/number-conversion.js b/test/built-ins/SharedArrayBuffer/prototype/slice/number-conversion.js new file mode 100755 index 0000000000000000000000000000000000000000..8117760802a53b853979f4c3c071a167cdddd8f3 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/number-conversion.js @@ -0,0 +1,30 @@ +// 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: > + ToInteger(start) is called before ToInteger(end). +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var log = ""; +var start = { + valueOf: function() { + log += "start-"; + return 0; + } +}; +var end = { + valueOf: function() { + log += "end"; + return 8; + } +}; + +arrayBuffer.slice(start, end); +assert.sameValue(log, "start-end"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-constructor-is-not-object.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-constructor-is-not-object.js new file mode 100755 index 0000000000000000000000000000000000000000..86212bc65b906f09532647d9b4f9ba15d6b7f67d --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-constructor-is-not-object.js @@ -0,0 +1,30 @@ +// 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: > + Throws TypeError if `constructor` property is not an object. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +function callSlice() { arrayBuffer.slice(); } + +arrayBuffer.constructor = null; +assert.throws(TypeError, callSlice, "`constructor` value is null"); + +arrayBuffer.constructor = true; +assert.throws(TypeError, callSlice, "`constructor` value is Boolean"); + +arrayBuffer.constructor = ""; +assert.throws(TypeError, callSlice, "`constructor` value is String"); + +arrayBuffer.constructor = Symbol(); +assert.throws(TypeError, callSlice, "`constructor` value is Symbol"); + +arrayBuffer.constructor = 1; +assert.throws(TypeError, callSlice, "`constructor` value is Number"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-constructor-is-undefined.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-constructor-is-undefined.js new file mode 100755 index 0000000000000000000000000000000000000000..82fef79d6bd6b433c43b06d696046d71d1abe0f9 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-constructor-is-undefined.js @@ -0,0 +1,16 @@ +// 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: > + Uses default constructor is `constructor` property is undefined. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = undefined; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), SharedArrayBuffer.prototype); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-not-constructor.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-not-constructor.js new file mode 100755 index 0000000000000000000000000000000000000000..257fbaceabeaca6c364a068794b4620cd63e6c5f --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-not-constructor.js @@ -0,0 +1,25 @@ +// 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: > + Throws a TypeError if species constructor is not a constructor function. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +function callSlice() { arrayBuffer.slice(); } + +speciesConstructor[Symbol.species] = {}; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Object"); + +speciesConstructor[Symbol.species] = Function.prototype; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Function.prototype"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-not-object.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-not-object.js new file mode 100755 index 0000000000000000000000000000000000000000..8bffd07470aeaf9967034f220f29ef3d21d0679e --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-not-object.js @@ -0,0 +1,31 @@ +// 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: > + Throws a TypeError if species constructor is not an object. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +function callSlice() { arrayBuffer.slice(); } + +speciesConstructor[Symbol.species] = true; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Boolean"); + +speciesConstructor[Symbol.species] = ""; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is String"); + +speciesConstructor[Symbol.species] = Symbol(); +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Symbol"); + +speciesConstructor[Symbol.species] = 1; +assert.throws(TypeError, callSlice, "`constructor[Symbol.species]` value is Number"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-null.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-null.js new file mode 100755 index 0000000000000000000000000000000000000000..d51c3b94d91b4798251c644de9e804332d01f02f --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-null.js @@ -0,0 +1,21 @@ +// 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: > + Uses default constructor is species constructor is null. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = null; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), SharedArrayBuffer.prototype); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-undefined.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-undefined.js new file mode 100755 index 0000000000000000000000000000000000000000..90d37be282f3adb0a80154b6ac8a0f1c4a0a4ccf --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-is-undefined.js @@ -0,0 +1,21 @@ +// 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: > + Uses default constructor is species constructor is undefined. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = undefined; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(Object.getPrototypeOf(result), SharedArrayBuffer.prototype); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js new file mode 100755 index 0000000000000000000000000000000000000000..6b015a86a6ec658087f03cfa1d44c8e8c4cfe7bd --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-larger-arraybuffer.js @@ -0,0 +1,23 @@ +// 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: > + Does not throw TypeError if new SharedArrayBuffer is too large. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return new SharedArrayBuffer(10); +}; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(result.byteLength, 10); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js new file mode 100755 index 0000000000000000000000000000000000000000..4c7224eaff839be063595c45cb3598f443a17d09 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-not-arraybuffer.js @@ -0,0 +1,24 @@ +// 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: > + Throws a TypeError if new object is not an SharedArrayBuffer instance. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return {}; +}; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js new file mode 100755 index 0000000000000000000000000000000000000000..b2fed3bac09a1318b38cd27d61a7811c3cea74ca --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-same-arraybuffer.js @@ -0,0 +1,24 @@ +// 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: > + Throws a TypeError if species constructor returns `this` value. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return arrayBuffer; +}; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js new file mode 100755 index 0000000000000000000000000000000000000000..9d6c4994bfa6c5ac159f514e3d5a435fa6db84c3 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species-returns-smaller-arraybuffer.js @@ -0,0 +1,24 @@ +// 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: > + Throws a TypeError if new SharedArrayBuffer is too small. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return new SharedArrayBuffer(4); +}; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +assert.throws(TypeError, function() { + arrayBuffer.slice(); +}); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/species.js b/test/built-ins/SharedArrayBuffer/prototype/slice/species.js new file mode 100755 index 0000000000000000000000000000000000000000..fa0cf8b28e7a71eccb8997d6785f096faf71e162 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/species.js @@ -0,0 +1,25 @@ +// 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: > + New SharedArrayBuffer instance is created from SpeciesConstructor. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +features: [Symbol.species] +---*/ + +var resultBuffer; + +var speciesConstructor = {}; +speciesConstructor[Symbol.species] = function(length) { + return resultBuffer = new SharedArrayBuffer(length); +}; + +var arrayBuffer = new SharedArrayBuffer(8); +arrayBuffer.constructor = speciesConstructor; + +var result = arrayBuffer.slice(); +assert.sameValue(result, resultBuffer); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/start-default-if-absent.js b/test/built-ins/SharedArrayBuffer/prototype/slice/start-default-if-absent.js new file mode 100755 index 0000000000000000000000000000000000000000..2df219ea4f9940a02d8500e9e16afbd081ca3537 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/start-default-if-absent.js @@ -0,0 +1,16 @@ +// 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: > + The `start` index defaults to 0 if absent. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var result = arrayBuffer.slice(); +assert.sameValue(result.byteLength, 8); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/start-default-if-undefined.js b/test/built-ins/SharedArrayBuffer/prototype/slice/start-default-if-undefined.js new file mode 100755 index 0000000000000000000000000000000000000000..f491586ffd3249cc7a0ad4a2d98e4c4415d7ef41 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/start-default-if-undefined.js @@ -0,0 +1,16 @@ +// 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: > + The `start` index defaults to 0 if undefined. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var start = undefined, end = 6; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 6); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/start-exceeds-end.js b/test/built-ins/SharedArrayBuffer/prototype/slice/start-exceeds-end.js new file mode 100755 index 0000000000000000000000000000000000000000..38493513a60afb0406d7bbbdcce86fcac7a1462c --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/start-exceeds-end.js @@ -0,0 +1,17 @@ +// 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: > + Returns zero-length buffer if `start` index exceeds `end` index. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) + +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); + +var start = 5, end = 4; +var result = arrayBuffer.slice(start, end); +assert.sameValue(result.byteLength, 0); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/start-exceeds-length.js b/test/built-ins/SharedArrayBuffer/prototype/slice/start-exceeds-length.js new file mode 100755 index 0000000000000000000000000000000000000000..59d7d9fcba3af239ca88f4788b22fdab64f387cb --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/start-exceeds-length.js @@ -0,0 +1,22 @@ +// 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: > + Large `start` index is clamped to [[ArrayBufferByteLength]]. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); +var result; + +result = arrayBuffer.slice(10, 8); +assert.sameValue(result.byteLength, 0, "slice(10, 8)"); + +result = arrayBuffer.slice(0x100000000, 7); +assert.sameValue(result.byteLength, 0, "slice(0x100000000, 7)"); + +result = arrayBuffer.slice(+Infinity, 6); +assert.sameValue(result.byteLength, 0, "slice(+Infinity, 6)"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/this-is-arraybuffer.js b/test/built-ins/SharedArrayBuffer/prototype/slice/this-is-arraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..341ea209675c3346648588a14c07d52653ac9a11 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/this-is-arraybuffer.js @@ -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-sharedarraybuffer.prototype.slice +description: > + Throws a TypeError if `this` is an ArrayBuffer +---*/ + +assert.throws(TypeError, function() { + var ab = new ArrayBuffer(0); + SharedArrayBuffer.prototype.slice.call(ab); +}, "`this` value cannot be an ArrayBuffer"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/tointeger-conversion-end.js b/test/built-ins/SharedArrayBuffer/prototype/slice/tointeger-conversion-end.js new file mode 100755 index 0000000000000000000000000000000000000000..6421c07abc3dbfd43699232149d385745de30cad --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/tointeger-conversion-end.js @@ -0,0 +1,19 @@ +// 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: > + The `end` index parameter is converted to an integral numeric value. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); +var result; + +result = arrayBuffer.slice(0, 4.5); +assert.sameValue(result.byteLength, 4, "slice(0, 4.5)"); + +result = arrayBuffer.slice(0, NaN); +assert.sameValue(result.byteLength, 0, "slice(0, NaN)"); diff --git a/test/built-ins/SharedArrayBuffer/prototype/slice/tointeger-conversion-start.js b/test/built-ins/SharedArrayBuffer/prototype/slice/tointeger-conversion-start.js new file mode 100755 index 0000000000000000000000000000000000000000..7f25bc54b9fa443ac485c7fae3728a1613ba7935 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/prototype/slice/tointeger-conversion-start.js @@ -0,0 +1,19 @@ +// 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: > + The `start` index parameter is converted to an integral numeric value. +info: > + SharedArrayBuffer.prototype.slice ( start, end ) +---*/ + +var arrayBuffer = new SharedArrayBuffer(8); +var result; + +result = arrayBuffer.slice(4.5, 8); +assert.sameValue(result.byteLength, 4, "slice(4.5, 8)"); + +result = arrayBuffer.slice(NaN, 8); +assert.sameValue(result.byteLength, 8, "slice(NaN, 8)"); diff --git a/test/built-ins/SharedArrayBuffer/return-abrupt-from-length-symbol.js b/test/built-ins/SharedArrayBuffer/return-abrupt-from-length-symbol.js new file mode 100644 index 0000000000000000000000000000000000000000..3b5358d8cd02451609f12d62e25e921d12e9e537 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/return-abrupt-from-length-symbol.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 The V8 Project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + Throws a TypeError if length is a symbol +info: | + SharedArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + ... +features: [Symbol] +---*/ + +var s = Symbol(); + +assert.throws(TypeError, function() { + new SharedArrayBuffer(s); +}, "`length` parameter is a Symbol"); diff --git a/test/built-ins/SharedArrayBuffer/return-abrupt-from-length.js b/test/built-ins/SharedArrayBuffer/return-abrupt-from-length.js new file mode 100644 index 0000000000000000000000000000000000000000..c5d2c899377c6b4542e657e17ac32a7935250576 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/return-abrupt-from-length.js @@ -0,0 +1,25 @@ +// Copyright (C) 2016 The V8 Project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + Return abrupt from ToIndex(length) +info: | + SharedArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + ... +---*/ + +var len = { + valueOf: function() { + throw new Test262Error(); + } +}; + +assert.throws(Test262Error, function() { + new SharedArrayBuffer(len); +}); diff --git a/test/built-ins/SharedArrayBuffer/toindex-length.js b/test/built-ins/SharedArrayBuffer/toindex-length.js new file mode 100644 index 0000000000000000000000000000000000000000..e77883e0a839fb5e8f4842fab6488a65f0b303e1 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/toindex-length.js @@ -0,0 +1,88 @@ +// Copyright (C) 2016 The V8 Project authors. All rights reserved. +// Copyright (C) 2016 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + The `length` parameter is converted to a value numeric index value. +info: | + SharedArrayBuffer( length ) + + 1. If NewTarget is undefined, throw a TypeError exception. + 2. Let byteLength be ? ToIndex(length). + 3. Return ? AllocateSharedArrayBuffer(NewTarget, byteLength). + + ToIndex( value ) + + 1. If value is undefined, then + a. Let index be 0. + 2. Else, + a. Let integerIndex be ? ToInteger(value). + b. If integerIndex < 0, throw a RangeError exception. + c. Let index be ! ToLength(integerIndex). + d. If SameValueZero(integerIndex, index) is false, throw a RangeError exception. + 3. Return index. +---*/ + +var obj1 = { + valueOf: function() { + return 42; + } +}; + +var obj2 = { + toString: function() { + return 42; + } +}; + +var buffer; + +buffer = new SharedArrayBuffer(obj1); +assert.sameValue(buffer.byteLength, 42, "object's valueOf"); + +buffer = new SharedArrayBuffer(obj2); +assert.sameValue(buffer.byteLength, 42, "object's toString"); + +buffer = new SharedArrayBuffer(""); +assert.sameValue(buffer.byteLength, 0, "the Empty string"); + +buffer = new SharedArrayBuffer("0"); +assert.sameValue(buffer.byteLength, 0, "string '0'"); + +buffer = new SharedArrayBuffer("1"); +assert.sameValue(buffer.byteLength, 1, "string '1'"); + +buffer = new SharedArrayBuffer(true); +assert.sameValue(buffer.byteLength, 1, "true"); + +buffer = new SharedArrayBuffer(false); +assert.sameValue(buffer.byteLength, 0, "false"); + +buffer = new SharedArrayBuffer(NaN); +assert.sameValue(buffer.byteLength, 0, "NaN"); + +buffer = new SharedArrayBuffer(null); +assert.sameValue(buffer.byteLength, 0, "null"); + +buffer = new SharedArrayBuffer(undefined); +assert.sameValue(buffer.byteLength, 0, "undefined"); + +buffer = new SharedArrayBuffer(0.1); +assert.sameValue(buffer.byteLength, 0, "0.1"); + +buffer = new SharedArrayBuffer(0.9); +assert.sameValue(buffer.byteLength, 0, "0.9"); + +buffer = new SharedArrayBuffer(1.1); +assert.sameValue(buffer.byteLength, 1, "1.1"); + +buffer = new SharedArrayBuffer(1.9); +assert.sameValue(buffer.byteLength, 1, "1.9"); + +buffer = new SharedArrayBuffer(-0.1); +assert.sameValue(buffer.byteLength, 0, "-0.1"); + +buffer = new SharedArrayBuffer(-0.99999); +assert.sameValue(buffer.byteLength, 0, "-0.99999"); diff --git a/test/built-ins/SharedArrayBuffer/undefined-newtarget-throws.js b/test/built-ins/SharedArrayBuffer/undefined-newtarget-throws.js new file mode 100644 index 0000000000000000000000000000000000000000..9729cab78872a2609fba4f919e3b01b934864313 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/undefined-newtarget-throws.js @@ -0,0 +1,24 @@ +// 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. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + Throws a TypeError if SharedArrayBuffer is called as a function. +info: > + SharedArrayBuffer( length ) + + SharedArrayBuffer called with argument length performs the following steps: + + 1. If NewTarget is undefined, throw a TypeError exception. + ... +---*/ + +assert.throws(TypeError, function() { + SharedArrayBuffer(); +}); + +assert.throws(TypeError, function() { + SharedArrayBuffer(10); +}); diff --git a/test/built-ins/SharedArrayBuffer/zero-length.js b/test/built-ins/SharedArrayBuffer/zero-length.js new file mode 100644 index 0000000000000000000000000000000000000000..dba463b6d30278eb65d4ba04c74d70a8abc8a919 --- /dev/null +++ b/test/built-ins/SharedArrayBuffer/zero-length.js @@ -0,0 +1,24 @@ +// 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. + +/*--- +esid: sec-sharedarraybuffer-length +description: > + The `length` parameter can be zero. +info: > + SharedArrayBuffer( length ) + + ... + 2. Let numberLength be ToNumber(length). + 3. Let byteLength be ToLength(numberLength). + 4. ReturnIfAbrupt(byteLength). + 5. If SameValueZero(numberLength, byteLength) is false, throw a RangeError exception. + ... +---*/ + +var positiveZero = new SharedArrayBuffer(+0); +assert.sameValue(positiveZero.byteLength, 0); + +var negativeZero = new SharedArrayBuffer(-0); +assert.sameValue(negativeZero.byteLength, 0); diff --git a/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..4960a32d43a26cebb399de6e83d66070c5644295 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-conversions-sab.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set converted values from different buffer of different types and different type instances +includes: [byteConversionValues.js, testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testTypedArrayConversions(byteConversionValues, function(TA, value, expected, initial) { + if (TA === Float64Array || TA === Float32Array || TA === Uint8ClampedArray) { + return; + } + if (TA === Int32Array) { + return; + } + + var sab, src, target; + + sab = new SharedArrayBuffer(4); + src = new Int32Array(sab); + src[0] = value; + target = new TA([initial]); + + target.set(src); + + assert.sameValue(target[0], expected, "src is SAB-backed"); + + sab = new SharedArrayBuffer(4); + src = new Int32Array([value]); + target = new TA(sab); + target[0] = initial; + + target.set(src); + + assert.sameValue(target[0], expected, "target is SAB-backed"); + + var sab1 = new SharedArrayBuffer(4); + var sab2 = new SharedArrayBuffer(4); + src = new Int32Array(sab1); + src[0] = value; + target = new TA(sab2); + target[0] = initial; + + target.set(src); + + assert.sameValue(target[0], expected, "src and target are SAB-backed"); +}); diff --git a/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..28c8a38ceb00c9fc2322c719f9ce29a192e8c555 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-other-type-sab.js @@ -0,0 +1,107 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and different + type. +includes: [testTypedArray.js, compareArray.js] +features: [SharedArrayBuffer] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(TA) { + var other = Int32Array; + var sab = new SharedArrayBuffer(2 * other.BYTES_PER_ELEMENT); + var src = new other(sab); + src[0] = 42; + src[1] = 43; + var sample, result; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + src = new other([42, 43]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + src = new other(sab1); + src[0] = 42; + src[1] = 43; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..f213799583a964f3a30ddd1abfe12284bfb0dc73 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-diff-buffer-same-type-sab.js @@ -0,0 +1,107 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the different buffer and same + constructor. srcBuffer values are cached. +includes: [testTypedArray.js, compareArray.js] +features: [SharedArrayBuffer] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(TA) { + var sample, result; + + var sab = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + var src = new TA(sab); + src[0] = 42; + src[1] = 43; + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sample = new TA([1, 2, 3, 4]); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + src = new TA([42, 43]); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "sample is SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "sample is SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "sample is SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + + var sab1 = new SharedArrayBuffer(2 * TA.BYTES_PER_ELEMENT); + src = new TA(sab1); + src[0] = 42; + src[1] = 43; + + var sab2; + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 1); + assert(compareArray(sample, [1, 42, 43, 4]), "src and sample are SAB-backed, offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 0); + assert(compareArray(sample, [42, 43, 3, 4]), "src and sample are SAB-backed, offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab2 = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab2); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 42, 43]), "src and sample are SAB-backed, offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..a16d9f9f93805672566de200a06fd01dc3b65657 --- /dev/null +++ b/test/built-ins/TypedArray/prototype/set/typedarray-arg-set-values-same-buffer-same-type-sab.js @@ -0,0 +1,51 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-%typedarray%.prototype.set-typedarray-offset +description: > + Set values from different instances using the same buffer and same + constructor. srcBuffer values are cached. +includes: [testTypedArray.js, compareArray.js] +features: [SharedArrayBuffer] +---*/ + +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(TA) { + var sample, src, result, sab; + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 0); + assert(compareArray(sample, [1, 2, 3, 4]), "offset: 0, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 1); + assert(compareArray(sample, [1, 1, 2, 4]), "offset: 1, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); + + sab = new SharedArrayBuffer(4 * TA.BYTES_PER_ELEMENT); + sample = new TA(sab); + sample[0] = 1; + sample[1] = 2; + sample[2] = 3; + sample[3] = 4; + src = new TA(sample.buffer, 0, 2); + result = sample.set(src, 2); + assert(compareArray(sample, [1, 2, 1, 2]), "offset: 2, result: " + sample); + assert.sameValue(result, undefined, "returns undefined"); +}, int_views); diff --git a/test/built-ins/TypedArrays/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js b/test/built-ins/TypedArrays/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..4e40dfef9e2901cdbc07cb61203b525423e39f40 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-bufferbyteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength modulo elementSize ≠0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(1); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..3f07c9da5f1350062d2956c05a7a8a1a538369af --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-throws-sab.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) is < 0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + 8. If offset < 0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, -1); + }); + assert.throws(RangeError, function() { + new TA(buffer, -Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-zero-sab.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-zero-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..06dd9be432cfd9c40477f25994cb7a37b18efac3 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-negative-zero-sab.js @@ -0,0 +1,23 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: pending +description: > + TypedArray's [[ByteOffset]] internal slot is always a positive number, test with negative zero. +info: > + %TypedArray% ( buffer [ , byteOffset [ , length ] ] ) + + ... + 6. Let offset be ? ToInteger(byteOffset). + 7. If offset < 0, throw a RangeError exception. + 8. If offset is -0, let offset be +0. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TAConstructor) { + var typedArray = new TAConstructor(new SharedArrayBuffer(8), -0); + assert.sameValue(typedArray.byteOffset, +0); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-symbol-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-symbol-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..416e5db7d1dcbddd82ca0d0f472cdd4af72b733b --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-is-symbol-throws-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset as a symbol +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var byteOffset = Symbol("1"); +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..15139fd6212870ce656eb24f3f7eb3693e9a502c --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-throws-from-modulo-element-size-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if ToInteger(byteOffset) modulo elementSize is not 0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 10. If offset modulo elementSize ≠0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +testWithTypedArrayConstructors(function(TA) { + if (TA.BYTES_PER_ELEMENT === 1) { + // Impossible to trigger this step here. + return; + } + + assert.throws(RangeError, function() { + new TA(buffer, 7); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-byteoffset-to-number-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-byteoffset-to-number-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..aca2e5331a6e42a5a1ec329bbe0b7f00d85e2d28 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-byteoffset-to-number-throws-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt from parsing integer value from byteOffset +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToInteger(byteOffset). + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var byteOffset = { + valueOf: function() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, byteOffset); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-custom-proto-access-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-custom-proto-access-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..0cc7860d5da43f0f07fa66049e18309caacb7097 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-custom-proto-access-throws-sab.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return abrupt completion getting newTarget's prototype +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + ... + + 9.1.15 GetPrototypeFromConstructor ( constructor, intrinsicDefaultProto ) + + ... + 3. Let proto be ? Get(constructor, "prototype"). + ... +features: [Reflect, SharedArrayBuffer] +includes: [testTypedArray.js] +---*/ + +var buffer = new SharedArrayBuffer(8); + +var newTarget = function() {}.bind(null); +Object.defineProperty(newTarget, "prototype", { + get() { + throw new Test262Error(); + } +}); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + Reflect.construct(TA, [buffer], newTarget); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-length-and-offset-sab.js b/test/built-ins/TypedArrays/buffer-arg-defined-length-and-offset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..f1a71ebece20b06498fe452ba5e706af761629f2 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-length-and-offset-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined length and offset +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var offset = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(3 * offset); + + var ta1 = new TA(buffer, offset, 2); + assert.sameValue(ta1.length, 2, "ta1.length"); + assert.sameValue(ta1.buffer, buffer, "ta1.buffer"); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, offset, 0); + assert.sameValue(ta2.length, 0, "ta2.length"); + assert.sameValue(ta2.buffer, buffer, "ta2.buffer"); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-length-sab.js b/test/built-ins/TypedArrays/buffer-arg-defined-length-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..0acb7537ba8c1174303595b8fec6b6f7cb5afd60 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-length-sab.js @@ -0,0 +1,35 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined length +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var length = 4; + var buffer = new SharedArrayBuffer(bpe * length * 4); + + var ta1 = new TA(buffer, 0, length); + assert.sameValue(ta1.length, length); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0, 0); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-negative-length-sab.js b/test/built-ins/TypedArrays/buffer-arg-defined-negative-length-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..8ad965c6e03a93a0499d470d7a34219b7b0b8fb4 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-negative-length-sab.js @@ -0,0 +1,29 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws RangeError for negative ToInteger(length) +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(16); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(RangeError, function() { + new TA(buffer, 0, -1); + }); + + assert.throws(RangeError, function() { + new TA(buffer, 0, -Infinity); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-defined-offset-sab.js b/test/built-ins/TypedArrays/buffer-arg-defined-offset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..ddcb73e86531b070fe4e66cf92c0f3d86318605f --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-defined-offset-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from defined offset +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe * 4); + + var ta1 = new TA(buffer, bpe * 2); + assert.sameValue(ta1.length, 2); + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var ta2 = new TA(buffer, 0); + assert.sameValue(ta2.length, 4); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-excessive-length-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-excessive-length-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..95936bc4415681e3be950bd2e4e03a9fbac2ce9c --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-excessive-length-throws-sab.js @@ -0,0 +1,32 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + If offset + newByteLength > bufferByteLength, throw a RangeError exception. +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + b. Let newByteLength be newLength × elementSize. + c. If offset+newByteLength > bufferByteLength, throw a RangeError exception. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, 0, bpe * 2); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-excessive-offset-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-excessive-offset-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..0daffb5add736b05d6ef8e8c1dafcdc1d2d5a39d --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-excessive-offset-throws-sab.js @@ -0,0 +1,36 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a RangeError if bufferByteLength - ToInteger(byteOffset) < 0 +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 13. If length is undefined, then + a. If bufferByteLength modulo elementSize ≠0, throw a RangeError exception. + b. Let newByteLength be bufferByteLength - offset. + c. If newByteLength < 0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + var buffer = new SharedArrayBuffer(bpe); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2); + }); + + assert.throws(RangeError, function() { + new TA(buffer, bpe * 2, undefined); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-invoked-with-undefined-newtarget-sab.js b/test/built-ins/TypedArrays/buffer-arg-invoked-with-undefined-newtarget-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..d6cd3981ae1e3369d90c611043370284dd87f532 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-invoked-with-undefined-newtarget-sab.js @@ -0,0 +1,27 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a TypeError if NewTarget is undefined. +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 2. If NewTarget is undefined, throw a TypeError exception. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(4); + assert.throws(TypeError, function() { + TA(buffer); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-is-referenced-sab.js b/test/built-ins/TypedArrays/buffer-arg-is-referenced-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..eb119ea96838720c9ca48f372793d340154f5266 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-is-referenced-sab.js @@ -0,0 +1,33 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Reuse buffer argument instead of making a new clone +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 15. Set O's [[ViewedArrayBuffer]] internal slot to buffer. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer = new SharedArrayBuffer(bpe); + + var ta1 = new TA(buffer); + var ta2 = new TA(buffer); + + assert.sameValue(ta1.buffer, buffer); + assert.sameValue(ta2.buffer, buffer); + assert.sameValue(ta1.buffer, ta2.buffer); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-length-access-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-length-access-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..d0e19ded160e450a610b21319e88e9c2ebcbd949 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-length-access-throws-sab.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Returns abrupt from ToLength(length) +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var length = { + valueOf() { + throw new Test262Error(); + } +}; + +testWithTypedArrayConstructors(function(TA) { + assert.throws(Test262Error, function() { + new TA(buffer, 0, length); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-length-is-symbol-throws-sab.js b/test/built-ins/TypedArrays/buffer-arg-length-is-symbol-throws-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..6f28e307749c3a0b4716d61fee4af1fa629b9e7c --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-length-is-symbol-throws-sab.js @@ -0,0 +1,30 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Throws a TypeError if length is a Symbol +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 14. Else, + a. Let newLength be ? ToLength(length). + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); +var length = Symbol("1"); + +testWithTypedArrayConstructors(function(TA) { + assert.throws(TypeError, function() { + new TA(buffer, 0, length); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-new-instance-extensibility-sab.js b/test/built-ins/TypedArrays/buffer-arg-new-instance-extensibility-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..80f506d7f0d02c8bd6e7994956bf6d9a1068e4d6 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-new-instance-extensibility-sab.js @@ -0,0 +1,38 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + The new typedArray instance from a buffer argument is extensible +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + ... + 2. Let obj be IntegerIndexedObjectCreate(proto, « [[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]] »). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 11. Set the [[Extensible]] internal slot of A to true. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var buffer = new SharedArrayBuffer(8); + var sample = new TA(buffer); + + assert(Object.isExtensible(sample)); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-proto-from-ctor-realm-sab.js b/test/built-ins/TypedArrays/buffer-arg-proto-from-ctor-realm-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..c7dbc656a9d0f059f175cb71f55997c91d484be0 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-proto-from-ctor-realm-sab.js @@ -0,0 +1,39 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: Default [[Prototype]] value derived from realm of the newTarget +info: | + [...] + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + "%TypedArrayPrototype%"). + [...] + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + [...] + + 9.1.14 GetPrototypeFromConstructor + + [...] + 3. Let proto be ? Get(constructor, "prototype"). + 4. If Type(proto) is not Object, then + a. Let realm be ? GetFunctionRealm(constructor). + b. Let proto be realm's intrinsic object named intrinsicDefaultProto. + 5. Return proto. +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +features: [Reflect] +---*/ + +var other = $.createRealm().global; +var C = new other.Function(); +C.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [new SharedArrayBuffer(8)], C); + + assert.sameValue(Object.getPrototypeOf(ta), other[TA.name].prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-returns-new-instance-sab.js b/test/built-ins/TypedArrays/buffer-arg-returns-new-instance-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..e702f69304fa691d990703cbcfa88264c9f5ee33 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-returns-new-instance-sab.js @@ -0,0 +1,34 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Return new typedArray from undefined offset and length +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +testWithTypedArrayConstructors(function(TA) { + var bpe = TA.BYTES_PER_ELEMENT; + + var buffer1 = new SharedArrayBuffer(bpe * 4); + var ta1 = new TA(buffer1); + assert.sameValue(ta1.length, 4); + assert.sameValue(ta1.buffer, buffer1); + assert.sameValue(ta1.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta1), TA.prototype); + + var buffer2 = new SharedArrayBuffer(0); + var ta2 = new TA(buffer2); + assert.sameValue(ta2.length, 0); + assert.sameValue(ta2.buffer, buffer2); + assert.sameValue(ta2.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta2), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-toindex-bytelength-sab.js b/test/built-ins/TypedArrays/buffer-arg-toindex-bytelength-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..e5791798a72a62a311bbe7ea3fa0113298caccf6 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-toindex-bytelength-sab.js @@ -0,0 +1,73 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + ToIndex(length) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 11. If length is either not present or undefined, then + ... + 12. Else, + a. Let newLength be ? ToIndex(length). + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 1; + } +}; + +var obj2 = { + toString: function() { + return 1; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 1, "object's valueOf"], + [obj2, 1, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["1", 1, "string '1'"], + [false, 0, "false"], + [true, 1, "true"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [1.1, 1, "1.1"], + [1.9, 1, "1.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var len = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, 0, len); + assert.sameValue(typedArray.length, expected, name + " length"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-toindex-byteoffset-sab.js b/test/built-ins/TypedArrays/buffer-arg-toindex-byteoffset-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..301172224eb87e4b53ada8e6d465caeebeb26e3c --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-toindex-byteoffset-sab.js @@ -0,0 +1,87 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + ToIndex(byteOffset) operations +info: | + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 7. Let offset be ? ToIndex(byteOffset). + 8. If offset modulo elementSize ≠0, throw a RangeError exception. + ... +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(16); + +var obj1 = { + valueOf: function() { + return 8; + } +}; + +var obj2 = { + toString: function() { + return 8; + } +}; + +var items = [ + [-0, 0, "-0"], + [obj1, 8, "object's valueOf"], + [obj2, 8, "object's toString"], + ["", 0, "the Empty string"], + ["0", 0, "string '0'"], + ["8", 8, "string '8'"], + [false, 0, "false"], + [NaN, 0, "NaN"], + [null, 0, "null"], + [undefined, 0, "undefined"], + [0.1, 0, "0.1"], + [0.9, 0, "0.9"], + [8.1, 8, "8.1"], + [8.9, 8, "8.9"], + [-0.1, 0, "-0.1"], + [-0.99999, 0, "-0.99999"] +]; + +testWithTypedArrayConstructors(function(TA) { + items.forEach(function(item) { + var offset = item[0]; + var expected = item[1]; + var name = item[2]; + + var typedArray = new TA(buffer, offset); + assert.sameValue(typedArray.byteOffset, expected, name + " byteOffset"); + assert.sameValue(typedArray.constructor, TA, name + " constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + name + " prototype" + ); + }); + + // Testing `true`. See step 8 + if (TA.BYTES_PER_ELEMENT === 1) { + var typedArray = new TA(buffer, true); + assert.sameValue(typedArray.byteOffset, 1, "true => 1 byteOffset"); + assert.sameValue(typedArray.constructor, TA, "true => 1 constructor"); + assert.sameValue( + Object.getPrototypeOf(typedArray), + TA.prototype, + "true => 1 prototype" + ); + } else { + assert.throws(RangeError, function() { + new TA(buffer, true); + }, "1 modulo elementSize ≠0, throws a RangeError"); + } +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-typedarray-backed-by-sharedarraybuffer.js b/test/built-ins/TypedArrays/buffer-arg-typedarray-backed-by-sharedarraybuffer.js new file mode 100644 index 0000000000000000000000000000000000000000..eecbe5eddbe53c703b109ad1d1cf850de78d2b1f --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-typedarray-backed-by-sharedarraybuffer.js @@ -0,0 +1,23 @@ +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-typedarray-typedarray +description: > + Passing a SharedArrayBuffer-backed TypedArray to a TypedArray constructor + produces an ArrayBuffer-backed TypedArray. +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var sab = new SharedArrayBuffer(4); +var int_views = [Int8Array, Uint8Array, Int16Array, Uint16Array, Int32Array, Uint32Array]; + +testWithTypedArrayConstructors(function(View1) { + var ta1 = new View1(sab); + testWithTypedArrayConstructors(function(View2) { + var ta2 = new View2(ta1); + assert.sameValue(ta2.buffer.constructor, ArrayBuffer, + "TypedArray of SharedArrayBuffer-backed TypedArray is ArrayBuffer-backed"); + }, int_views); +}, int_views); diff --git a/test/built-ins/TypedArrays/buffer-arg-use-custom-proto-if-object-sab.js b/test/built-ins/TypedArrays/buffer-arg-use-custom-proto-if-object-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..678713d72136872fb87c88d80d50b1a6e35d50c8 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-use-custom-proto-if-object-sab.js @@ -0,0 +1,50 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Use prototype from new target if it's an Object +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +features: [Reflect] +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +var proto = {}; +newTarget.prototype = proto; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, Object); + assert.sameValue(Object.getPrototypeOf(ta), proto); +}); diff --git a/test/built-ins/TypedArrays/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js b/test/built-ins/TypedArrays/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..60b4fcbb65e6828db83fc7a4255f2bbad0da5e71 --- /dev/null +++ b/test/built-ins/TypedArrays/buffer-arg-use-default-proto-if-custom-proto-is-not-object-sab.js @@ -0,0 +1,48 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: sec-typedarray-buffer-byteoffset-length +description: > + Use prototype from %TypedArray% if newTarget's prototype is not an Object +info: > + 22.2.4.5 TypedArray ( buffer [ , byteOffset [ , length ] ] ) + + This description applies only if the TypedArray function is called with at + least one argument and the Type of the first argument is Object and that + object has an [[ArrayBufferData]] internal slot. + + ... + 4. Let O be ? AllocateTypedArray(constructorName, NewTarget, + %TypedArrayPrototype%). + ... + + 22.2.4.2.1 Runtime Semantics: AllocateTypedArray (constructorName, newTarget, + defaultProto [ , length ]) + + 1. Let proto be ? GetPrototypeFromConstructor(newTarget, defaultProto). + 2. Let obj be IntegerIndexedObjectCreate (proto, «[[ViewedArrayBuffer]], + [[TypedArrayName]], [[ByteLength]], [[ByteOffset]], [[ArrayLength]]» ). + ... + + 9.4.5.7 IntegerIndexedObjectCreate (prototype, internalSlotsList) + + ... + 10. Set the [[Prototype]] internal slot of A to prototype. + ... + 12. Return A. +includes: [testTypedArray.js] +features: [SharedArrayBuffer] +---*/ + +var buffer = new SharedArrayBuffer(8); + +function newTarget() {} +newTarget.prototype = null; + +testWithTypedArrayConstructors(function(TA) { + var ta = Reflect.construct(TA, [buffer], newTarget); + + assert.sameValue(ta.constructor, TA); + assert.sameValue(Object.getPrototypeOf(ta), TA.prototype); +}); diff --git a/test/built-ins/TypedArrays/internals/Get/indexed-value-sab.js b/test/built-ins/TypedArrays/internals/Get/indexed-value-sab.js new file mode 100644 index 0000000000000000000000000000000000000000..2c0ab922ac30d63998a77ed095f21bc7cdf5cf97 --- /dev/null +++ b/test/built-ins/TypedArrays/internals/Get/indexed-value-sab.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 the V8 project authors. 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: > + Return value from valid numeric index, with SharedArrayBuffer +includes: [testTypedArray.js] +---*/ + +var proto = TypedArray.prototype; +var throwDesc = { + get: function() { + throw new Test262Error("OrdinaryGet was called! Ref: 9.1.8.1 3.c"); + } +}; +Object.defineProperty(proto, "0", throwDesc); +Object.defineProperty(proto, "1", throwDesc); + +testWithTypedArrayConstructors(function(TA) { + var sab = new SharedArrayBuffer(TA.BYTES_PER_ELEMENT * 2); + var sample = new TA(sab); + sample.set([42, 1]); + + assert.sameValue(sample["0"], 42); + assert.sameValue(sample["1"], 1); +});