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.

     1 // Creating a new script with any number of subscripts triggers the newScript hook exactly once.
     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 };
    14 dbg.uncaughtExceptionHook = function () { hits = -999; };
    16 function test(f) {
    17     hits = 0;
    18     f();
    19     assertEq(hits, 1);
    20 }
    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)); }"); });
    25 // evaluate declaring a function
    26 test(function () { g.eval("function g(a, b) { return b===0?a:g(b,a%b); }"); });
    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 });
    34 // eval declaring nested functions
    35 test(function () { g.eval("function plus(x) { return function plusx(y) { return x + y; }; }"); });
    37 // eval with a function-expression
    38 test(function () { g.eval("[3].map(function (i) { return -i; });"); });
    40 // eval with getters and setters
    41 test(function () { g.eval("var obj = {get x() { return 1; }, set x(v) { print(v); }};"); });
    43 // Function with nested functions
    44 test(function () { return g.Function("a", "b", "return b - a;"); });
    46 // cloning a function with nested functions
    47 test(function () { g.clone(evaluate("(function(x) { return x + 1; })", {compileAndGo: false})); });
    49 // eval declaring a generator
    50 test(function () { g.eval("function r(n) { for (var i=0;i<n;i++) yield i; }"); });
    52 // eval declaring a star generator
    53 test(function () { g.eval("function* sg(n) { for (var i=0;i<n;i++) yield i; }"); });
    55 // eval with a generator-expression
    56 test(function () { g.eval("var it = (obj[p] for (p in obj));"); });
    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"); });
    62 // non-strict-mode direct eval
    63 g.eval("function e(s) { eval(s); }");
    64 test(function () { g.e("function f(x) { return -x; }"); });
    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; }"); });

mercurial