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.

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

mercurial