js/src/jit-test/tests/basic/shell-principals.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 // Test the JS shell's toy principals.
     3 var count = 0;
     5 // Given a string of letters |expected|, say "abc", assert that the stack
     6 // contains calls to a series of functions named by the next letter from
     7 // the string, say a, b, and then c. Younger frames appear earlier in
     8 // |expected| than older frames.
     9 function check(expected, stack) {
    10   print("check(" + uneval(expected) + ") against:\n" + stack);
    11   count++;
    13   // Extract only the function names from the stack trace. Omit the frames
    14   // for the top-level evaluation, if it is present.
    15   var split = stack.split(/(.)?@.*\n/).slice(0, -1);
    16   if (split[split.length - 1] === undefined)
    17     split = split.slice(0, -2);
    19   // Check the function names against the expected sequence.
    20   assertEq(split.length, expected.length * 2);
    21   for (var i = 0; i < expected.length; i++)
    22     assertEq(split[i * 2 + 1], expected[i]);
    23 }
    25 var low = newGlobal({ principal: 0 });
    26 var mid = newGlobal({ principal: 0xffff });
    27 var high = newGlobal({ principal: 0xfffff });
    29      eval('function a() { check("a",        Error().stack); b(); }');
    30 low .eval('function b() { check("b",        Error().stack); c(); }');
    31 mid .eval('function c() { check("cba",      Error().stack); d(); }');
    32 high.eval('function d() { check("dcba",     Error().stack); e(); }');
    33      eval('function e() { check("edcba",    Error().stack); f(); }'); // no principal, so checks skipped
    34 low .eval('function f() { check("fb",       Error().stack); g(); }');
    35 mid .eval('function g() { check("gfecba",   Error().stack); h(); }');
    36 high.eval('function h() { check("hgfedcba", Error().stack);      }');
    38 // Make everyone's functions visible to each other, as needed.
    39      b = low .b;
    40 low .c = mid .c;
    41 mid .d = high.d;
    42 high.e =      e;
    43      f = low .f;
    44 low .g = mid .g;
    45 mid .h = high.h;
    47 low.check = mid.check = high.check = check;
    49 // Kick the whole process off.
    50 a();
    52 assertEq(count, 8);

mercurial