js/src/tests/js1_8_5/extensions/clone-transferables.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 // |reftest| skip-if(!xulRuntime.shell)
michael@0 2 // Any copyright is dedicated to the Public Domain.
michael@0 3 // http://creativecommons.org/licenses/publicdomain/
michael@0 4
michael@0 5 function test() {
michael@0 6 // Note: -8 and -200 will trigger asm.js link failures because 8 and 200
michael@0 7 // bytes are below the minimum allowed size, and the buffer will not
michael@0 8 // actually be converted to an asm.js buffer.
michael@0 9 for (var size of [0, 8, 16, 200, 1000, 4096, -8, -200, -8192, -65536]) {
michael@0 10 var buffer_ctor = (size < 0) ? AsmJSArrayBuffer : ArrayBuffer;
michael@0 11 size = Math.abs(size);
michael@0 12
michael@0 13 var old = new buffer_ctor(size);
michael@0 14 var copy = deserialize(serialize(old, [old]));
michael@0 15 assertEq(old.byteLength, 0);
michael@0 16 assertEq(copy.byteLength, size);
michael@0 17
michael@0 18 var constructors = [ Int8Array,
michael@0 19 Uint8Array,
michael@0 20 Int16Array,
michael@0 21 Uint16Array,
michael@0 22 Int32Array,
michael@0 23 Uint32Array,
michael@0 24 Float32Array,
michael@0 25 Float64Array,
michael@0 26 Uint8ClampedArray ];
michael@0 27
michael@0 28 for (var ctor of constructors) {
michael@0 29 var buf = new buffer_ctor(size);
michael@0 30 var old_arr = new ctor(buf);
michael@0 31 assertEq(buf.byteLength, size);
michael@0 32 assertEq(buf, old_arr.buffer);
michael@0 33 assertEq(old_arr.length, size / old_arr.BYTES_PER_ELEMENT);
michael@0 34
michael@0 35 var copy_arr = deserialize(serialize(old_arr, [ buf ]));
michael@0 36 assertEq(buf.byteLength, 0, "donor array buffer should be neutered");
michael@0 37 assertEq(old_arr.length, 0, "donor typed array should be neutered");
michael@0 38 assertEq(copy_arr.buffer.byteLength == size, true);
michael@0 39 assertEq(copy_arr.length, size / old_arr.BYTES_PER_ELEMENT);
michael@0 40
michael@0 41 buf = null;
michael@0 42 old_arr = null;
michael@0 43 gc(); // Tickle the ArrayBuffer -> view management
michael@0 44 }
michael@0 45
michael@0 46 for (var ctor of constructors) {
michael@0 47 var buf = new buffer_ctor(size);
michael@0 48 var old_arr = new ctor(buf);
michael@0 49 var dv = new DataView(buf); // Second view
michael@0 50 var copy_arr = deserialize(serialize(old_arr, [ buf ]));
michael@0 51 assertEq(buf.byteLength, 0, "donor array buffer should be neutered");
michael@0 52 assertEq(old_arr.length, 0, "donor typed array should be neutered");
michael@0 53 assertEq(dv.byteLength, 0, "all views of donor array buffer should be neutered");
michael@0 54
michael@0 55 buf = null;
michael@0 56 old_arr = null;
michael@0 57 gc(); // Tickle the ArrayBuffer -> view management
michael@0 58 }
michael@0 59
michael@0 60 // Mutate the buffer during the clone operation. The modifications should be visible.
michael@0 61 if (size >= 4) {
michael@0 62 old = new buffer_ctor(size);
michael@0 63 var view = new Int32Array(old);
michael@0 64 view[0] = 1;
michael@0 65 var mutator = { get foo() { view[0] = 2; } };
michael@0 66 var copy = deserialize(serialize([ old, mutator ], [old]));
michael@0 67 var viewCopy = new Int32Array(copy[0]);
michael@0 68 assertEq(view.length, 0); // Neutered
michael@0 69 assertEq(viewCopy[0], 2);
michael@0 70 }
michael@0 71
michael@0 72 // Neuter the buffer during the clone operation. Should throw an exception.
michael@0 73 if (size >= 4) {
michael@0 74 old = new buffer_ctor(size);
michael@0 75 var mutator = {
michael@0 76 get foo() {
michael@0 77 deserialize(serialize(old, [old]));
michael@0 78 }
michael@0 79 };
michael@0 80 // The throw is not yet implemented, bug 919259.
michael@0 81 //var copy = deserialize(serialize([ old, mutator ], [old]));
michael@0 82 }
michael@0 83 }
michael@0 84 }
michael@0 85
michael@0 86 test();
michael@0 87 reportCompare(0, 0, 'ok');

mercurial