summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/debug/Object-apply-02.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/debug/Object-apply-02.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/debug/Object-apply-02.js')
-rw-r--r--js/src/jit-test/tests/debug/Object-apply-02.js58
1 files changed, 58 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/debug/Object-apply-02.js b/js/src/jit-test/tests/debug/Object-apply-02.js
new file mode 100644
index 0000000000..18ce4468a2
--- /dev/null
+++ b/js/src/jit-test/tests/debug/Object-apply-02.js
@@ -0,0 +1,58 @@
+// tests calling native functions via Debugger.Object.prototype.apply/call
+
+load(libdir + "asserts.js");
+
+var g = newGlobal({newCompartment: true});
+g.eval("function f() { debugger; }");
+var dbg = new Debugger(g);
+
+function test(usingApply) {
+ dbg.onDebuggerStatement = function (frame) {
+ var max = frame.arguments[0];
+ var cv = usingApply ? max.apply(null, [9, 16]) : max.call(null, 9, 16);
+ assertEq(cv.return, 16);
+
+ cv = usingApply ? max.apply() : max.call();
+ assertEq(cv.return, -1/0);
+
+ cv = usingApply ? max.apply(null, [2, 5, 3, 8, 1, 9, 4, 6, 7])
+ : max.call(null, 2, 5, 3, 8, 1, 9, 4, 6, 7);
+ assertEq(cv.return, 9);
+
+ // second argument to apply must be an array
+ assertThrowsInstanceOf(function () { max.apply(null, 12); }, TypeError);
+ };
+ g.eval("f(Math.max);");
+
+ dbg.onDebuggerStatement = function (frame) {
+ var push = frame.arguments[0];
+ var arr = frame.arguments[1];
+ var cv;
+
+ cv = usingApply ? push.apply(arr, [0, 1, 2]) : push.call(arr, 0, 1, 2);
+ assertEq(cv.return, 3);
+
+ cv = usingApply ? push.apply(arr, [arr]) : push.call(arr, arr);
+ assertEq(cv.return, 4);
+
+ cv = usingApply ? push.apply(arr) : push.call(arr);
+ assertEq(cv.return, 4);
+
+ // You can apply Array.prototype.push to a string; it does ToObject on
+ // it. But as the length property on String objects is non-writable,
+ // attempting to increase the length will throw a TypeError.
+ cv = usingApply
+ ? push.apply("hello", ["world"])
+ : push.call("hello", "world");
+ assertEq("throw" in cv, true);
+ var ex = cv.throw;
+ assertEq(frame.evalWithBindings("ex instanceof TypeError", { ex: ex }).return, true);
+ };
+ g.eval("var a = []; f(Array.prototype.push, a);");
+ assertEq(g.a.length, 4);
+ assertEq(g.a.slice(0, 3).join(","), "0,1,2");
+ assertEq(g.a[3], g.a);
+}
+
+test(true);
+test(false);