diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/basic/shell-principals.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/basic/shell-principals.js')
-rw-r--r-- | js/src/jit-test/tests/basic/shell-principals.js | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/shell-principals.js b/js/src/jit-test/tests/basic/shell-principals.js new file mode 100644 index 000000000..a96ce69c7 --- /dev/null +++ b/js/src/jit-test/tests/basic/shell-principals.js @@ -0,0 +1,55 @@ +// Test the JS shell's toy principals. + +var count = 0; + +// Given a string of letters |expected|, say "abc", assert that the stack +// contains calls to a series of functions named by the next letter from +// the string, say a, b, and then c. Younger frames appear earlier in +// |expected| than older frames. +function check(expected, stack) { + print("check(" + uneval(expected) + ") against:\n" + stack); + count++; + + // Extract only the function names from the stack trace. Omit the frames + // for the top-level evaluation, if it is present. + var split = stack.split(/(.)?@.*\n/).slice(0, -1); + if (split[split.length - 1] === undefined) + split = split.slice(0, -2); + + // Check the function names against the expected sequence. + assertEq(split.length, expected.length * 2); + for (var i = 0; i < expected.length; i++) + assertEq(split[i * 2 + 1], expected[i]); +} + +var low = newGlobal({ principal: 0 }); +var mid = newGlobal({ principal: 0xffff }); +var high = newGlobal({ principal: 0xfffff }); + + eval('function a() { check("a", Error().stack); b(); }'); +low .eval('function b() { check("b", Error().stack); c(); }'); +mid .eval('function c() { check("cba", Error().stack); d(); }'); +high.eval('function d() { check("dcba", Error().stack); e(); }'); + +// Globals created with no explicit principals get 0xffff. + eval('function e() { check("ecba", Error().stack); f(); }'); + +low .eval('function f() { check("fb", Error().stack); g(); }'); +mid .eval('function g() { check("gfecba", Error().stack); h(); }'); +high.eval('function h() { check("hgfedcba", Error().stack); }'); + +// Make everyone's functions visible to each other, as needed. + b = low .b; +low .c = mid .c; +mid .d = high.d; +high.e = e; + f = low .f; +low .g = mid .g; +mid .h = high.h; + +low.check = mid.check = high.check = check; + +// Kick the whole process off. +a(); + +assertEq(count, 8); |