js/src/tests/js1_8_5/extensions/clone-forge.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 // -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
michael@0 3 // Any copyright is dedicated to the Public Domain.
michael@0 4 // http://creativecommons.org/licenses/publicdomain/
michael@0 5
michael@0 6 function assertThrows(f) {
michael@0 7 var ok = false;
michael@0 8 try {
michael@0 9 f();
michael@0 10 } catch (exc) {
michael@0 11 ok = true;
michael@0 12 }
michael@0 13 if (!ok)
michael@0 14 throw new TypeError("Assertion failed: " + f + " did not throw as expected");
michael@0 15 }
michael@0 16
michael@0 17 function byteArray(str) {
michael@0 18 return [ c.charCodeAt(0) for (c of str.split('')) ];
michael@0 19 }
michael@0 20
michael@0 21 // Don't allow forging bogus Date objects.
michael@0 22 var mutated = byteArray(serialize(new Date(NaN)).clonebuffer);
michael@0 23
michael@0 24 var a = [1/0, -1/0,
michael@0 25 Number.MIN_VALUE, -Number.MIN_VALUE,
michael@0 26 Math.PI, 1286523948674.5,
michael@0 27 Number.MAX_VALUE, -Number.MAX_VALUE,
michael@0 28 8.64e15 + 1, -(8.64e15 + 1)];
michael@0 29 for (var i = 0; i < a.length; i++) {
michael@0 30 var n = a[i];
michael@0 31 var nbuf = serialize(n);
michael@0 32 var data = byteArray(nbuf.clonebuffer);
michael@0 33 for (var j = 0; j < 8; j++)
michael@0 34 mutated[j+8] = data[j];
michael@0 35 nbuf.clonebuffer = String.fromCharCode.apply(null, mutated);
michael@0 36 assertThrows(function () { deserialize(nbuf); });
michael@0 37 }
michael@0 38
michael@0 39 reportCompare(0, 0);

mercurial