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