1 // GENERATED, DO NOT EDIT
2 // file: testAtomics.js
3 // Copyright (C) 2017 Mozilla Corporation. All rights reserved.
4 // This code is governed by the BSD license found in the LICENSE file.
7 Collection of functions used to assert the correctness of SharedArrayBuffer objects.
9 - testWithAtomicsOutOfBoundsIndices
10 - testWithAtomicsInBoundsIndices
11 - testWithAtomicsNonViewValues
16 * Calls the provided function for a each bad index that should throw a
17 * RangeError when passed to an Atomics method on a SAB-backed view where
18 * index 125 is out of range.
20 * @param f - the function to call for each bad index.
22 function testWithAtomicsOutOfBoundsIndices(f) {
24 function(view) { return -1; },
25 function(view) { return view.length; },
26 function(view) { return view.length * 2; },
27 function(view) { return Number.POSITIVE_INFINITY; },
28 function(view) { return Number.NEGATIVE_INFINITY; },
29 function(view) { return { valueOf: function() { return 125; } }; },
30 function(view) { return { toString: function() { return '125'; }, valueOf: false }; }, // non-callable valueOf triggers invocation of toString
33 for (var i = 0; i < bad_indices.length; ++i) {
34 var IdxGen = bad_indices[i];
38 e.message += ' (Testing with index gen ' + IdxGen + '.)';
45 * Calls the provided function for each good index that should not throw when
46 * passed to an Atomics method on a SAB-backed view.
48 * The view must have length greater than zero.
50 * @param f - the function to call for each good index.
52 function testWithAtomicsInBoundsIndices(f) {
53 // Most of these are eventually coerced to +0 by ToIndex.
55 function(view) { return 0/-1; },
56 function(view) { return '-0'; },
57 function(view) { return undefined; },
58 function(view) { return NaN; },
59 function(view) { return 0.5; },
60 function(view) { return '0.5'; },
61 function(view) { return -0.9; },
62 function(view) { return { password: 'qumquat' }; },
63 function(view) { return view.length - 1; },
64 function(view) { return { valueOf: function() { return 0; } }; },
65 function(view) { return { toString: function() { return '0'; }, valueOf: false }; }, // non-callable valueOf triggers invocation of toString
68 for (var i = 0; i < good_indices.length; ++i) {
69 var IdxGen = good_indices[i];
73 e.message += ' (Testing with index gen ' + IdxGen + '.)';
80 * Calls the provided function for each value that should throw a TypeError
81 * when passed to an Atomics method as a view.
83 * @param f - the function to call for each non-view value.
86 function testWithAtomicsNonViewValues(f) {
99 { password: 'qumquat' },
100 new DataView(new ArrayBuffer(10)),
101 new ArrayBuffer(128),
102 new SharedArrayBuffer(128),
105 function(x) { return -x; },
115 for (var i = 0; i < values.length; ++i) {
116 var nonView = values[i];
120 e.message += ' (Testing with non-view value ' + nonView + '.)';
127 // file: testTypedArray.js
128 // Copyright (C) 2015 André Bargull. All rights reserved.
129 // This code is governed by the BSD license found in the LICENSE file.
132 Collection of functions used to assert the correctness of TypedArray objects.
134 - floatArrayConstructors
135 - nonClampedIntArrayConstructors
136 - intArrayConstructors
137 - typedArrayConstructors
139 - testWithTypedArrayConstructors
140 - nonAtomicsFriendlyTypedArrayConstructors
141 - testWithAtomicsFriendlyTypedArrayConstructors
142 - testWithNonAtomicsFriendlyTypedArrayConstructors
143 - testTypedArrayConversions
146 var floatArrayConstructors = [
151 var nonClampedIntArrayConstructors = [
160 var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]);
162 // Float16Array is a newer feature
163 // adding it to this list unconditionally would cause implementations lacking it to fail every test which uses it
164 if (typeof Float16Array !== 'undefined') {
165 floatArrayConstructors.push(Float16Array);
169 * Array containing every non-bigint typed array constructor.
172 var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors);
175 * The %TypedArray% intrinsic constructor function.
177 var TypedArray = Object.getPrototypeOf(Int8Array);
180 * Callback for testing a typed array constructor.
182 * @callback typedArrayConstructorCallback
183 * @param {Function} Constructor the constructor object to test with.
187 * Calls the provided function for every typed array constructor.
189 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
190 * @param {Array} selected - An optional Array with filtered typed arrays
192 function testWithTypedArrayConstructors(f, selected) {
193 var constructors = selected || typedArrayConstructors;
194 for (var i = 0; i < constructors.length; ++i) {
195 var constructor = constructors[i];
199 e.message += " (Testing with " + constructor.name + ".)";
205 var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]);
207 * Calls the provided function for every non-"Atomics Friendly" typed array constructor.
209 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
210 * @param {Array} selected - An optional Array with filtered typed arrays
212 function testWithNonAtomicsFriendlyTypedArrayConstructors(f) {
213 testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors);
217 * Calls the provided function for every "Atomics Friendly" typed array constructor.
219 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor.
220 * @param {Array} selected - An optional Array with filtered typed arrays
222 function testWithAtomicsFriendlyTypedArrayConstructors(f) {
223 testWithTypedArrayConstructors(f, [
234 * Helper for conversion operations on TypedArrays, the expected values
235 * properties are indexed in order to match the respective value for each
236 * TypedArray constructor
237 * @param {Function} fn - the function to call for each constructor and value.
238 * will be called with the constructor, value, expected
239 * value, and a initial value that can be used to avoid
240 * a false positive with an equivalent expected value.
242 function testTypedArrayConversions(byteConversionValues, fn) {
243 var values = byteConversionValues.values;
244 var expected = byteConversionValues.expected;
246 testWithTypedArrayConstructors(function(TA) {
247 var name = TA.name.slice(0, -5);
249 return values.forEach(function(value, index) {
250 var exp = expected[name][index];
255 fn(TA, value, exp, initial);
261 * Checks if the given argument is one of the float-based TypedArray constructors.
263 * @param {constructor} ctor - the value to check
266 function isFloatTypedArrayConstructor(arg) {
267 return floatArrayConstructors.indexOf(arg) !== -1;
271 * Determines the precision of the given float-based TypedArray constructor.
273 * @param {constructor} ctor - the value to check
274 * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively.
276 function floatTypedArrayConstructorPrecision(FA) {
277 if (typeof Float16Array !== "undefined" && FA === Float16Array) {
279 } else if (FA === Float32Array) {
281 } else if (FA === Float64Array) {
284 throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray");