michael@0: // Based on tests/ion/typed-arrays-1.js, but with string indexes michael@0: function testInt8() { michael@0: var arr1 = new Int8Array(50); michael@0: var arr2 = new Uint8Array(50); michael@0: var arr3 = new Uint8ClampedArray(50); michael@0: michael@0: for (var i=0; i 290888255, true); michael@0: assertEq(arr1["74".concat("")] < 290888257, true); michael@0: michael@0: assertEq(arr2["74".concat("")] > 290888184, true); michael@0: assertEq(arr2["74".concat("")] < 290888185, true); michael@0: } michael@0: testFloat(); michael@0: michael@0: function testCanonicalNaN() { michael@0: // NaN values have to be canonicalized. Otherwise, malicious scripts could michael@0: // construct arbitrary Value's (due to our NaN boxing Value representation). michael@0: var buf = new ArrayBuffer(16); michael@0: var uint32 = new Uint32Array(buf); michael@0: var f64 = new Float64Array(buf); michael@0: var f32 = new Float32Array(buf); michael@0: michael@0: // Evil: write a JSVAL_TYPE_OBJECT type tag... michael@0: uint32[0] = 0xffffff87; michael@0: uint32[1] = 0xffffff87; michael@0: michael@0: // Make sure this value is interpreted as a double. michael@0: for (var i=0; i<3; i++) { michael@0: assertEq(isNaN(f64["0".concat("")]), true); michael@0: assertEq(isNaN(f32["0".concat("")]), true); michael@0: } michael@0: } michael@0: testCanonicalNaN(); michael@0: michael@0: function testOutOfBounds() { michael@0: var buf = new ArrayBuffer(16); michael@0: var uint32 = new Uint32Array(buf); michael@0: michael@0: uint32[0] = 0; michael@0: uint32[1] = 1; michael@0: michael@0: for (var i=0; i<3; i++) { michael@0: assertEq(uint32["0".concat("")], 0); michael@0: assertEq(uint32["1".concat("")], 1); michael@0: assertEq(uint32["2".concat("")], 0); michael@0: assertEq(uint32["17".concat("")], undefined); michael@0: } michael@0: } michael@0: testOutOfBounds(); michael@0: michael@0: function testStrangeIndexes() { michael@0: var buf = new ArrayBuffer(16); michael@0: var uint32 = new Uint32Array(buf); michael@0: michael@0: uint32[0] = 0; michael@0: uint32[1] = 1; michael@0: michael@0: indexes = ["0", "1", "2", "3", "17", "3.5", "NaN", "undefined", "null"]; michael@0: solutions = [0, 1, 0, 0, undefined, undefined, undefined, undefined, undefined]; michael@0: michael@0: for (var i=0; i