michael@0: // Test that SavedFrame.prototype.toString only shows frames whose principal is michael@0: // subsumed by the caller's principal. michael@0: michael@0: var count = 0; michael@0: michael@0: // Given a string of letters |expected|, say "abc", assert that the stack michael@0: // contains calls to a series of functions named by the next letter from michael@0: // the string, say a, b, and then c. Younger frames appear earlier in michael@0: // |expected| than older frames. michael@0: function check(expected, stack) { michael@0: print("check(" + uneval(expected) + ") against:\n" + stack); michael@0: count++; michael@0: michael@0: // Extract only the function names from the stack trace. Omit the frames michael@0: // for the top-level evaluation, if it is present. michael@0: const frames = stack michael@0: .split("\n") michael@0: .filter(f => f.match(/^.@/)) michael@0: .map(f => f.replace(/@.*$/g, "")); michael@0: michael@0: // Check the function names against the expected sequence. michael@0: assertEq(frames.length, expected.length); michael@0: for (var i = 0; i < expected.length; i++) { michael@0: assertEq(frames[i], expected[i]); michael@0: } michael@0: } michael@0: michael@0: var low = newGlobal({ principal: 0 }); michael@0: var mid = newGlobal({ principal: 0xffff }); michael@0: var high = newGlobal({ principal: 0xfffff }); michael@0: michael@0: eval('function a() { check("a", saveStack().toString()); b(); }'); michael@0: low .eval('function b() { check("b", saveStack().toString()); c(); }'); michael@0: mid .eval('function c() { check("cba", saveStack().toString()); d(); }'); michael@0: high.eval('function d() { check("dcba", saveStack().toString()); e(); }'); michael@0: eval('function e() { check("edcba", saveStack().toString()); f(); }'); // no principal, so checks skipped michael@0: low .eval('function f() { check("fb", saveStack().toString()); g(); }'); michael@0: mid .eval('function g() { check("gfecba", saveStack().toString()); h(); }'); michael@0: high.eval('function h() { check("hgfedcba", saveStack().toString()); }'); michael@0: michael@0: // Make everyone's functions visible to each other, as needed. michael@0: b = low .b; michael@0: low .c = mid .c; michael@0: mid .d = high.d; michael@0: high.e = e; michael@0: f = low .f; michael@0: low .g = mid .g; michael@0: mid .h = high.h; michael@0: michael@0: low.check = mid.check = high.check = check; michael@0: michael@0: // Kick the whole process off. michael@0: a(); michael@0: michael@0: assertEq(count, 8); michael@0: