michael@0: // |reftest| skip-if(!xulRuntime.shell) michael@0: // Any copyright is dedicated to the Public Domain. michael@0: // http://creativecommons.org/licenses/publicdomain/ michael@0: michael@0: function test() { michael@0: // Note: -8 and -200 will trigger asm.js link failures because 8 and 200 michael@0: // bytes are below the minimum allowed size, and the buffer will not michael@0: // actually be converted to an asm.js buffer. michael@0: for (var size of [0, 8, 16, 200, 1000, 4096, -8, -200, -8192, -65536]) { michael@0: var buffer_ctor = (size < 0) ? AsmJSArrayBuffer : ArrayBuffer; michael@0: size = Math.abs(size); michael@0: michael@0: var old = new buffer_ctor(size); michael@0: var copy = deserialize(serialize(old, [old])); michael@0: assertEq(old.byteLength, 0); michael@0: assertEq(copy.byteLength, size); michael@0: michael@0: var constructors = [ Int8Array, michael@0: Uint8Array, michael@0: Int16Array, michael@0: Uint16Array, michael@0: Int32Array, michael@0: Uint32Array, michael@0: Float32Array, michael@0: Float64Array, michael@0: Uint8ClampedArray ]; michael@0: michael@0: for (var ctor of constructors) { michael@0: var buf = new buffer_ctor(size); michael@0: var old_arr = new ctor(buf); michael@0: assertEq(buf.byteLength, size); michael@0: assertEq(buf, old_arr.buffer); michael@0: assertEq(old_arr.length, size / old_arr.BYTES_PER_ELEMENT); michael@0: michael@0: var copy_arr = deserialize(serialize(old_arr, [ buf ])); michael@0: assertEq(buf.byteLength, 0, "donor array buffer should be neutered"); michael@0: assertEq(old_arr.length, 0, "donor typed array should be neutered"); michael@0: assertEq(copy_arr.buffer.byteLength == size, true); michael@0: assertEq(copy_arr.length, size / old_arr.BYTES_PER_ELEMENT); michael@0: michael@0: buf = null; michael@0: old_arr = null; michael@0: gc(); // Tickle the ArrayBuffer -> view management michael@0: } michael@0: michael@0: for (var ctor of constructors) { michael@0: var buf = new buffer_ctor(size); michael@0: var old_arr = new ctor(buf); michael@0: var dv = new DataView(buf); // Second view michael@0: var copy_arr = deserialize(serialize(old_arr, [ buf ])); michael@0: assertEq(buf.byteLength, 0, "donor array buffer should be neutered"); michael@0: assertEq(old_arr.length, 0, "donor typed array should be neutered"); michael@0: assertEq(dv.byteLength, 0, "all views of donor array buffer should be neutered"); michael@0: michael@0: buf = null; michael@0: old_arr = null; michael@0: gc(); // Tickle the ArrayBuffer -> view management michael@0: } michael@0: michael@0: // Mutate the buffer during the clone operation. The modifications should be visible. michael@0: if (size >= 4) { michael@0: old = new buffer_ctor(size); michael@0: var view = new Int32Array(old); michael@0: view[0] = 1; michael@0: var mutator = { get foo() { view[0] = 2; } }; michael@0: var copy = deserialize(serialize([ old, mutator ], [old])); michael@0: var viewCopy = new Int32Array(copy[0]); michael@0: assertEq(view.length, 0); // Neutered michael@0: assertEq(viewCopy[0], 2); michael@0: } michael@0: michael@0: // Neuter the buffer during the clone operation. Should throw an exception. michael@0: if (size >= 4) { michael@0: old = new buffer_ctor(size); michael@0: var mutator = { michael@0: get foo() { michael@0: deserialize(serialize(old, [old])); michael@0: } michael@0: }; michael@0: // The throw is not yet implemented, bug 919259. michael@0: //var copy = deserialize(serialize([ old, mutator ], [old])); michael@0: } michael@0: } michael@0: } michael@0: michael@0: test(); michael@0: reportCompare(0, 0, 'ok');