js/src/jit-test/tests/debug/onNewScript-01.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 // Basic newScript hook tests.
michael@0 2
michael@0 3 var g = newGlobal();
michael@0 4 var dbg = Debugger(g);
michael@0 5 var seen = WeakMap();
michael@0 6 var hits = 0;
michael@0 7 dbg.onNewScript = function (s) {
michael@0 8 // Exceptions thrown from onNewScript are swept under the rug, but they
michael@0 9 // will at least prevent hits from being the expected number.
michael@0 10 assertEq(s instanceof Debugger.Script, true);
michael@0 11 assertEq(!seen.has(s), true);
michael@0 12 seen.set(s, true);
michael@0 13 hits++;
michael@0 14 };
michael@0 15
michael@0 16 dbg.uncaughtExceptionHook = function () { hits = -999; };
michael@0 17
michael@0 18 // eval code
michael@0 19 hits = 0;
michael@0 20 assertEq(g.eval("2 + 2"), 4);
michael@0 21 assertEq(hits, 1);
michael@0 22
michael@0 23 hits = 0;
michael@0 24 assertEq(g.eval("eval('2 + 3')"), 5);
michael@0 25 assertEq(hits, 2);
michael@0 26
michael@0 27 // global code
michael@0 28 hits = 0;
michael@0 29 g.evaluate("3 + 4");
michael@0 30 assertEq(hits, 1);
michael@0 31
michael@0 32 // function code
michael@0 33 hits = 0;
michael@0 34 var fn = g.Function("a", "return 5 + a;");
michael@0 35 assertEq(hits, 1);
michael@0 36 assertEq(fn(8), 13);
michael@0 37 assertEq(hits, 1);
michael@0 38
michael@0 39 // cloning functions across compartments
michael@0 40 fn = g.evaluate("(function(a) { return 5 + a; })", {compileAndGo: false});
michael@0 41 var g2 = newGlobal();
michael@0 42 dbg.addDebuggee(g2, dbg);
michael@0 43 hits = 0;
michael@0 44 g2.clone(fn);
michael@0 45 assertEq(hits, 1);

mercurial