Bug 980962. Fix in-tree consumers to not construct typed arrays without "new". r=jorendorff

This commit is contained in:
Boris Zbarsky 2014-03-20 23:19:42 -04:00
parent 1eb065e532
commit 009cf4dd56
48 changed files with 125 additions and 125 deletions

View File

@ -44,7 +44,7 @@ function Buffer(subject, encoding /*, bufferLength */) {
case 'number':
// Create typed array of the given size if number.
try {
let buffer = Uint8Array(subject > 0 ? Math.floor(subject) : 0);
let buffer = new Uint8Array(subject > 0 ? Math.floor(subject) : 0);
return buffer;
} catch (e) {
if (/size and count too large/.test(e.message) ||
@ -58,19 +58,19 @@ function Buffer(subject, encoding /*, bufferLength */) {
// If string encode it and use buffer for the returned Uint8Array
// to create a local patched version that acts like node buffer.
encoding = encoding || 'utf8';
return Uint8Array(new TextEncoder(encoding).encode(subject).buffer);
return new Uint8Array(new TextEncoder(encoding).encode(subject).buffer);
case 'object':
// This form of the constructor uses the form of
// Uint8Array(buffer, offset, length);
// new Uint8Array(buffer, offset, length);
// So we can instantiate a typed array within the constructor
// to inherit the appropriate properties, where both the
// `subject` and newly instantiated buffer share the same underlying
// data structure.
if (arguments.length === 3)
return Uint8Array(subject, encoding, arguments[2]);
return new Uint8Array(subject, encoding, arguments[2]);
// If array or alike just make a copy with a local patched prototype.
else
return Uint8Array(subject);
return new Uint8Array(subject);
default:
throw new TypeError('must start with number, buffer, array or string');
}
@ -146,7 +146,7 @@ Object.defineProperties(Buffer.prototype, {
get: function () {
let view = views.get(this, undefined);
if (view) return view;
view = DataView(this.buffer);
view = new DataView(this.buffer);
views.set(this, view);
return view;
}
@ -229,7 +229,7 @@ Object.defineProperties(Buffer.prototype, {
if (end < start)
end = start;
// This instantiation uses the Uint8Array(buffer, offset, length) version
// This instantiation uses the new Uint8Array(buffer, offset, length) version
// of construction to share the same underling data structure
let buffer = new Buffer(this.buffer, start, end - start);

View File

@ -304,7 +304,7 @@ MainPreferencesPropertyList.prototype = {
binaryStream.setInputStream(inputStream);
let bytes = binaryStream.readByteArray(inputStream.available());
this._dict = PropertyListUtils._readFromArrayBufferSync(
Uint8Array(bytes).buffer);
new Uint8Array(bytes).buffer);
return this._dict;
}
};

View File

@ -62,7 +62,7 @@ void main(void) {
function isScreenBlack() {
var pixels = gl.drawingBufferWidth * gl.drawingBufferHeight;
var data = Uint8Array(4 * pixels);
var data = new Uint8Array(4 * pixels);
gl.readPixels(0, 0,
gl.drawingBufferWidth, gl.drawingBufferHeight,
gl.RGBA, gl.UNSIGNED_BYTE,
@ -98,11 +98,11 @@ void main(void) {
var indexType = gl.UNSIGNED_SHORT;
var indexStride = 2;
var indexArr = Uint16Array([0, 1, Math.min(hugeIndex, UINT16_MAX)]);
var indexArr = new Uint16Array([0, 1, Math.min(hugeIndex, UINT16_MAX)]);
if (gl.getExtension('OES_element_index_uint')) {
indexType = gl.UNSIGNED_INT;
indexStride = 4;
indexArr = Uint32Array([0, 1, hugeIndex]);
indexArr = new Uint32Array([0, 1, hugeIndex]);
}
gl.clear(gl.COLOR_BUFFER_BIT);

View File

@ -57,8 +57,8 @@ o16[i] = Math.sin(i * 7);
}
return o15;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(Float32Array(7), Float32Array(127), Float32Array(7)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(Float32Array(15), Float32Array(127), Float32Array(7)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(new Float32Array(7), new Float32Array(127), new Float32Array(7)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(new Float32Array(15), new Float32Array(127), new Float32Array(7)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o17 = document.createElement('audio'); } catch(e) { Logger.error(Logger.comment(e)); }
try { (document.body || document.documentElement).appendChild(o0); } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o18 = o1.createBuffer(1, 7, 91261);
@ -68,7 +68,7 @@ o19[i] = Math.sin(i * 7);
}
return o18;
}(); } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(Float32Array(31), Float32Array(31), Float32Array(127)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.getFrequencyResponse(new Float32Array(31), new Float32Array(31), new Float32Array(127)) } catch(e) { Logger.error(Logger.comment(e)); }
try { o20 = o1.createChannelSplitter(1, 2, 4, 16, 32); } catch(e) { Logger.error(Logger.comment(e)); }
try { o12.channelCountMode = 'explicit'; } catch(e) { Logger.error(Logger.comment(e)); }
try { o3.buffer = function() { o21 = o1.createBuffer(1, 0, 14451);

View File

@ -2,11 +2,11 @@
try { o1 = new AudioContext(); } catch(e) { }
try { o6 = o1.createGain(); } catch(e) { }
try { o8 = o1.createBufferSource(); } catch(e) { }
try { o6.gain.setValueCurveAtTime(Float32Array(7), 0, 0) } catch(e) { }
try { o6.gain.setValueCurveAtTime(new Float32Array(7), 0, 0) } catch(e) { }
try { o8.connect(o6, 0, 0) } catch(e) { }
try { o8.buffer = function() {
o19 = o1.createBuffer(1, 1, 76309);
for(var i=0; i<1; ++i) { }
return o19;
}(); } catch(e) { }
</script>
</script>

View File

@ -21,10 +21,10 @@ try { o7.channelInterpretation = 'speakers'; } catch(e) { }
try { o1.destination.channelInterpretation = 'speakers'; } catch(e) { }
try { o5.connect(o1.destination, 1, 1) } catch(e) { }
try { o1.listener.setOrientation(0, 1073741824, 1073741824, 4194304, 1, 0) } catch(e) { }
try { o4.curve = Float32Array(127); } catch(e) { }
try { o6.getByteFrequencyData(Uint8Array(12)) } catch(e) { }
try { o4.curve = new Float32Array(127); } catch(e) { }
try { o6.getByteFrequencyData(new Uint8Array(12)) } catch(e) { }
try { o6.disconnect() } catch(e) { }
try { o1.destination.channelCount = 33554432; } catch(e) { }
try { o7.playbackRate.setTargetAtTime(0, 8388608, 1) } catch(e) { }
try { o6.getByteTimeDomainData(Uint8Array(12)) } catch(e) { }
</script>
try { o6.getByteTimeDomainData(new Uint8Array(12)) } catch(e) { }
</script>

View File

@ -51,7 +51,7 @@ function runTests() {
is(written, samples1.length, "Not all samples in JS Array written.");
// Test writing with Float32Array
var samples2 = Float32Array([.2, .3, .2, .3]);
var samples2 = new Float32Array([.2, .3, .2, .3]);
written = a1.mozWriteAudio(samples2);
is(written, samples2.length, "Not all samples in Float32Array written.");

View File

@ -150,7 +150,7 @@ try { o9.connect(o4); } catch(e) { }
try { o1.listener.speedOfSound = 1; } catch(e) { }
try { o15.disconnect() } catch(e) { }
try { o11.gain.exponentialRampToValueAtTime(0, 15) } catch(e) { }
try { o15.curve = Float32Array(15); } catch(e) { }
try { o15.curve = new Float32Array(15); } catch(e) { }
try { o4.listener.setVelocity(1, 1, 1) } catch(e) { }
try { o14.connect(o6, 0, 0) } catch(e) { }
try { o2.connect(o9); } catch(e) { }
@ -193,7 +193,7 @@ try { o9.disconnect() } catch(e) { }
try { o4.listener.speedOfSound = 1; } catch(e) { }
try { o2.connect(o7); } catch(e) { }
try { o7.connect(o4); } catch(e) { }
try { o11.gain.setValueCurveAtTime(Float32Array(3), 2048, 3) } catch(e) { }
try { o11.gain.setValueCurveAtTime(new Float32Array(3), 2048, 3) } catch(e) { }
try { o13.gain.value = 8; } catch(e) { }
try { o2.connect(o7); } catch(e) { }
try { o9.connect(o4); } catch(e) { }

View File

@ -8,7 +8,7 @@ Function("\
return f\
})(this, {\
ff: arguments.callee\
}, ArrayBuffer(4096))\
}, new ArrayBuffer(4096))\
")()
function m(f) {
for (var j = 0; j < 6000; ++j) {

View File

@ -1,5 +1,5 @@
// Binary: cache/js-dbg-32-82ff7c27fcb0-linux
// Flags:
//
var x = Int32Array();
var x = new Int32Array();
x.set(x);

View File

@ -5,5 +5,5 @@
//
function v(s) { eval(s); }
v("eval(function(){})()");
var x = Int32Array(0);
var x = new Int32Array(0);
v("x.set()");

View File

@ -5,7 +5,7 @@
//
try {
(function () {
__proto__ = Uint32Array()
__proto__ = new Uint32Array()
}())
} catch (e) {}(function () {
})()

View File

@ -8,7 +8,7 @@ try {
var _ = q;
} catch (e) { }
try {
v = ArrayBuffer();
v = new ArrayBuffer();
s = [];
function e() { }
let a;

View File

@ -3,9 +3,9 @@
// Binary: cache/js-dbg-32-0428dbdf3d58-linux
// Flags:
//
o1 = Float32Array().buffer
o1 = new Float32Array().buffer
o2 = ArrayBuffer.prototype
o3 = Uint32Array().buffer
o3 = new Uint32Array().buffer
for (i = 0; i < 2; i++) {
for (var x in o2) {
o3.__defineGetter__("", function() {})

View File

@ -2,9 +2,9 @@
// Flags:
//
try {
a = ArrayBuffer(76);
b = Uint32Array(a);
a = new ArrayBuffer(76);
b = new Uint32Array(a);
uneval()
c = Uint8Array(a);
c = new Uint8Array(a);
c.set(b)
} catch (e) {}

View File

@ -1,4 +1,4 @@
var x = Uint32Array();
var x = new Uint32Array();
for (var i = 0; i < 100; i++)
x[77] = x[77];

View File

@ -1,4 +1,4 @@
gczeal(2);
for (var loopa2 = 0; loopa2 < 13; loopa2++) {
[, , , , , , ][Float64Array()] = 72413.8139177333;
[, , , , , , ][new Float64Array()] = 72413.8139177333;
}

View File

@ -30,8 +30,8 @@ M4x4.scale3 = function M4x4_scale3(x, y, z, m) {
m[11] *= z;
};
M4x4.makeLookAt = function M4x4_makeLookAt() {
tm1 = Float32Array(16);
tm2 = Float32Array(16);
tm1 = new Float32Array(16);
tm2 = new Float32Array(16);
r = new Float32Array(16)
return M4x4.mul(tm1, tm2, r);
};

View File

@ -1,7 +1,7 @@
try {
(function() {
var m
ArrayBuffer()
new ArrayBuffer()
var _ = t
var _2 = []
}())

View File

@ -15,7 +15,7 @@ assertEqArray([,,...[1, 2, 3],,,,], [,,1,2,3,,,,]);
assertEqArray([...[undefined]], [undefined]);
// other iterable objects
assertEqArray([...Int32Array([1, 2, 3])], [1, 2, 3]);
assertEqArray([...new Int32Array([1, 2, 3])], [1, 2, 3]);
assertEqArray([..."abc"], ["a", "b", "c"]);
assertEqArray([...[1, 2, 3][std_iterator]()], [1, 2, 3]);
assertEqArray([...Set([1, 2, 3])], [1, 2, 3]);

View File

@ -19,7 +19,7 @@ function checkLength(f, makeFn) {
assertEq(makeFn("...[undefined]")(f), 1);
// other iterable objects
assertEq(makeFn("...arg")(f, Int32Array([1, 2, 3])), 3);
assertEq(makeFn("...arg")(f, new Int32Array([1, 2, 3])), 3);
assertEq(makeFn("...arg")(f, "abc"), 3);
assertEq(makeFn("...arg")(f, [1, 2, 3][std_iterator]()), 3);
assertEq(makeFn("...arg")(f, Set([1, 2, 3])), 3);

View File

@ -14,7 +14,7 @@ function checkCommon(f, makeFn) {
assertEqArray(makeFn("1, ...[], 2, 3")(f), [1, 2, 3]);
// other iterable objects
assertEqArray(makeFn("...arg")(f, Int32Array([1, 2, 3])), [1, 2, 3]);
assertEqArray(makeFn("...arg")(f, new Int32Array([1, 2, 3])), [1, 2, 3]);
assertEqArray(makeFn("...arg")(f, "abc"), ["a", "b", "c"]);
assertEqArray(makeFn("...arg")(f, [1, 2, 3][std_iterator]()), [1, 2, 3]);
assertEqArray(makeFn("...arg")(f, Set([1, 2, 3])), [1, 2, 3]);

View File

@ -1,4 +1,4 @@
var arr = Float32Array(1);
var arr = new Float32Array(1);
arr[0] = 15;
var a = arr[0];
assertEq(a, 15);

View File

@ -1,4 +1,4 @@
JSON.__proto__[1] = Uint8ClampedArray().buffer
JSON.__proto__[1] = new Uint8ClampedArray().buffer
f = (function() {
function g(c) {
Object.freeze(c).__proto__ = c

View File

@ -2,9 +2,9 @@ function f(x, y) {
for (var i = 0; i < 100; i++)
assertEq(x[0], y);
}
var a = ArrayBuffer(20);
var b = Int32Array(a, 12, 2);
var c = Int32Array(a, 0, 2);
var a = new ArrayBuffer(20);
var b = new Int32Array(a, 12, 2);
var c = new Int32Array(a, 0, 2);
b[0] = 10;
f(b, 10);
c[0] = 20;

View File

@ -4,4 +4,4 @@
load(libdir + "asserts.js");
Uint8Array.of = Array.of;
assertDeepEq(Uint8Array.of(0x12, 0x34, 0x5678, 0x9abcdef), Uint8Array([0x12, 0x34, 0x78, 0xef]));
assertDeepEq(new Uint8Array.of(0x12, 0x34, 0x5678, 0x9abcdef), new Uint8Array([0x12, 0x34, 0x78, 0xef]));

View File

@ -1,6 +1,6 @@
// for-of can iterate over typed arrays.
var a = Int8Array([0, 1, -7, 3])
var a = new Int8Array([0, 1, -7, 3])
var s = '';
for (var v of a)
s += v + ',';

View File

@ -1,11 +1,11 @@
// The body of a for-of loop does not run if the target is an empty typed array.
for (x of Int16Array(0))
for (x of new Int16Array(0))
throw "FAIL";
for (x of Float32Array(0))
for (x of new Float32Array(0))
throw "FAIL";
var a = Int8Array([0, 1, 2, 3]).subarray(2, 2);
var a = new Int8Array([0, 1, 2, 3]).subarray(2, 2);
assertEq(a.length, 0);
for (v of a)
throw "FAIL";

View File

@ -1,4 +1,4 @@
// Destructuring does not occur when the target of for-of is an empty typed array.
for (var [[x]] of Int32Array(0))
for (var [[x]] of new Int32Array(0))
throw "FAIL";

View File

@ -2,6 +2,6 @@
load(libdir + "asserts.js");
assertThrowsInstanceOf(function () {
for (var v of Int8Array([0, 1, 2, 3]).buffer)
for (var v of new Int8Array([0, 1, 2, 3]).buffer)
throw "FAIL";
}, TypeError);

View File

@ -1,6 +1,6 @@
x = newGlobal()
Int32Array = x.Int32Array
x.p = ArrayBuffer()
x.p = new ArrayBuffer()
schedulegc(29);
(function(stdlib, n, heap) {
"use asm"
@ -11,4 +11,4 @@ schedulegc(29);
return f
})(this, {
f: new Function
}, ArrayBuffer())
}, new ArrayBuffer())

View File

@ -1,7 +1,7 @@
// |jit-test| error: InternalError: too much recursion
for (let y in []);
(function f(x) {
Float64Array(ArrayBuffer());
new Float64Array(new ArrayBuffer());
{
f(x)
function t() {}

View File

@ -14,7 +14,7 @@ Object.create(a2);
e: true,
e: RegExp(""),
get: function() {
return Uint32Array(this.a2)
return new Uint32Array(this.a2)
}
})
})()

View File

@ -1,4 +1,4 @@
y = Float32Array(11);
y = new Float32Array(11);
x = [];
Object.defineProperty(x, 18, {

View File

@ -1,7 +1,7 @@
x = {};
x.toString = (function(stdlib, heap) {
Int8ArrayView = stdlib.Int8Array(heap);
Float32ArrayView = stdlib.Float32Array(heap);
Int8ArrayView = new stdlib.Int8Array(heap);
Float32ArrayView = new stdlib.Float32Array(heap);
function f() {
Int8ArrayView[0] = Float32ArrayView[0]
}

View File

@ -1,6 +1,6 @@
var e = new Error();
function test() {
var arr = Float32Array(1);
var arr = new Float32Array(1);
for (var Number in e) {}
var a = arr [0];
switch (a) {}

View File

@ -1,6 +1,6 @@
x = {};
y = x;
x.toString = function() {
Int8Array(ArrayBuffer)[0] = Float32Array(ArrayBuffer)[0];
new Int8Array(ArrayBuffer)[0] = new Float32Array(ArrayBuffer)[0];
}
print(x << y);

View File

@ -3,7 +3,7 @@
//
(function(){
var g = {};
x = Float32Array()
x = new Float32Array()
Function('g', "g.o = x[1]")(g);
})();
//
@ -33,9 +33,9 @@
//
(function() {
x = y = {};
z = Float32Array(6)
z = new Float32Array(6)
for (c in this) {
Array.prototype.unshift.call(x, ArrayBuffer())
Array.prototype.unshift.call(x, new ArrayBuffer())
}
Array.prototype.sort.call(x, (function (j) {
y.s = z[2]

View File

@ -1,4 +1,4 @@
assertEq(-(!Int32Array(5)), -0);
assertEq(-(!new Int32Array(5)), -0);
assertEq(-(!Math), -0);
assertEq(-(!{}), -0);
assertEq(-(![]), -0);

View File

@ -1,4 +1,4 @@
var ab = ArrayBuffer(5);
var ab = new ArrayBuffer(5);
var p = new Proxy(ab, {});
var ps = Object.getOwnPropertyDescriptor(Object.prototype, "__proto__").set;
var threw = 0;

View File

@ -10,7 +10,7 @@ function test() {
var buffer_ctor = (size < 0) ? AsmJSArrayBuffer : ArrayBuffer;
size = Math.abs(size);
var old = buffer_ctor(size);
var old = new buffer_ctor(size);
var copy = deserialize(serialize(old, [old]));
assertEq(old.byteLength, 0);
assertEq(copy.byteLength, size);
@ -26,8 +26,8 @@ function test() {
Uint8ClampedArray ];
for (var ctor of constructors) {
var buf = buffer_ctor(size);
var old_arr = ctor(buf);
var buf = new buffer_ctor(size);
var old_arr = new ctor(buf);
assertEq(buf.byteLength, size);
assertEq(buf, old_arr.buffer);
assertEq(old_arr.length, size / old_arr.BYTES_PER_ELEMENT);
@ -44,9 +44,9 @@ function test() {
}
for (var ctor of constructors) {
var buf = buffer_ctor(size);
var old_arr = ctor(buf);
var dv = DataView(buf); // Second view
var buf = new buffer_ctor(size);
var old_arr = new ctor(buf);
var dv = new DataView(buf); // Second view
var copy_arr = deserialize(serialize(old_arr, [ buf ]));
assertEq(buf.byteLength, 0, "donor array buffer should be neutered");
assertEq(old_arr.length, 0, "donor typed array should be neutered");
@ -59,19 +59,19 @@ function test() {
// Mutate the buffer during the clone operation. The modifications should be visible.
if (size >= 4) {
old = buffer_ctor(size);
var view = Int32Array(old);
old = new buffer_ctor(size);
var view = new Int32Array(old);
view[0] = 1;
var mutator = { get foo() { view[0] = 2; } };
var copy = deserialize(serialize([ old, mutator ], [old]));
var viewCopy = Int32Array(copy[0]);
var viewCopy = new Int32Array(copy[0]);
assertEq(view.length, 0); // Neutered
assertEq(viewCopy[0], 2);
}
// Neuter the buffer during the clone operation. Should throw an exception.
if (size >= 4) {
old = buffer_ctor(size);
old = new buffer_ctor(size);
var mutator = {
get foo() {
deserialize(serialize(old, [old]));

View File

@ -27,8 +27,8 @@ function checkPrototype(ctor) {
function test() {
// Test cloning ArrayBuffer objects.
check(ArrayBuffer(0));
check(ArrayBuffer(7));
check(new ArrayBuffer(0));
check(new ArrayBuffer(7));
checkPrototype(ArrayBuffer);
// Test cloning typed array objects.
@ -48,11 +48,11 @@ function test() {
var ctor = ctors[i];
// check empty array
b = ctor(0);
b = new ctor(0);
check(b);
// check array with some elements
b = ctor(100);
b = new ctor(100);
var v = 1;
for (var j = 0; j < 100; j++) {
b[j] = v;
@ -69,15 +69,15 @@ function test() {
// TypedArrays still sharing a buffer. This also tests cloning TypedArrays
// where the arr->data pointer is not 8-byte-aligned.
var base = Int8Array([0, 1, 2, 3]);
b = [Int8Array(base.buffer, 0, 3), Int8Array(base.buffer, 1, 3)];
var base = new Int8Array([0, 1, 2, 3]);
b = [new Int8Array(base.buffer, 0, 3), new Int8Array(base.buffer, 1, 3)];
var a = deserialize(serialize(b));
base[1] = -1;
a[0][2] = -2;
assertArraysEqual(b[0], Int8Array([0, -1, 2])); // shared with base
assertArraysEqual(b[1], Int8Array([-1, 2, 3])); // shared with base
assertArraysEqual(a[0], Int8Array([0, 1, -2])); // not shared with base
assertArraysEqual(a[1], Int8Array([1, -2, 3])); // not shared with base, shared with a[0]
assertArraysEqual(b[0], new Int8Array([0, -1, 2])); // shared with base
assertArraysEqual(b[1], new Int8Array([-1, 2, 3])); // shared with base
assertArraysEqual(a[0], new Int8Array([0, 1, -2])); // not shared with base
assertArraysEqual(a[1], new Int8Array([1, -2, 3])); // not shared with base, shared with a[0]
assertEq(b[0].buffer, b[1].buffer);
assertEq(b[1].byteOffset, 1);
@ -86,8 +86,8 @@ function test() {
// ArrayBuffer clones do not preserve properties
base = Int8Array([0, 1, 2, 3]);
b = [Int8Array(base.buffer, 0, 3), Int8Array(base.buffer, 1, 3)];
base = new Int8Array([0, 1, 2, 3]);
b = [new Int8Array(base.buffer, 0, 3), new Int8Array(base.buffer, 1, 3)];
base.buffer.prop = "yes";
base.buffer.loop = b[0];
base.buffer.loops = [ b[0], b[1] ];

View File

@ -60,8 +60,8 @@ function checkPrototype(ctor) {
function test() {
// Test cloning ArrayBuffer objects.
check(ArrayBuffer(0));
check(ArrayBuffer(7));
check(new ArrayBuffer(0));
check(new ArrayBuffer(7));
checkPrototype(ArrayBuffer);
// Test cloning typed array objects.
@ -81,11 +81,11 @@ function test() {
var ctor = ctors[i];
// check empty array
b = ctor(0);
b = new ctor(0);
check(b);
// check array with some elements
b = ctor(100);
b = new ctor(100);
var v = 1;
for (var j = 0; j < 100; j++) {
b[j] = v;
@ -102,15 +102,15 @@ function test() {
// ArrayBuffer. This also tests cloning TypedArrays where the arr->data
// pointer is not 8-byte-aligned.
var base = Int8Array([0, 1, 2, 3]);
b = [Int8Array(base.buffer, 0, 3), Int8Array(base.buffer, 1, 3)];
var base = new Int8Array([0, 1, 2, 3]);
b = [new Int8Array(base.buffer, 0, 3), new Int8Array(base.buffer, 1, 3)];
var a = deserialize(serialize(b));
base[1] = -1;
a[0][2] = -2;
assertArraysEqual(b[0], Int8Array([0, -1, 2])); // shared with base
assertArraysEqual(b[1], Int8Array([-1, 2, 3])); // shared with base
assertArraysEqual(a[0], Int8Array([0, 1, -2])); // not shared with base
assertArraysEqual(a[1], Int8Array([1, 2, 3])); // not shared with base or a[0]
assertArraysEqual(b[0], new Int8Array([0, -1, 2])); // shared with base
assertArraysEqual(b[1], new Int8Array([-1, 2, 3])); // shared with base
assertArraysEqual(a[0], new Int8Array([0, 1, -2])); // not shared with base
assertArraysEqual(a[1], new Int8Array([1, 2, 3])); // not shared with base or a[0]
}
test();

View File

@ -1558,12 +1558,12 @@ function test() {
assertEq(view.getUint8(0), 1);
// Test WebIDL-specific class and prototype class names
assertEq(Object.prototype.toString.apply(Uint8Array(0)), "[object Uint8Array]");
assertEq(Object.prototype.toString.apply(Float32Array(0)), "[object Float32Array]");
assertEq(Object.prototype.toString.apply(new Uint8Array(0)), "[object Uint8Array]");
assertEq(Object.prototype.toString.apply(new Float32Array(0)), "[object Float32Array]");
assertEq(Object.prototype.toString.apply(Uint8Array.prototype), "[object Uint8ArrayPrototype]");
assertEq(Object.prototype.toString.apply(Float32Array.prototype), "[object Float32ArrayPrototype]");
assertEq(Object.prototype.toString.apply(ArrayBuffer()), "[object ArrayBuffer]");
assertEq(Object.prototype.toString.apply(DataView(view.buffer)), "[object DataView]");
assertEq(Object.prototype.toString.apply(new ArrayBuffer()), "[object ArrayBuffer]");
assertEq(Object.prototype.toString.apply(new DataView(view.buffer)), "[object DataView]");
assertEq(Object.prototype.toString.apply(DataView.prototype), "[object DataViewPrototype]");
// Accessing DataView fields on DataView.prototype should crash

View File

@ -143,10 +143,10 @@ function test()
// Buffer with multiple views, kill all possible subsets of views
buffer = new ArrayBuffer(128);
for (let order = 0; order < 16; order++) {
var views = [ Uint8Array(buffer),
Uint8Array(buffer),
Uint8Array(buffer),
Uint8Array(buffer) ];
var views = [ new Uint8Array(buffer),
new Uint8Array(buffer),
new Uint8Array(buffer),
new Uint8Array(buffer) ];
gc();
// Kill views according to the bits set in 'order'
@ -164,10 +164,10 @@ function test()
// Similar: multiple views, kill them one at a time in every possible order
buffer = new ArrayBuffer(128);
for (let order = 0; order < 4*3*2*1; order++) {
var views = [ Uint8Array(buffer),
Uint8Array(buffer),
Uint8Array(buffer),
Uint8Array(buffer) ];
var views = [ new Uint8Array(buffer),
new Uint8Array(buffer),
new Uint8Array(buffer),
new Uint8Array(buffer) ];
gc();
var sequence = [ 0, 1, 2, 3 ];
@ -191,7 +191,7 @@ function test()
for (let numViews of [ 1, 2, 0, 3, 2, 1 ]) {
buffer = new ArrayBuffer(128);
for (let viewNum = 0; viewNum < numViews; viewNum++) {
views.push(Int8Array(buffer));
views.push(new Int8Array(buffer));
}
}

View File

@ -180,10 +180,10 @@ function test_component(contractid) {
[makeB(), makeB(), makeB()], 3, Ci['nsIXPCTestInterfaceB']);
// Test incorrect (too big) array size parameter; this should throw NOT_ENOUGH_ELEMENTS.
doTypedArrayMismatchTest("testShortArray", Int16Array([-3, 7, 4]), 4,
Int16Array([1, -32, 6]), 3);
doTypedArrayMismatchTest("testShortArray", new Int16Array([-3, 7, 4]), 4,
new Int16Array([1, -32, 6]), 3);
// Test type mismatch (int16 <-> uint16); this should throw BAD_CONVERT_JS.
doTypedArrayMismatchTest("testShortArray", Uint16Array([0, 7, 4, 3]), 4,
Uint16Array([1, 5, 6]), 3);
doTypedArrayMismatchTest("testShortArray", new Uint16Array([0, 7, 4, 3]), 4,
new Uint16Array([1, 5, 6]), 3);
}

View File

@ -138,7 +138,7 @@ this.PropertyListUtils = Object.freeze({
// Convert the buffer into an XML tree.
let domParser = Cc["@mozilla.org/xmlextras/domparser;1"].
createInstance(Ci.nsIDOMParser);
let bytesView = Uint8Array(aBuffer);
let bytesView = new Uint8Array(aBuffer);
try {
let doc = domParser.parseFromBuffer(bytesView, bytesView.length,
"application/xml");
@ -261,7 +261,7 @@ BinaryPropertyListReader.prototype = {
* It can be called on the prototype.
*/
canProcess: function BPLR_canProcess(aBuffer)
[String.fromCharCode(c) for each (c in Uint8Array(aBuffer, 0, 8))].
[String.fromCharCode(c) for each (c in new Uint8Array(aBuffer, 0, 8))].
join("") == "bplist00",
get root() this._readObject(this._rootObjectIndex),
@ -311,9 +311,9 @@ BinaryPropertyListReader.prototype = {
_readReal: function BPLR__readReal(aByteOffset, aRealSize) {
let swapped = this._swapForBigEndian(aByteOffset, aRealSize, 1);
if (aRealSize == 4)
return Float32Array(swapped.buffer, 0, 1)[0];
return new Float32Array(swapped.buffer, 0, 1)[0];
if (aRealSize == 8)
return Float64Array(swapped.buffer, 0, 1)[0];
return new Float64Array(swapped.buffer, 0, 1)[0];
throw new Error("Unsupported real size: " + aRealSize);
},
@ -415,7 +415,7 @@ BinaryPropertyListReader.prototype = {
_readUnsignedInts:
function BPLR__readUnsignedInts(aByteOffset, aIntSize, aLength, aBigIntAllowed) {
if (aIntSize == 1)
return Uint8Array(this._buffer, aByteOffset, aLength);
return new Uint8Array(this._buffer, aByteOffset, aLength);
// There are two reasons for the complexity you see here:
// (1) 64-bit integers - For which we use ctypes. When possible, the
@ -424,9 +424,9 @@ BinaryPropertyListReader.prototype = {
// bytes, is not yet implemented (bug 575688).
let swapped = this._swapForBigEndian(aByteOffset, aIntSize, aLength);
if (aIntSize == 2)
return Uint16Array(swapped.buffer);
return new Uint16Array(swapped.buffer);
if (aIntSize == 4)
return Uint32Array(swapped.buffer);
return new Uint32Array(swapped.buffer);
if (aIntSize == 8) {
let intsArray = [];
let lo_hi_view = new Uint32Array(swapped.buffer);
@ -695,7 +695,7 @@ XMLPropertyListReader.prototype = {
// Strip spaces and new lines.
let base64str = aDOMElt.textContent.replace(/\s*/g, "");
let decoded = atob(base64str);
return Uint8Array([decoded.charCodeAt(i) for (i in decoded)]);
return new Uint8Array([decoded.charCodeAt(i) for (i in decoded)]);
case "dict":
return this._wrapDictionary(aDOMElt);
case "array":

View File

@ -52,7 +52,7 @@ function saveStreamAsync(aPath, aStream, aFile) {
createInstance(Ci.nsIBinaryInputStream);
source.setInputStream(input);
let data = Uint8Array(EXTRACTION_BUFFER);
let data = new Uint8Array(EXTRACTION_BUFFER);
function readFailed(error) {
try {