js/src/tests/js1_8_5/extensions/findReferences-01.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 // Any copyright is dedicated to the Public Domain.
michael@0 2 // http://creativecommons.org/licenses/publicdomain/
michael@0 3 // Contributor: Jim Blandy
michael@0 4
michael@0 5 if (typeof findReferences == "function") {
michael@0 6 function C() {}
michael@0 7 var o = new C;
michael@0 8 o.x = {}; // via ordinary property
michael@0 9 o[42] = {}; // via numeric property
michael@0 10 o[123456789] = {}; // via ridiculous numeric property
michael@0 11 o.myself = o; // self-references should be reported
michael@0 12 o.alsoMyself = o; // multiple self-references should all be reported
michael@0 13
michael@0 14 assertEq(referencesVia(o, 'type; type_proto', C.prototype), true);
michael@0 15 assertEq(referencesVia(o, 'shape; base; parent', this), true);
michael@0 16 assertEq(referencesVia(o, 'x', o.x), true);
michael@0 17 assertEq(referencesVia(o, 'objectElements[42]', o[42]), true);
michael@0 18 assertEq(referencesVia(o, '123456789', o[123456789]), true);
michael@0 19 assertEq(referencesVia(o, 'myself', o), true);
michael@0 20 assertEq(referencesVia(o, 'alsoMyself', o), true);
michael@0 21
michael@0 22 function g() { return 42; }
michael@0 23 function s(v) { }
michael@0 24 var p = Object.defineProperty({}, 'a', { get:g, set:s });
michael@0 25 assertEq(referencesVia(p, 'shape; base; getter', g), true);
michael@0 26 assertEq(referencesVia(p, 'shape; base; setter', s), true);
michael@0 27
michael@0 28 // If there are multiple objects with the same shape referring to a getter
michael@0 29 // or setter, findReferences should get all of them, even though the shape
michael@0 30 // gets 'marked' the first time we visit it.
michael@0 31 var q = Object.defineProperty({}, 'a', { get:g, set:s });
michael@0 32 assertEq(referencesVia(p, 'shape; base; getter', g), true);
michael@0 33 assertEq(referencesVia(q, 'shape; base; getter', g), true);
michael@0 34
michael@0 35 // If we extend each object's shape chain, both should still be able to
michael@0 36 // reach the getter, even though the two shapes are each traversed twice.
michael@0 37 p.b = 9;
michael@0 38 q.b = 9;
michael@0 39 assertEq(referencesVia(p, 'shape; parent; base; getter', g), true);
michael@0 40 assertEq(referencesVia(q, 'shape; parent; base; getter', g), true);
michael@0 41
michael@0 42 // These are really just ordinary own property references.
michael@0 43 assertEq(referencesVia(C, 'prototype', Object.getPrototypeOf(o)), true);
michael@0 44 assertEq(referencesVia(Object.getPrototypeOf(o), 'constructor', C), true);
michael@0 45
michael@0 46 // Dense arrays should work, too.
michael@0 47 a = [];
michael@0 48 a[1] = o;
michael@0 49 assertEq(referencesVia(a, 'objectElements[1]', o), true);
michael@0 50
michael@0 51 reportCompare(true, true);
michael@0 52 } else {
michael@0 53 reportCompare(true, true, "test skipped: findReferences is not a function");
michael@0 54 }

mercurial