diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/test262/built-ins/Atomics/isLockFree | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/test262/built-ins/Atomics/isLockFree')
11 files changed, 402 insertions, 0 deletions
diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/browser.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/browser.js diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/expected-return-value.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/expected-return-value.js new file mode 100644 index 0000000000..3d9cb376dc --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/expected-return-value.js @@ -0,0 +1,38 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2018 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.isLockFree +description: > + Atomics.isLockFree returns a boolean that indicates whether + operations on datum of size will be performed without the agent + acquiring a lock outside of size bytes. +info: | + Atomics.isLockFree( size ) + + 1. Let n be ? ToInteger(size). + 2. Let AR be the Agent Record of the surrounding agent. + 3. If n equals 1, return AR.[[IsLockFree1]]. + 4. If n equals 2, return AR.[[IsLockFree2]]. + 5. If n equals 4, return true. + 6. If n equals 8, return AR.[[IsLockFree8]]. + 7. Return false. + +features: [Atomics, BigInt, SharedArrayBuffer, TypedArray] +includes: [testBigIntTypedArray.js] +---*/ + +testWithBigIntTypedArrayConstructors(function(TA) { + var observed = Atomics.isLockFree(TA.BYTES_PER_ELEMENT); + + assert.sameValue( + Atomics.isLockFree(TA.BYTES_PER_ELEMENT), + observed, + 'Atomics.isLockFree(TA.BYTES_PER_ELEMENT) returns the value of `observed` (Atomics.isLockFree(TA.BYTES_PER_ELEMENT))' + ); +}); + + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/shell.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/shell.js new file mode 100644 index 0000000000..90ee9c114d --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/bigint/shell.js @@ -0,0 +1,42 @@ +// GENERATED, DO NOT EDIT +// file: testBigIntTypedArray.js +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +description: | + Collection of functions used to assert the correctness of BigInt TypedArray objects. +defines: + - TypedArray + - testWithBigIntTypedArrayConstructors +---*/ + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Calls the provided function for every typed array constructor. + * + * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. + * @param {Array} selected - An optional Array with filtered typed arrays + */ +function testWithBigIntTypedArrayConstructors(f, selected) { + /** + * Array containing every BigInt typed array constructor. + */ + var constructors = selected || [ + BigInt64Array, + BigUint64Array + ]; + + for (var i = 0; i < constructors.length; ++i) { + var constructor = constructors[i]; + try { + f(constructor); + } catch (e) { + e.message += " (Testing with " + constructor.name + ".)"; + throw e; + } + } +} diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/browser.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/browser.js new file mode 100644 index 0000000000..e69de29bb2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/browser.js diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/corner-cases.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/corner-cases.js new file mode 100644 index 0000000000..f398e06100 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/corner-cases.js @@ -0,0 +1,78 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.islockfree +description: > + Test isLockFree on various non-intuitive arguments +features: [Atomics] +---*/ + +assert.sameValue( + Atomics.isLockFree(hide(3, Number.NaN)), + false, + 'Atomics.isLockFree(hide(3, Number.NaN)) returns false' +); +assert.sameValue( + Atomics.isLockFree(hide(3, -1)), + false, + 'Atomics.isLockFree(hide(3, -1)) returns false' +); +assert.sameValue( + Atomics.isLockFree(hide(3, 3.14)), + false, + 'Atomics.isLockFree(hide(3, 3.14)) returns false' +); +assert.sameValue( + Atomics.isLockFree(hide(3, 0)), + false, + 'Atomics.isLockFree(hide(3, 0)) returns false' +); + +assert.sameValue( + Atomics.isLockFree('1'), + Atomics.isLockFree(1), + 'Atomics.isLockFree(\'1\') returns Atomics.isLockFree(1)' +); +assert.sameValue( + Atomics.isLockFree('3'), + Atomics.isLockFree(3), + 'Atomics.isLockFree(\'3\') returns Atomics.isLockFree(3)' +); + +assert.sameValue( + Atomics.isLockFree(true), + Atomics.isLockFree(1), + 'Atomics.isLockFree(true) returns Atomics.isLockFree(1)' +); + +assert.sameValue( + Atomics.isLockFree(1), + Atomics.isLockFree({valueOf: () => 1}), + 'Atomics.isLockFree(1) returns Atomics.isLockFree({valueOf: () => 1})' +); +assert.sameValue( + Atomics.isLockFree(3), + Atomics.isLockFree({valueOf: () => 3}), + 'Atomics.isLockFree(3) returns Atomics.isLockFree({valueOf: () => 3})' +); +assert.sameValue( + Atomics.isLockFree(1), + Atomics.isLockFree({toString: () => '1'}), + 'Atomics.isLockFree(1) returns Atomics.isLockFree({toString: () => \'1\'})' +); +assert.sameValue( + Atomics.isLockFree(3), + Atomics.isLockFree({toString: () => '3'}), + 'Atomics.isLockFree(3) returns Atomics.isLockFree({toString: () => \'3\'})' +); + +function hide(k, x) { + if (k) { + return hide(k - 3, x) + x; + } + return 0; +} + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/descriptor.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/descriptor.js new file mode 100644 index 0000000000..48dd04aeb5 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/descriptor.js @@ -0,0 +1,18 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the license found in the LICENSE file. + +/*--- +esid: sec-atomics.islockfree +description: Testing descriptor property of Atomics.add +includes: [propertyHelper.js] +features: [Atomics] +---*/ + +verifyProperty(Atomics, 'add', { + enumerable: false, + writable: true, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/expected-return-value.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/expected-return-value.js new file mode 100644 index 0000000000..b7cdc26857 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/expected-return-value.js @@ -0,0 +1,114 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// Copyright (C) 2017 Mozilla Corporation. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-atomics.islockfree +description: > + Atomics.isLockFree( size ) + Let n be ? ToInteger(size). + Let AR be the Agent Record of the surrounding agent. + If n equals 1, return AR.[[IsLockFree1]]. + If n equals 2, return AR.[[IsLockFree2]]. + If n equals 4, return true. + If n equals 8, return AR.[[IsLockFree8]]. + Return false. +features: [Atomics, Array.prototype.includes] +---*/ + +// These are the only counts that we care about tracking. +var isLockFree1; +var isLockFree2; +var isLockFree8; + +{ + isLockFree1 = Atomics.isLockFree(1); + // + // If n equals 1, return AR.[[IsLockFree1]]. + // + assert.sameValue(typeof isLockFree1, 'boolean', 'The value of `typeof isLockFree1` is "boolean"'); + // Once the values of [[Signifier]], [[IsLockFree1]], [[IsLockFree2]], + // and [[IsLockFree8]] have been observed by any agent in the agent + // cluster they cannot change. + assert.sameValue( + Atomics.isLockFree(1), + isLockFree1, + 'Atomics.isLockFree(1) returns the value of `isLockFree1` (Atomics.isLockFree(1))' + ); +}; +{ + isLockFree2 = Atomics.isLockFree(2); + // + // If n equals 2, return AR.[[IsLockFree2]]. + // + assert.sameValue(typeof isLockFree2, 'boolean', 'The value of `typeof isLockFree2` is "boolean"'); + // Once the values of [[Signifier]], [[IsLockFree1]], [[IsLockFree2]], + // and [[IsLockFree8]] have been observed by any agent in the agent + // cluster they cannot change. + assert.sameValue( + Atomics.isLockFree(2), + isLockFree2, + 'Atomics.isLockFree(2) returns the value of `isLockFree2` (Atomics.isLockFree(2))' + ); +}; +{ + let isLockFree4 = Atomics.isLockFree(4); + // + // If n equals 4, return true. + // + assert.sameValue(typeof isLockFree4, 'boolean', 'The value of `typeof isLockFree4` is "boolean"'); + assert.sameValue(isLockFree4, true, 'The value of `isLockFree4` is true'); +}; + +{ + isLockFree8 = Atomics.isLockFree(8); + // + // If n equals 8, return AR.[[IsLockFree8]]. + // + assert.sameValue(typeof isLockFree8, 'boolean', 'The value of `typeof isLockFree8` is "boolean"'); + // Once the values of [[Signifier]], [[IsLockFree1]], [[IsLockFree2]], + // and [[IsLockFree8]] have been observed by any agent in the agent + // cluster they cannot change. + assert.sameValue( + Atomics.isLockFree(8), + isLockFree8, + 'Atomics.isLockFree(8) returns the value of `isLockFree8` (Atomics.isLockFree(8))' + ); +}; + +{ + for (let i = 0; i < 12; i++) { + if (![1, 2, 4, 8].includes(i)) { + assert.sameValue(Atomics.isLockFree(i), false, 'Atomics.isLockFree(i) returns false'); + } + } +}; + +assert.sameValue( + Atomics.isLockFree(1), + isLockFree1, + 'Atomics.isLockFree(1) returns the value of `isLockFree1` (Atomics.isLockFree(1))' +); +assert.sameValue( + Atomics.isLockFree(2), + isLockFree2, + 'Atomics.isLockFree(2) returns the value of `isLockFree2` (Atomics.isLockFree(2))' +); +assert.sameValue( + Atomics.isLockFree(8), + isLockFree8, + 'Atomics.isLockFree(8) returns the value of `isLockFree8` (Atomics.isLockFree(8))' +); + +// Duplicates behavior created by loop from above +assert.sameValue(Atomics.isLockFree(3), false, 'Atomics.isLockFree(3) returns false'); +assert.sameValue(Atomics.isLockFree(4), true, 'Atomics.isLockFree(4) returns true'); +assert.sameValue(Atomics.isLockFree(5), false, 'Atomics.isLockFree(5) returns false'); +assert.sameValue(Atomics.isLockFree(6), false, 'Atomics.isLockFree(6) returns false'); +assert.sameValue(Atomics.isLockFree(7), false, 'Atomics.isLockFree(7) returns false'); +assert.sameValue(Atomics.isLockFree(9), false, 'Atomics.isLockFree(9) returns false'); +assert.sameValue(Atomics.isLockFree(10), false, 'Atomics.isLockFree(10) returns false'); +assert.sameValue(Atomics.isLockFree(11), false, 'Atomics.isLockFree(11) returns false'); +assert.sameValue(Atomics.isLockFree(12), false, 'Atomics.isLockFree(12) returns false'); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/length.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/length.js new file mode 100644 index 0000000000..95f2343657 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/length.js @@ -0,0 +1,35 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// 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-atomics.islockfree +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] +features: [Atomics] +---*/ + +verifyProperty(Atomics.isLockFree, 'length', { + value: 1, + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/name.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/name.js new file mode 100644 index 0000000000..78022fe120 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/name.js @@ -0,0 +1,21 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')) -- Atomics is not enabled unconditionally +// 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-atomics.islockfree +description: > + Atomics.isLockFree.name is "isLockFree". +includes: [propertyHelper.js] +features: [Atomics] +---*/ + +verifyProperty(Atomics.isLockFree, 'name', { + value: 'isLockFree', + enumerable: false, + writable: false, + configurable: true, +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/not-a-constructor.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/not-a-constructor.js new file mode 100644 index 0000000000..63054624e2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/not-a-constructor.js @@ -0,0 +1,32 @@ +// |reftest| skip-if(!this.hasOwnProperty('Atomics')||!this.hasOwnProperty('SharedArrayBuffer')||(this.hasOwnProperty('getBuildConfiguration')&&getBuildConfiguration()['arm64-simulator'])) -- Atomics,SharedArrayBuffer is not enabled unconditionally, ARM64 Simulator cannot emulate atomics +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-ecmascript-standard-built-in-objects +description: > + Atomics.isLockFree does not implement [[Construct]], is not new-able +info: | + ECMAScript Function 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. + + sec-evaluatenew + + ... + 7. If IsConstructor(constructor) is false, throw a TypeError exception. + ... +includes: [isConstructor.js] +features: [Reflect.construct, Atomics, arrow-function, TypedArray, SharedArrayBuffer] +---*/ + +assert.sameValue(isConstructor(Atomics.isLockFree), false, 'isConstructor(Atomics.isLockFree) must return false'); + +assert.throws(TypeError, () => { + new Atomics.isLockFree(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT))); +}, '`new Atomics.isLockFree(new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT)))` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/Atomics/isLockFree/shell.js b/js/src/tests/test262/built-ins/Atomics/isLockFree/shell.js new file mode 100644 index 0000000000..eda1477282 --- /dev/null +++ b/js/src/tests/test262/built-ins/Atomics/isLockFree/shell.js @@ -0,0 +1,24 @@ +// GENERATED, DO NOT EDIT +// file: isConstructor.js +// Copyright (C) 2017 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +description: | + Test if a given function is a constructor function. +defines: [isConstructor] +features: [Reflect.construct] +---*/ + +function isConstructor(f) { + if (typeof f !== "function") { + throw new Test262Error("isConstructor invoked with a non-function value"); + } + + try { + Reflect.construct(function(){}, [], f); + } catch (e) { + return false; + } + return true; +} |