diff options
Diffstat (limited to 'js/src/jit-test/tests/symbol/typed-arrays.js')
-rw-r--r-- | js/src/jit-test/tests/symbol/typed-arrays.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/symbol/typed-arrays.js b/js/src/jit-test/tests/symbol/typed-arrays.js new file mode 100644 index 000000000..005eec09a --- /dev/null +++ b/js/src/jit-test/tests/symbol/typed-arrays.js @@ -0,0 +1,29 @@ +load(libdir + "asserts.js"); + +var LENGTH = 1024, SYMBOL_INDEX = 999; + +var big = []; +for (var i = 0; i < LENGTH; i++) + big[i] = (i === SYMBOL_INDEX ? Symbol.for("comet") : i); + +var progress; +function copy(arr, big) { + for (var i = 0; i < LENGTH; i++) { + arr[i] = big[i]; + progress = i; + } +} + +for (var T of [Uint8Array, Uint8ClampedArray, Int16Array, Float32Array]) { + // Typed array constructors convert symbols using ToNumber, which throws. + assertThrowsInstanceOf(() => new T(big), TypeError); + + // Element assignment does the same. + var arr = new T(big.length); + for (var k = 0; k < 3; k++) { + progress = -1; + assertThrowsInstanceOf(() => copy(arr, big), TypeError); + assertEq(progress, SYMBOL_INDEX - 1); + assertEq(arr[SYMBOL_INDEX], 0); + } +} |