| 1 |
// Test that SavedFrame.prototype.toString only shows frames whose principal is |
| 2 |
// subsumed by the caller's principal. |
| 3 |
|
| 4 |
var count = 0; |
| 5 |
|
| 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(" + JSON.stringify(expected) + ") against:\n" + stack); |
| 12 |
count++; |
| 13 |
|
| 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, "")); |
| 20 |
|
| 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 |
} |
| 27 |
|
| 28 |
var low = newGlobal({ principal: 0 }); |
| 29 |
var mid = newGlobal({ principal: 0xffff }); |
| 30 |
var high = newGlobal({ principal: 0xfffff }); |
| 31 |
|
| 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("ecba", saveStack().toString()); f(); }'); |
| 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()); }'); |
| 40 |
|
| 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; |
| 49 |
|
| 50 |
low.check = mid.check = high.check = check; |
| 51 |
|
| 52 |
// Kick the whole process off. |
| 53 |
a(); |
| 54 |
|
| 55 |
assertEq(count, 8); |
| 56 |
|