1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jit-test/tests/debug/onNewScript-02.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,68 @@ 1.4 +// Creating a new script with any number of subscripts triggers the newScript hook exactly once. 1.5 + 1.6 +var g = newGlobal(); 1.7 +var dbg = Debugger(g); 1.8 +var seen = WeakMap(); 1.9 +var hits; 1.10 +dbg.onNewScript = function (s) { 1.11 + assertEq(s instanceof Debugger.Script, true); 1.12 + assertEq(!seen.has(s), true); 1.13 + seen.set(s, true); 1.14 + hits++; 1.15 +}; 1.16 + 1.17 +dbg.uncaughtExceptionHook = function () { hits = -999; }; 1.18 + 1.19 +function test(f) { 1.20 + hits = 0; 1.21 + f(); 1.22 + assertEq(hits, 1); 1.23 +} 1.24 + 1.25 +// eval declaring a function 1.26 +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)); }"); }); 1.27 + 1.28 +// evaluate declaring a function 1.29 +test(function () { g.eval("function g(a, b) { return b===0?a:g(b,a%b); }"); }); 1.30 + 1.31 +// eval declaring multiple functions 1.32 +test(function () { 1.33 + g.eval("function e(i) { return i===0||o(i-1); }\n" + 1.34 + "function o(i) { return i!==0&&e(i-1); }\n"); 1.35 +}); 1.36 + 1.37 +// eval declaring nested functions 1.38 +test(function () { g.eval("function plus(x) { return function plusx(y) { return x + y; }; }"); }); 1.39 + 1.40 +// eval with a function-expression 1.41 +test(function () { g.eval("[3].map(function (i) { return -i; });"); }); 1.42 + 1.43 +// eval with getters and setters 1.44 +test(function () { g.eval("var obj = {get x() { return 1; }, set x(v) { print(v); }};"); }); 1.45 + 1.46 +// Function with nested functions 1.47 +test(function () { return g.Function("a", "b", "return b - a;"); }); 1.48 + 1.49 +// cloning a function with nested functions 1.50 +test(function () { g.clone(evaluate("(function(x) { return x + 1; })", {compileAndGo: false})); }); 1.51 + 1.52 +// eval declaring a generator 1.53 +test(function () { g.eval("function r(n) { for (var i=0;i<n;i++) yield i; }"); }); 1.54 + 1.55 +// eval declaring a star generator 1.56 +test(function () { g.eval("function* sg(n) { for (var i=0;i<n;i++) yield i; }"); }); 1.57 + 1.58 +// eval with a generator-expression 1.59 +test(function () { g.eval("var it = (obj[p] for (p in obj));"); }); 1.60 + 1.61 +// eval creating several instances of a closure 1.62 +test(function () { g.eval("for (var i = 0; i < 7; i++)\n" + 1.63 + " obj = function () { return obj; };\n"); }); 1.64 + 1.65 +// non-strict-mode direct eval 1.66 +g.eval("function e(s) { eval(s); }"); 1.67 +test(function () { g.e("function f(x) { return -x; }"); }); 1.68 + 1.69 +// strict-mode direct eval 1.70 +g.eval("function E(s) { 'use strict'; eval(s); }"); 1.71 +test(function () { g.E("function g(x) { return -x; }"); });