js/src/jit-test/tests/debug/Object-apply-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 // tests calling native functions via Debugger.Object.prototype.apply/call
     3 load(libdir + "asserts.js");
     5 var g = newGlobal();
     6 g.eval("function f() { debugger; }");
     7 var dbg = new Debugger(g);
     9 function test(usingApply) {
    10     dbg.onDebuggerStatement = function (frame) {
    11         var max = frame.arguments[0];
    12         var cv = usingApply ? max.apply(null, [9, 16]) : max.call(null, 9, 16);
    13         assertEq(cv.return, 16);
    15         cv = usingApply ? max.apply() : max.call();
    16         assertEq(cv.return, -1/0);
    18         cv = usingApply ? max.apply(null, [2, 5, 3, 8, 1, 9, 4, 6, 7])
    19                         : max.call(null, 2, 5, 3, 8, 1, 9, 4, 6, 7);
    20         assertEq(cv.return, 9);
    22         // second argument to apply must be an array
    23         assertThrowsInstanceOf(function () { max.apply(null, 12); }, TypeError);
    24     };
    25     g.eval("f(Math.max);");
    27     dbg.onDebuggerStatement = function (frame) {
    28         var push = frame.arguments[0];
    29         var arr = frame.arguments[1];
    30         var cv;
    32         cv = usingApply ? push.apply(arr, [0, 1, 2]) : push.call(arr, 0, 1, 2);
    33         assertEq(cv.return, 3);
    35         cv = usingApply ? push.apply(arr, [arr]) : push.call(arr, arr);
    36         assertEq(cv.return, 4);
    38         cv = usingApply ? push.apply(arr) : push.call(arr);
    39         assertEq(cv.return, 4);
    41         // You can apply Array.prototype.push to a string; it does ToObject on
    42         // it.  But as the length property on String objects is non-writable,
    43         // attempting to increase the length will throw a TypeError.
    44         cv = usingApply
    45              ? push.apply("hello", ["world"])
    46              : push.call("hello", "world");
    47         assertEq("throw" in cv, true);
    48         var ex = cv.throw;
    49         assertEq(frame.evalWithBindings("ex instanceof TypeError", { ex: ex }).return, true);
    50     };
    51     g.eval("var a = []; f(Array.prototype.push, a);");
    52     assertEq(g.a.length, 4);
    53     assertEq(g.a.slice(0, 3).join(","), "0,1,2");
    54     assertEq(g.a[3], g.a);
    55 }
    57 test(true);
    58 test(false);

mercurial