shell.js (8566B)
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. 5 /*--- 6 description: | 7 Collection of functions used to assert the correctness of SharedArrayBuffer objects. 8 defines: 9 - testWithAtomicsOutOfBoundsIndices 10 - testWithAtomicsInBoundsIndices 11 - testWithAtomicsNonViewValues 12 ---*/ 13 14 15 /** 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. 19 * 20 * @param f - the function to call for each bad index. 21 */ 22 function testWithAtomicsOutOfBoundsIndices(f) { 23 var bad_indices = [ 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 31 ]; 32 33 for (var i = 0; i < bad_indices.length; ++i) { 34 var IdxGen = bad_indices[i]; 35 try { 36 f(IdxGen); 37 } catch (e) { 38 e.message += ' (Testing with index gen ' + IdxGen + '.)'; 39 throw e; 40 } 41 } 42 } 43 44 /** 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. 47 * 48 * The view must have length greater than zero. 49 * 50 * @param f - the function to call for each good index. 51 */ 52 function testWithAtomicsInBoundsIndices(f) { 53 // Most of these are eventually coerced to +0 by ToIndex. 54 var good_indices = [ 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 66 ]; 67 68 for (var i = 0; i < good_indices.length; ++i) { 69 var IdxGen = good_indices[i]; 70 try { 71 f(IdxGen); 72 } catch (e) { 73 e.message += ' (Testing with index gen ' + IdxGen + '.)'; 74 throw e; 75 } 76 } 77 } 78 79 /** 80 * Calls the provided function for each value that should throw a TypeError 81 * when passed to an Atomics method as a view. 82 * 83 * @param f - the function to call for each non-view value. 84 */ 85 86 function testWithAtomicsNonViewValues(f) { 87 var values = [ 88 null, 89 undefined, 90 true, 91 false, 92 new Boolean(true), 93 10, 94 3.14, 95 new Number(4), 96 'Hi there', 97 new Date, 98 /a*utomaton/g, 99 { password: 'qumquat' }, 100 new DataView(new ArrayBuffer(10)), 101 new ArrayBuffer(128), 102 new SharedArrayBuffer(128), 103 new Error('Ouch'), 104 [1,1,2,3,5,8], 105 function(x) { return -x; }, 106 Symbol('halleluja'), 107 // TODO: Proxy? 108 Object, 109 Int32Array, 110 Date, 111 Math, 112 Atomics 113 ]; 114 115 for (var i = 0; i < values.length; ++i) { 116 var nonView = values[i]; 117 try { 118 f(nonView); 119 } catch (e) { 120 e.message += ' (Testing with non-view value ' + nonView + '.)'; 121 throw e; 122 } 123 } 124 } 125 126 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. 130 /*--- 131 description: | 132 Collection of functions used to assert the correctness of TypedArray objects. 133 defines: 134 - floatArrayConstructors 135 - nonClampedIntArrayConstructors 136 - intArrayConstructors 137 - typedArrayConstructors 138 - TypedArray 139 - testWithTypedArrayConstructors 140 - nonAtomicsFriendlyTypedArrayConstructors 141 - testWithAtomicsFriendlyTypedArrayConstructors 142 - testWithNonAtomicsFriendlyTypedArrayConstructors 143 - testTypedArrayConversions 144 ---*/ 145 146 var floatArrayConstructors = [ 147 Float64Array, 148 Float32Array 149 ]; 150 151 var nonClampedIntArrayConstructors = [ 152 Int32Array, 153 Int16Array, 154 Int8Array, 155 Uint32Array, 156 Uint16Array, 157 Uint8Array 158 ]; 159 160 var intArrayConstructors = nonClampedIntArrayConstructors.concat([Uint8ClampedArray]); 161 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); 166 } 167 168 /** 169 * Array containing every non-bigint typed array constructor. 170 */ 171 172 var typedArrayConstructors = floatArrayConstructors.concat(intArrayConstructors); 173 174 /** 175 * The %TypedArray% intrinsic constructor function. 176 */ 177 var TypedArray = Object.getPrototypeOf(Int8Array); 178 179 /** 180 * Callback for testing a typed array constructor. 181 * 182 * @callback typedArrayConstructorCallback 183 * @param {Function} Constructor the constructor object to test with. 184 */ 185 186 /** 187 * Calls the provided function for every typed array constructor. 188 * 189 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. 190 * @param {Array} selected - An optional Array with filtered typed arrays 191 */ 192 function testWithTypedArrayConstructors(f, selected) { 193 var constructors = selected || typedArrayConstructors; 194 for (var i = 0; i < constructors.length; ++i) { 195 var constructor = constructors[i]; 196 try { 197 f(constructor); 198 } catch (e) { 199 e.message += " (Testing with " + constructor.name + ".)"; 200 throw e; 201 } 202 } 203 } 204 205 var nonAtomicsFriendlyTypedArrayConstructors = floatArrayConstructors.concat([Uint8ClampedArray]); 206 /** 207 * Calls the provided function for every non-"Atomics Friendly" typed array constructor. 208 * 209 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. 210 * @param {Array} selected - An optional Array with filtered typed arrays 211 */ 212 function testWithNonAtomicsFriendlyTypedArrayConstructors(f) { 213 testWithTypedArrayConstructors(f, nonAtomicsFriendlyTypedArrayConstructors); 214 } 215 216 /** 217 * Calls the provided function for every "Atomics Friendly" typed array constructor. 218 * 219 * @param {typedArrayConstructorCallback} f - the function to call for each typed array constructor. 220 * @param {Array} selected - An optional Array with filtered typed arrays 221 */ 222 function testWithAtomicsFriendlyTypedArrayConstructors(f) { 223 testWithTypedArrayConstructors(f, [ 224 Int32Array, 225 Int16Array, 226 Int8Array, 227 Uint32Array, 228 Uint16Array, 229 Uint8Array, 230 ]); 231 } 232 233 /** 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. 241 */ 242 function testTypedArrayConversions(byteConversionValues, fn) { 243 var values = byteConversionValues.values; 244 var expected = byteConversionValues.expected; 245 246 testWithTypedArrayConstructors(function(TA) { 247 var name = TA.name.slice(0, -5); 248 249 return values.forEach(function(value, index) { 250 var exp = expected[name][index]; 251 var initial = 0; 252 if (exp === 0) { 253 initial = 1; 254 } 255 fn(TA, value, exp, initial); 256 }); 257 }); 258 } 259 260 /** 261 * Checks if the given argument is one of the float-based TypedArray constructors. 262 * 263 * @param {constructor} ctor - the value to check 264 * @returns {boolean} 265 */ 266 function isFloatTypedArrayConstructor(arg) { 267 return floatArrayConstructors.indexOf(arg) !== -1; 268 } 269 270 /** 271 * Determines the precision of the given float-based TypedArray constructor. 272 * 273 * @param {constructor} ctor - the value to check 274 * @returns {string} "half", "single", or "double" for Float16Array, Float32Array, and Float64Array respectively. 275 */ 276 function floatTypedArrayConstructorPrecision(FA) { 277 if (typeof Float16Array !== "undefined" && FA === Float16Array) { 278 return "half"; 279 } else if (FA === Float32Array) { 280 return "single"; 281 } else if (FA === Float64Array) { 282 return "double"; 283 } else { 284 throw new Error("Malformed test - floatTypedArrayConstructorPrecision called with non-float TypedArray"); 285 } 286 }