From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- .../isView/arg-has-no-viewedarraybuffer.js | 19 +++ .../ArrayBuffer/isView/arg-is-arraybuffer.js | 20 +++ .../ArrayBuffer/isView/arg-is-dataview-buffer.js | 21 +++ .../isView/arg-is-dataview-constructor.js | 19 +++ .../isView/arg-is-dataview-subclass-instance.js | 23 +++ .../ArrayBuffer/isView/arg-is-dataview.js | 21 +++ .../ArrayBuffer/isView/arg-is-not-object.js | 20 +++ .../ArrayBuffer/isView/arg-is-typedarray-buffer.js | 24 +++ .../isView/arg-is-typedarray-constructor.js | 22 +++ .../isView/arg-is-typedarray-subclass-instance.js | 26 ++++ .../ArrayBuffer/isView/arg-is-typedarray.js | 24 +++ .../built-ins/ArrayBuffer/isView/browser.js | 0 .../ArrayBuffer/isView/invoked-as-a-fn.js | 31 ++++ .../test262/built-ins/ArrayBuffer/isView/length.js | 31 ++++ .../test262/built-ins/ArrayBuffer/isView/name.js | 28 ++++ .../test262/built-ins/ArrayBuffer/isView/no-arg.js | 17 +++ .../ArrayBuffer/isView/not-a-constructor.js | 31 ++++ .../built-ins/ArrayBuffer/isView/prop-desc.js | 19 +++ .../test262/built-ins/ArrayBuffer/isView/shell.js | 161 +++++++++++++++++++++ 19 files changed, 557 insertions(+) create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-has-no-viewedarraybuffer.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-arraybuffer.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-buffer.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-constructor.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-subclass-instance.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-not-object.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-buffer.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-constructor.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/browser.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/invoked-as-a-fn.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/length.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/name.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/no-arg.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/not-a-constructor.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/prop-desc.js create mode 100644 js/src/tests/test262/built-ins/ArrayBuffer/isView/shell.js (limited to 'js/src/tests/test262/built-ins/ArrayBuffer/isView') diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-has-no-viewedarraybuffer.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-has-no-viewedarraybuffer.js new file mode 100644 index 0000000000..28138d45e3 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-has-no-viewedarraybuffer.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false if arg has no [[ViewedArrayBuffer]] internal slot. +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +---*/ + +assert.sameValue(ArrayBuffer.isView({}), false, "ordinary object"); +assert.sameValue(ArrayBuffer.isView([]), false, "Array"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-arraybuffer.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-arraybuffer.js new file mode 100644 index 0000000000..2ca8a2d1ee --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-arraybuffer.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false from an instance of ArrayBuffer +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +---*/ + +var sample = new ArrayBuffer(1); + +assert.sameValue(ArrayBuffer.isView(sample), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-buffer.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-buffer.js new file mode 100644 index 0000000000..2b59775a4b --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-buffer.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false from DataView's instance `.buffer` +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [DataView] +---*/ + +var sample = new DataView(new ArrayBuffer(1), 0, 0).buffer; + +assert.sameValue(ArrayBuffer.isView(sample), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-constructor.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-constructor.js new file mode 100644 index 0000000000..1095947f70 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-constructor.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false if arg is the DataView constructor +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [DataView] +---*/ + +assert.sameValue(ArrayBuffer.isView(DataView), false, "DataView"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-subclass-instance.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-subclass-instance.js new file mode 100644 index 0000000000..727e318f0d --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview-subclass-instance.js @@ -0,0 +1,23 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return true if arg is an instance from a subclass of DataView +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [class, DataView] +---*/ + +class DV extends DataView {} + +var sample = new DV(new ArrayBuffer(1), 0, 0); + +assert(ArrayBuffer.isView(sample)); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview.js new file mode 100644 index 0000000000..ab145cf6cf --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-dataview.js @@ -0,0 +1,21 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return true if is an instance of DataView +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [DataView] +---*/ + +var sample = new DataView(new ArrayBuffer(1), 0, 0); + +assert.sameValue(ArrayBuffer.isView(sample), true); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-not-object.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-not-object.js new file mode 100644 index 0000000000..3fc13f5b05 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-not-object.js @@ -0,0 +1,20 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false if arg is not Object +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + ... +---*/ + +assert.sameValue(ArrayBuffer.isView(null), false, "null"); +assert.sameValue(ArrayBuffer.isView(undefined), false, "undefined"); +assert.sameValue(ArrayBuffer.isView(1), false, "number"); +assert.sameValue(ArrayBuffer.isView(""), false, "string"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-buffer.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-buffer.js new file mode 100644 index 0000000000..9e8918b388 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-buffer.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false from TypedArray's instance `.buffer` +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + var sample = new ctor().buffer; + + assert.sameValue(ArrayBuffer.isView(sample), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-constructor.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-constructor.js new file mode 100644 index 0000000000..efd5d16984 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-constructor.js @@ -0,0 +1,22 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false if arg is a TypedArray constructor +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + assert.sameValue(ArrayBuffer.isView(ctor), false); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js new file mode 100644 index 0000000000..3d17140d0f --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray-subclass-instance.js @@ -0,0 +1,26 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return true if arg is an instance from a subclass of TypedArray +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [class, TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + class TA extends ctor {} + + var sample = new TA(); + + assert(ArrayBuffer.isView(sample)); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray.js new file mode 100644 index 0000000000..78cbfbbf61 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/arg-is-typedarray.js @@ -0,0 +1,24 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return true if arg is an instance of TypedArray +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray] +includes: [testTypedArray.js] +---*/ + +testWithTypedArrayConstructors(function(ctor) { + var sample = new ctor(); + + assert.sameValue(ArrayBuffer.isView(sample), true); +}); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/browser.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/browser.js new file mode 100644 index 0000000000..e69de29bb2 diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/invoked-as-a-fn.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/invoked-as-a-fn.js new file mode 100644 index 0000000000..e58a330cdb --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/invoked-as-a-fn.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. + +/*--- +esid: sec-arraybuffer.isview +description: > + `isView` can be invoked as a function +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + 2. If arg has a [[ViewedArrayBuffer]] internal slot, return true. + 3. Return false. +features: [TypedArray, DataView] +includes: [testTypedArray.js] +---*/ + +var isView = ArrayBuffer.isView; + +testWithTypedArrayConstructors(function(ctor) { + var sample = new ctor(); + assert.sameValue(isView(sample), true, "instance of TypedArray"); +}); + +var dv = new DataView(new ArrayBuffer(1), 0, 0); +assert.sameValue(isView(dv), true, "instance of DataView"); + +assert.sameValue(isView(), false, "undefined arg"); +assert.sameValue(isView({}), false, "ordinary object"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/length.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/length.js new file mode 100644 index 0000000000..d74f5ab42d --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/length.js @@ -0,0 +1,31 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + ArrayBuffer.isView.length is 1. +info: | + ArrayBuffer.isView ( arg ) + + 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(ArrayBuffer.isView.length, 1); + +verifyNotEnumerable(ArrayBuffer.isView, "length"); +verifyNotWritable(ArrayBuffer.isView, "length"); +verifyConfigurable(ArrayBuffer.isView, "length"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/name.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/name.js new file mode 100644 index 0000000000..e8ef8b04e5 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/name.js @@ -0,0 +1,28 @@ +// Copyright (C) 2015 André Bargull. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + ArrayBuffer.isView.name is "isView". +info: | + ArrayBuffer.isView ( arg ) + + 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(ArrayBuffer.isView.name, "isView"); + +verifyNotEnumerable(ArrayBuffer.isView, "name"); +verifyNotWritable(ArrayBuffer.isView, "name"); +verifyConfigurable(ArrayBuffer.isView, "name"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/no-arg.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/no-arg.js new file mode 100644 index 0000000000..c3b747b7bf --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/no-arg.js @@ -0,0 +1,17 @@ +// Copyright (C) 2016 The V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + Return false if isView is called with no arg +info: | + 24.1.3.1 ArrayBuffer.isView ( arg ) + + 1. If Type(arg) is not Object, return false. + ... +---*/ + +assert.sameValue(ArrayBuffer.isView(), false); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/not-a-constructor.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/not-a-constructor.js new file mode 100644 index 0000000000..09f8d71685 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/not-a-constructor.js @@ -0,0 +1,31 @@ +// 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: > + ArrayBuffer.isView 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, ArrayBuffer, arrow-function] +---*/ + +assert.sameValue(isConstructor(ArrayBuffer.isView), false, 'isConstructor(ArrayBuffer.isView) must return false'); + +assert.throws(TypeError, () => { + new ArrayBuffer.isView(); +}, '`new ArrayBuffer.isView()` throws TypeError'); + + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/prop-desc.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/prop-desc.js new file mode 100644 index 0000000000..3eebf6ed54 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/prop-desc.js @@ -0,0 +1,19 @@ +// Copyright (C) 2016 the V8 project authors. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-arraybuffer.isview +description: > + "isView" property of ArrayBuffer +info: | + ES6 section 17: 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(ArrayBuffer, "isView"); +verifyWritable(ArrayBuffer, "isView"); +verifyConfigurable(ArrayBuffer, "isView"); + +reportCompare(0, 0); diff --git a/js/src/tests/test262/built-ins/ArrayBuffer/isView/shell.js b/js/src/tests/test262/built-ins/ArrayBuffer/isView/shell.js new file mode 100644 index 0000000000..05fecd6ef1 --- /dev/null +++ b/js/src/tests/test262/built-ins/ArrayBuffer/isView/shell.js @@ -0,0 +1,161 @@ +// GENERATED, DO NOT EDIT +// file: testTypedArray.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 TypedArray objects. +defines: + - floatArrayConstructors + - nonClampedIntArrayConstructors + - intArrayConstructors + - typedArrayConstructors + - TypedArray + - testWithTypedArrayConstructors + - nonAtomicsFriendlyTypedArrayConstructors + - testWithAtomicsFriendlyTypedArrayConstructors + - testWithNonAtomicsFriendlyTypedArrayConstructors + - testTypedArrayConversions +---*/ + +var floatArrayConstructors = [ + Float64Array, + Float32Array +]; + +var nonClampedIntArrayConstructors = [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array +]; + +var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); + +// Float16Array is a newer feature +// adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it +if (typeof Float16Array !== 'undefined') { + floatArrayConstructors.push(Float16Array); +} + +/** + * Array containing every non-bigint typed array constructor. + */ + +var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); + +/** + * The %TypedArray% intrinsic constructor function. + */ +var TypedArray = Object.getPrototypeOf(Int8Array); + +/** + * Callback for testing a typed array constructor. + * + * @callback typedArrayConstructorCallback + * @param {Function} Constructor the constructor object to test with. + */ + +/** + * 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 testWithTypedArrayConstructors(f, selected) { + var constructors = selected || typedArrayConstructors; + 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; + } + } +} + +var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); +/** + * Calls the provided function for every non-"Atomics Friendly" 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 testWithNonAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); +} + +/** + * Calls the provided function for every "Atomics Friendly" 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 testWithAtomicsFriendlyTypedArrayConstructors(f) { + testWithTypedArrayConstructors(f, [ + Int32Array, + Int16Array, + Int8Array, + Uint32Array, + Uint16Array, + Uint8Array, + ]); +} + +/** + * Helper for conversion operations on TypedArrays, the expected values + * properties are indexed in order to match the respective value for each + * TypedArray constructor + * @param {Function} fn - the function to call for each constructor and value. + * will be called with the constructor, value, expected + * value, and a initial value that can be used to avoid + * a false positive with an equivalent expected value. + */ +function testTypedArrayConversions(byteConversionValues, fn) { + var values = byteConversionValues.values; + var expected = byteConversionValues.expected; + + testWithTypedArrayConstructors(function(TA) { + var name = TA.name.slice(0, -5); + + return values.forEach(function(value, index) { + var exp = expected[name][index]; + var initial = 0; + if (exp === 0) { + initial = 1; + } + fn(TA, value, exp, initial); + }); + }); +} + +/** + * Checks if the given argument is one of the float-based TypedArray constructors. + * + * @param {constructor} ctor - the value to check + * @returns {boolean} + */ +function isFloatTypedArrayConstructor(arg) { + return floatArrayConstructors.indexOf(arg) !== -1; +} + +/** + * Determines the precision of the given float-based TypedArray constructor. + * + * @param {constructor} ctor - the value to check + * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. + */ +function floatTypedArrayConstructorPrecision(FA) { + if (typeof Float16Array !== "undefined" && FA === Float16Array) { + return "half"; + } else if (FA === Float32Array) { + return "single"; + } else if (FA === Float64Array) { + return "double"; + } else { + throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); + } +} -- cgit v1.2.3