diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/tests/js1_8_5/extensions/clone-transferables.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/tests/js1_8_5/extensions/clone-transferables.js')
-rw-r--r-- | js/src/tests/js1_8_5/extensions/clone-transferables.js | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/js/src/tests/js1_8_5/extensions/clone-transferables.js b/js/src/tests/js1_8_5/extensions/clone-transferables.js new file mode 100644 index 000000000..673684b95 --- /dev/null +++ b/js/src/tests/js1_8_5/extensions/clone-transferables.js @@ -0,0 +1,112 @@ +// |reftest| skip-if(!xulRuntime.shell) +// Any copyright is dedicated to the Public Domain. +// http://creativecommons.org/licenses/publicdomain/ + +function* buffer_options() { + for (var scope of ["SameProcessSameThread", "SameProcessDifferentThread", "DifferentProcess"]) { + for (var size of [0, 8, 16, 200, 1000, 4096, 8192, 65536]) { + yield { scope, size }; + } + } +} + + +function test() { + for (var {scope, size} of buffer_options()) { + var old = new ArrayBuffer(size); + var copy = deserialize(serialize([old, old], [old], { scope }), { scope }); + assertEq(old.byteLength, 0); + assertEq(copy[0] === copy[1], true); + copy = copy[0]; + assertEq(copy.byteLength, size); + + var constructors = [ Int8Array, + Uint8Array, + Int16Array, + Uint16Array, + Int32Array, + Uint32Array, + Float32Array, + Float64Array, + Uint8ClampedArray, + DataView ]; + + for (var ctor of constructors) { + var dataview = (ctor === DataView); + + var buf = new ArrayBuffer(size); + var old_arr = new ctor(buf); + assertEq(buf.byteLength, size); + assertEq(buf, old_arr.buffer); + if (!dataview) + assertEq(old_arr.length, size / old_arr.BYTES_PER_ELEMENT); + + var copy_arr = deserialize(serialize(old_arr, [ buf ], { scope }), { scope }); + assertEq(buf.byteLength, 0, + "donor array buffer should be detached"); + if (!dataview) { + assertEq(old_arr.length, 0, + "donor typed array should be detached"); + } + assertEq(copy_arr.buffer.byteLength == size, true); + if (!dataview) + assertEq(copy_arr.length, size / old_arr.BYTES_PER_ELEMENT); + + buf = null; + old_arr = null; + gc(); // Tickle the ArrayBuffer -> view management + } + + for (var ctor of constructors) { + var dataview = (ctor === DataView); + + var buf = new ArrayBuffer(size); + var old_arr = new ctor(buf); + var dv = new DataView(buf); // Second view + var copy_arr = deserialize(serialize(old_arr, [ buf ], { scope }), { scope }); + assertEq(buf.byteLength, 0, + "donor array buffer should be detached"); + assertEq(old_arr.byteLength, 0, + "donor typed array should be detached"); + if (!dataview) { + assertEq(old_arr.length, 0, + "donor typed array should be detached"); + } + assertEq(dv.byteLength, 0, + "all views of donor array buffer should have zero " + + "length because their underlying buffer is detached"); + + buf = null; + old_arr = null; + gc(); // Tickle the ArrayBuffer -> view management + } + + // Mutate the buffer during the clone operation. The modifications should be visible. + if (size >= 4) { + old = new ArrayBuffer(size); + var view = new Int32Array(old); + view[0] = 1; + var mutator = { get foo() { view[0] = 2; } }; + var copy = deserialize(serialize([ old, mutator ], [ old ], { scope }), { scope }); + var viewCopy = new Int32Array(copy[0]); + assertEq(view.length, 0); // Underlying buffer now detached. + assertEq(viewCopy[0], 2); + } + + // Detach the buffer during the clone operation. Should throw an + // exception. + if (size >= 4) { + old = new ArrayBuffer(size); + var mutator = { + get foo() { + deserialize(serialize(old, [old], { scope }), { scope }); + } + }; + // The throw is not yet implemented, bug 919259. + //var copy = deserialize(serialize([ old, mutator ], [old])); + } + } +} + +test(); +reportCompare(0, 0, 'ok'); |