summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-apply-01.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /js/src/jit-test/tests/debug/Object-apply-01.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'js/src/jit-test/tests/debug/Object-apply-01.js')
-rw-r--r--js/src/jit-test/tests/debug/Object-apply-01.js59
1 files changed, 59 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Object-apply-01.js b/js/src/jit-test/tests/debug/Object-apply-01.js
new file mode 100644
index 000000000..954e80b66
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Object-apply-01.js
@@ -0,0 +1,59 @@
+// tests calling script functions via Debugger.Object.prototype.apply/call
+
+load(libdir + "asserts.js");
+
+var g = newGlobal();
+g.eval("function f() { debugger; }");
+var dbg = new Debugger(g);
+
+var hits = 0;
+function test(usingApply) {
+ dbg.onDebuggerStatement = function (frame) {
+ var fn = frame.arguments[0];
+ var cv = usingApply ? fn.apply(null, [9, 16]) : fn.call(null, 9, 16);
+ assertEq(Object.keys(cv).join(","), "return");
+ assertEq(Object.getPrototypeOf(cv), Object.prototype);
+ assertEq(cv.return, 25);
+
+ cv = usingApply ? fn.apply(null, ["hello ", "world"]) : fn.call(null, "hello ", "world");
+ assertEq(Object.keys(cv).join(","), "return");
+ assertEq(cv.return, "hello world");
+
+ // Handle more or less arguments.
+ assertEq((usingApply ? fn.apply(null, [1, 5, 100]) : fn.call(null, 1, 5, 100)).return, 6);
+ assertEq((usingApply ? fn.apply(null, []) : fn.call(null)).return, NaN);
+ assertEq((usingApply ? fn.apply() : fn.call()).return, NaN);
+
+ // Throw if a this-value or argument is an object but not a Debugger.Object.
+ assertThrowsInstanceOf(function () { usingApply ? fn.apply({}, []) : fn.call({}); },
+ TypeError);
+ assertThrowsInstanceOf(function () { usingApply ? fn.apply(null, [{}]) : fn.call(null, {}); },
+ TypeError);
+ hits++;
+ };
+ g.eval("f(function (a, b) { return a + b; });");
+
+ // The callee receives the right arguments even if more arguments are provided
+ // than the callee's .length.
+ dbg.onDebuggerStatement = function (frame) {
+ assertEq((usingApply ? frame.arguments[0].apply(null, ['one', 'two'])
+ : frame.arguments[0].call(null, 'one', 'two')).return,
+ 2);
+ hits++;
+ };
+ g.eval("f(function () { return arguments.length; });");
+
+ // Exceptions are reported as {throw:} completion values.
+ dbg.onDebuggerStatement = function (frame) {
+ var lose = frame.arguments[0];
+ var cv = usingApply ? lose.apply(null, []) : lose.call(null);
+ assertEq(Object.keys(cv).join(","), "throw");
+ assertEq(cv.throw, frame.callee);
+ hits++;
+ };
+ g.eval("f(function lose() { throw f; });");
+}
+
+test(true);
+test(false);
+assertEq(hits, 6);