js/src/jit-test/tests/debug/Object-apply-01.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jit-test/tests/debug/Object-apply-01.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,59 @@
     1.4 +// tests calling script functions via Debugger.Object.prototype.apply/call
     1.5 +
     1.6 +load(libdir + "asserts.js");
     1.7 +
     1.8 +var g = newGlobal();
     1.9 +g.eval("function f() { debugger; }");
    1.10 +var dbg = new Debugger(g);
    1.11 +
    1.12 +var hits = 0;
    1.13 +function test(usingApply) {
    1.14 +    dbg.onDebuggerStatement = function (frame) {
    1.15 +        var fn = frame.arguments[0];
    1.16 +        var cv = usingApply ? fn.apply(null, [9, 16]) : fn.call(null, 9, 16);
    1.17 +        assertEq(Object.keys(cv).join(","), "return");
    1.18 +        assertEq(Object.getPrototypeOf(cv), Object.prototype);
    1.19 +        assertEq(cv.return, 25);
    1.20 +
    1.21 +        cv = usingApply ? fn.apply(null, ["hello ", "world"]) : fn.call(null, "hello ", "world");
    1.22 +        assertEq(Object.keys(cv).join(","), "return");
    1.23 +        assertEq(cv.return, "hello world");
    1.24 +
    1.25 +        // Handle more or less arguments.
    1.26 +        assertEq((usingApply ? fn.apply(null, [1, 5, 100]) : fn.call(null, 1, 5, 100)).return, 6);
    1.27 +        assertEq((usingApply ? fn.apply(null, []) : fn.call(null)).return, NaN);
    1.28 +        assertEq((usingApply ? fn.apply() : fn.call()).return, NaN);
    1.29 +
    1.30 +        // Throw if a this-value or argument is an object but not a Debugger.Object.
    1.31 +        assertThrowsInstanceOf(function () { usingApply ? fn.apply({}, []) : fn.call({}); },
    1.32 +                               TypeError);
    1.33 +        assertThrowsInstanceOf(function () { usingApply ? fn.apply(null, [{}]) : fn.call(null, {}); },
    1.34 +                               TypeError);
    1.35 +        hits++;
    1.36 +    };
    1.37 +    g.eval("f(function (a, b) { return a + b; });");
    1.38 +
    1.39 +    // The callee receives the right arguments even if more arguments are provided
    1.40 +    // than the callee's .length.
    1.41 +    dbg.onDebuggerStatement = function (frame) {
    1.42 +        assertEq((usingApply ? frame.arguments[0].apply(null, ['one', 'two'])
    1.43 +                             : frame.arguments[0].call(null, 'one', 'two')).return,
    1.44 +                 2);
    1.45 +        hits++;
    1.46 +    };
    1.47 +    g.eval("f(function () { return arguments.length; });");
    1.48 +
    1.49 +    // Exceptions are reported as {throw:} completion values.
    1.50 +    dbg.onDebuggerStatement = function (frame) {
    1.51 +        var lose = frame.arguments[0];
    1.52 +        var cv = usingApply ? lose.apply(null, []) : lose.call(null);
    1.53 +        assertEq(Object.keys(cv).join(","), "throw");
    1.54 +        assertEq(cv.throw, frame.callee);
    1.55 +        hits++;
    1.56 +    };
    1.57 +    g.eval("f(function lose() { throw f; });");
    1.58 +}
    1.59 +
    1.60 +test(true);
    1.61 +test(false);
    1.62 +assertEq(hits, 6);

mercurial