js/src/jit-test/tests/debug/onNewScript-02.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 // Creating a new script with any number of subscripts triggers the newScript hook exactly once.
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;
michael@0 7 dbg.onNewScript = function (s) {
michael@0 8 assertEq(s instanceof Debugger.Script, true);
michael@0 9 assertEq(!seen.has(s), true);
michael@0 10 seen.set(s, true);
michael@0 11 hits++;
michael@0 12 };
michael@0 13
michael@0 14 dbg.uncaughtExceptionHook = function () { hits = -999; };
michael@0 15
michael@0 16 function test(f) {
michael@0 17 hits = 0;
michael@0 18 f();
michael@0 19 assertEq(hits, 1);
michael@0 20 }
michael@0 21
michael@0 22 // eval declaring a function
michael@0 23 test(function () { g.eval("function A(m, n) { return m===0?n+1:n===0?A(m-1,1):A(m-1,A(m,n-1)); }"); });
michael@0 24
michael@0 25 // evaluate declaring a function
michael@0 26 test(function () { g.eval("function g(a, b) { return b===0?a:g(b,a%b); }"); });
michael@0 27
michael@0 28 // eval declaring multiple functions
michael@0 29 test(function () {
michael@0 30 g.eval("function e(i) { return i===0||o(i-1); }\n" +
michael@0 31 "function o(i) { return i!==0&&e(i-1); }\n");
michael@0 32 });
michael@0 33
michael@0 34 // eval declaring nested functions
michael@0 35 test(function () { g.eval("function plus(x) { return function plusx(y) { return x + y; }; }"); });
michael@0 36
michael@0 37 // eval with a function-expression
michael@0 38 test(function () { g.eval("[3].map(function (i) { return -i; });"); });
michael@0 39
michael@0 40 // eval with getters and setters
michael@0 41 test(function () { g.eval("var obj = {get x() { return 1; }, set x(v) { print(v); }};"); });
michael@0 42
michael@0 43 // Function with nested functions
michael@0 44 test(function () { return g.Function("a", "b", "return b - a;"); });
michael@0 45
michael@0 46 // cloning a function with nested functions
michael@0 47 test(function () { g.clone(evaluate("(function(x) { return x + 1; })", {compileAndGo: false})); });
michael@0 48
michael@0 49 // eval declaring a generator
michael@0 50 test(function () { g.eval("function r(n) { for (var i=0;i<n;i++) yield i; }"); });
michael@0 51
michael@0 52 // eval declaring a star generator
michael@0 53 test(function () { g.eval("function* sg(n) { for (var i=0;i<n;i++) yield i; }"); });
michael@0 54
michael@0 55 // eval with a generator-expression
michael@0 56 test(function () { g.eval("var it = (obj[p] for (p in obj));"); });
michael@0 57
michael@0 58 // eval creating several instances of a closure
michael@0 59 test(function () { g.eval("for (var i = 0; i < 7; i++)\n" +
michael@0 60 " obj = function () { return obj; };\n"); });
michael@0 61
michael@0 62 // non-strict-mode direct eval
michael@0 63 g.eval("function e(s) { eval(s); }");
michael@0 64 test(function () { g.e("function f(x) { return -x; }"); });
michael@0 65
michael@0 66 // strict-mode direct eval
michael@0 67 g.eval("function E(s) { 'use strict'; eval(s); }");
michael@0 68 test(function () { g.E("function g(x) { return -x; }"); });

mercurial