js/src/jit-test/tests/debug/Script-staticLevel.js

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 // Debugger.Script.prototype.staticLevel returns the script's static level.
     2 load(libdir + 'asserts.js');
     4 var g = newGlobal();
     5 var dbg = Debugger();
     6 var gw = dbg.addDebuggee(g);
     8 function test(expr, level) {
     9     var log;
    10     dbg.onDebuggerStatement = function (frame) {
    11         log += 'd';
    12         assertEq(frame.script.staticLevel, level);
    13     };
    15     print("Testing: " + expr);
    17     log = '';
    18     // The shell's 'evaluate' runs its argument as global code.
    19     g.evaluate(expr);
    20     assertEq(log, 'd');
    21 }
    24 test("debugger;", 0);
    25 test("(function () { debugger; })()", 1);
    26 test("(function () { (function () { debugger; })(); })()", 2);
    27 test("(function () { (function () { (function () { debugger; })(); })(); })()", 3);
    29 test("eval('debugger;');", 1);
    30 test("eval('eval(\\\'debugger;\\\');');", 2);
    31 test("evil = eval; eval('evil(\\\'debugger;\\\');');", 0); // I don't think it's evil at all!
    32 test("(function () { eval('debugger;'); })();", 2);
    33 test("evil = eval; (function () { evil('debugger;'); })();", 0);
    35 // Generators' expressions are within a synthesized function's body.
    36 test("((function () { debugger; })() for (x in [1])).next();", 2);
    37 test("(x for (x in ((function () { debugger; })(), [1]))).next();", 2);
    39 // The staticLevel accessor can't be assigned to.
    40 g.eval('function f() {}');
    41 var fw = gw.makeDebuggeeValue(g.f);
    42 assertThrowsInstanceOf(function () { "use strict"; fw.script.staticLevel = 10; },
    43                        TypeError);

mercurial