Bug 1885337 - Part 3: Import tests from test262 PR. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / prs / 3994 / built-ins / Uint8Array / prototype / toBase64 / shell.js
blob2af708ed5996862df9f1ae07b0ea7897cf35c389
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.
5 /*---
6 description: |
7     A function used in the process of asserting correctness of TypedArray objects.
9     $262.detachArrayBuffer is defined by a host.
10 defines: [$DETACHBUFFER]
11 ---*/
13 function $DETACHBUFFER(buffer) {
14   if (!$262 || typeof $262.detachArrayBuffer !== "function") {
15     throw new Test262Error("No method available to detach an ArrayBuffer");
16   }
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.
24 /*---
25 description: |
26     Test if a given function is a constructor function.
27 defines: [isConstructor]
28 features: [Reflect.construct]
29 ---*/
31 function isConstructor(f) {
32     if (typeof f !== "function") {
33       throw new Test262Error("isConstructor invoked with a non-function value");
34     }
36     try {
37         Reflect.construct(function(){}, [], f);
38     } catch (e) {
39         return false;
40     }
41     return true;
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.
47 /*---
48 description: |
49     Collection of functions used to assert the correctness of TypedArray objects.
50 defines:
51   - floatArrayConstructors
52   - nonClampedIntArrayConstructors
53   - intArrayConstructors
54   - typedArrayConstructors
55   - TypedArray
56   - testWithTypedArrayConstructors
57   - nonAtomicsFriendlyTypedArrayConstructors
58   - testWithAtomicsFriendlyTypedArrayConstructors
59   - testWithNonAtomicsFriendlyTypedArrayConstructors
60   - testTypedArrayConversions
61 ---*/
63 var floatArrayConstructors = [
64   Float64Array,
65   Float32Array
68 var nonClampedIntArrayConstructors = [
69   Int32Array,
70   Int16Array,
71   Int8Array,
72   Uint32Array,
73   Uint16Array,
74   Uint8Array
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);
85 /**
86  * Array containing every non-bigint typed array constructor.
87  */
89 var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);
91 /**
92  * The %TypedArray% intrinsic constructor function.
93  */
94 var TypedArray = Object.getPrototypeOf(Int8Array);
96 /**
97  * Callback for testing a typed array constructor.
98  *
99  * @callback typedArrayConstructorCallback
100  * @param {Function} Constructor the constructor object to test with.
101  */
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
108  */
109 function testWithTypedArrayConstructors(f, selected) {
110   var constructors = selected || typedArrayConstructors;
111   for (var i = 0; i < constructors.length; ++i) {
112     var constructor = constructors[i];
113     try {
114       f(constructor);
115     } catch (e) {
116       e.message += " (Testing with " + constructor.name + ".)";
117       throw e;
118     }
119   }
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
128  */
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
138  */
139 function testWithAtomicsFriendlyTypedArrayConstructors(f) {
140   testWithTypedArrayConstructors(f, [
141     Int32Array,
142     Int16Array,
143     Int8Array,
144     Uint32Array,
145     Uint16Array,
146     Uint8Array,
147   ]);
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.
158  */
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];
168       var initial = 0;
169       if (exp === 0) {
170         initial = 1;
171       }
172       fn(TA, value, exp, initial);
173     });
174   });
178  * Checks if the given argument is one of the float-based TypedArray constructors.
180  * @param {constructor} ctor - the value to check
181  * @returns {boolean}
182  */
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.
192  */
193 function floatTypedArrayConstructorPrecision(FA) {
194   if (typeof Float16Array !== "undefined" && FA === Float16Array) {
195     return "half";
196   } else if (FA === Float32Array) {
197     return "single";
198   } else if (FA === Float64Array) {
199     return "double";
200   } else {
201     throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray");
202   }