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.

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

mercurial