1 // GENERATED, DO NOT EDIT
2 // file: detachArrayBuffer.js
3 // Copyright (C) 2016 the V8 project authors. All rights reserved.
4 // This code is governed by the BSD license found in the LICENSE file.
7 A function used in the process of asserting correctness of TypedArray objects.
9 $262.detachArrayBuffer is defined by a host.
10 defines: [$DETACHBUFFER]
13 function $DETACHBUFFER(buffer) {
14 if (!$262 || typeof $262.detachArrayBuffer !== "function") {
15 throw new Test262Error("No method available to detach an ArrayBuffer");
17 $262.detachArrayBuffer(buffer);
20 // file: isConstructor.js
21 // Copyright (C) 2017 André Bargull. All rights reserved.
22 // This code is governed by the BSD license found in the LICENSE file.
26 Test if a given function is a constructor function.
27 defines: [isConstructor]
28 features: [Reflect.construct]
31 function isConstructor(f) {
32 if (typeof f !== "function") {
33 throw new Test262Error("isConstructor invoked with a non-function value");
37 Reflect.construct(function(){}, [], f);
44 // file: testTypedArray.js
45 // Copyright (C) 2015 André Bargull. All rights reserved.
46 // This code is governed by the BSD license found in the LICENSE file.
49 Collection of functions used to assert the correctness of TypedArray objects.
51 - floatArrayConstructors
52 - nonClampedIntArrayConstructors
53 - intArrayConstructors
54 - typedArrayConstructors
56 - testWithTypedArrayConstructors
57 - nonAtomicsFriendlyTypedArrayConstructors
58 - testWithAtomicsFriendlyTypedArrayConstructors
59 - testWithNonAtomicsFriendlyTypedArrayConstructors
60 - testTypedArrayConversions
63 var floatArrayConstructors = [
68 var nonClampedIntArrayConstructors = [
77 var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]);
79 // Float16Array is a newer feature
80 // adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it
81 if (typeof Float16Array !== 'undefined') {
82 floatArrayConstructors.push(Float16Array);
86 * Array containing every non-bigint typed array constructor.
89 var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);
92 * The %TypedArray% intrinsic constructor function.
94 var TypedArray = Object.getPrototypeOf(Int8Array);
97 * Callback for testing a typed array constructor.
99 * @callback typedArrayConstructorCallback
100 * @param {Function} Constructor the constructor object to test with.
104 * Calls the provided function for every typed array constructor.
106 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
107 * @param {Array} selected - An optional Array with filtered typed arrays
109 function testWithTypedArrayConstructors(f, selected) {
110 var constructors = selected || typedArrayConstructors;
111 for (var i = 0; i < constructors.length; ++i) {
112 var constructor = constructors[i];
116 e.message += " (Testing with " + constructor.name + ".)";
122 var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]);
124 * Calls the provided function for every non-"Atomics Friendly" typed array constructor.
126 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
127 * @param {Array} selected - An optional Array with filtered typed arrays
129 function testWithNonAtomicsFriendlyTypedArrayConstructors(f) {
130 testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors);
134 * Calls the provided function for every "Atomics Friendly" typed array constructor.
136 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
137 * @param {Array} selected - An optional Array with filtered typed arrays
139 function testWithAtomicsFriendlyTypedArrayConstructors(f) {
140 testWithTypedArrayConstructors(f, [
151 * Helper for conversion operations on TypedArrays, the expected values
152 * properties are indexed in order to match the respective value for each
153 * TypedArray constructor
154 * @param {Function} fn - the function to call for each constructor and value.
155 * will be called with the constructor, value, expected
156 * value, and a initial value that can be used to avoid
157 * a false positive with an equivalent expected value.
159 function testTypedArrayConversions(byteConversionValues, fn) {
160 var values = byteConversionValues.values;
161 var expected = byteConversionValues.expected;
163 testWithTypedArrayConstructors(function(TA) {
164 var name = TA.name.slice(0, -5);
166 return values.forEach(function(value, index) {
167 var exp = expected[name][index];
172 fn(TA, value, exp, initial);
178 * Checks if the given argument is one of the float-based TypedArray constructors.
180 * @param {constructor} ctor - the value to check
183 function isFloatTypedArrayConstructor(arg) {
184 return floatArrayConstructors.indexOf(arg) !== -1;
188 * Determines the precision of the given float-based TypedArray constructor.
190 * @param {constructor} ctor - the value to check
191 * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively.
193 function floatTypedArrayConstructorPrecision(FA) {
194 if (typeof Float16Array !== "undefined" && FA === Float16Array) {
196 } else if (FA === Float32Array) {
198 } else if (FA === Float64Array) {
201 throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray");