js/src/jit-test/tests/saved-stacks/principals-02.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/saved-stacks/principals-02.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,56 @@
     1.4 +// Test that SavedFrame.prototype.toString only shows frames whose principal is
     1.5 +// subsumed by the caller's principal.
     1.6 +
     1.7 +var count = 0;
     1.8 +
     1.9 +// Given a string of letters |expected|, say "abc", assert that the stack
    1.10 +// contains calls to a series of functions named by the next letter from
    1.11 +// the string, say a, b, and then c. Younger frames appear earlier in
    1.12 +// |expected| than older frames.
    1.13 +function check(expected, stack) {
    1.14 +  print("check(" + uneval(expected) + ") against:\n" + stack);
    1.15 +  count++;
    1.16 +
    1.17 +  // Extract only the function names from the stack trace. Omit the frames
    1.18 +  // for the top-level evaluation, if it is present.
    1.19 +  const frames = stack
    1.20 +    .split("\n")
    1.21 +    .filter(f => f.match(/^.@/))
    1.22 +    .map(f => f.replace(/@.*$/g, ""));
    1.23 +
    1.24 +  // Check the function names against the expected sequence.
    1.25 +  assertEq(frames.length, expected.length);
    1.26 +  for (var i = 0; i < expected.length; i++) {
    1.27 +    assertEq(frames[i], expected[i]);
    1.28 +  }
    1.29 +}
    1.30 +
    1.31 +var low = newGlobal({ principal: 0 });
    1.32 +var mid = newGlobal({ principal: 0xffff });
    1.33 +var high = newGlobal({ principal: 0xfffff });
    1.34 +
    1.35 +     eval('function a() { check("a",        saveStack().toString()); b(); }');
    1.36 +low .eval('function b() { check("b",        saveStack().toString()); c(); }');
    1.37 +mid .eval('function c() { check("cba",      saveStack().toString()); d(); }');
    1.38 +high.eval('function d() { check("dcba",     saveStack().toString()); e(); }');
    1.39 +     eval('function e() { check("edcba",    saveStack().toString()); f(); }'); // no principal, so checks skipped
    1.40 +low .eval('function f() { check("fb",       saveStack().toString()); g(); }');
    1.41 +mid .eval('function g() { check("gfecba",   saveStack().toString()); h(); }');
    1.42 +high.eval('function h() { check("hgfedcba", saveStack().toString());      }');
    1.43 +
    1.44 +// Make everyone's functions visible to each other, as needed.
    1.45 +     b = low .b;
    1.46 +low .c = mid .c;
    1.47 +mid .d = high.d;
    1.48 +high.e =      e;
    1.49 +     f = low .f;
    1.50 +low .g = mid .g;
    1.51 +mid .h = high.h;
    1.52 +
    1.53 +low.check = mid.check = high.check = check;
    1.54 +
    1.55 +// Kick the whole process off.
    1.56 +a();
    1.57 +
    1.58 +assertEq(count, 8);
    1.59 +

mercurial