js/src/jit-test/tests/saved-stacks/principals-02.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 // Test that SavedFrame.prototype.toString only shows frames whose principal is
michael@0 2 // subsumed by the caller's principal.
michael@0 3
michael@0 4 var count = 0;
michael@0 5
michael@0 6 // Given a string of letters |expected|, say "abc", assert that the stack
michael@0 7 // contains calls to a series of functions named by the next letter from
michael@0 8 // the string, say a, b, and then c. Younger frames appear earlier in
michael@0 9 // |expected| than older frames.
michael@0 10 function check(expected, stack) {
michael@0 11 print("check(" + uneval(expected) + ") against:\n" + stack);
michael@0 12 count++;
michael@0 13
michael@0 14 // Extract only the function names from the stack trace. Omit the frames
michael@0 15 // for the top-level evaluation, if it is present.
michael@0 16 const frames = stack
michael@0 17 .split("\n")
michael@0 18 .filter(f => f.match(/^.@/))
michael@0 19 .map(f => f.replace(/@.*$/g, ""));
michael@0 20
michael@0 21 // Check the function names against the expected sequence.
michael@0 22 assertEq(frames.length, expected.length);
michael@0 23 for (var i = 0; i < expected.length; i++) {
michael@0 24 assertEq(frames[i], expected[i]);
michael@0 25 }
michael@0 26 }
michael@0 27
michael@0 28 var low = newGlobal({ principal: 0 });
michael@0 29 var mid = newGlobal({ principal: 0xffff });
michael@0 30 var high = newGlobal({ principal: 0xfffff });
michael@0 31
michael@0 32 eval('function a() { check("a", saveStack().toString()); b(); }');
michael@0 33 low .eval('function b() { check("b", saveStack().toString()); c(); }');
michael@0 34 mid .eval('function c() { check("cba", saveStack().toString()); d(); }');
michael@0 35 high.eval('function d() { check("dcba", saveStack().toString()); e(); }');
michael@0 36 eval('function e() { check("edcba", saveStack().toString()); f(); }'); // no principal, so checks skipped
michael@0 37 low .eval('function f() { check("fb", saveStack().toString()); g(); }');
michael@0 38 mid .eval('function g() { check("gfecba", saveStack().toString()); h(); }');
michael@0 39 high.eval('function h() { check("hgfedcba", saveStack().toString()); }');
michael@0 40
michael@0 41 // Make everyone's functions visible to each other, as needed.
michael@0 42 b = low .b;
michael@0 43 low .c = mid .c;
michael@0 44 mid .d = high.d;
michael@0 45 high.e = e;
michael@0 46 f = low .f;
michael@0 47 low .g = mid .g;
michael@0 48 mid .h = high.h;
michael@0 49
michael@0 50 low.check = mid.check = high.check = check;
michael@0 51
michael@0 52 // Kick the whole process off.
michael@0 53 a();
michael@0 54
michael@0 55 assertEq(count, 8);
michael@0 56

mercurial