summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Function/function-call.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /js/src/tests/non262/Function/function-call.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Function/function-call.js')
-rw-r--r--js/src/tests/non262/Function/function-call.js134
1 files changed, 134 insertions, 0 deletions
diff --git a/js/src/tests/non262/Function/function-call.js b/js/src/tests/non262/Function/function-call.js
new file mode 100644
index 0000000000..756b583842
--- /dev/null
+++ b/js/src/tests/non262/Function/function-call.js
@@ -0,0 +1,134 @@
+/*
+ * Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/licenses/publicdomain/
+ * Contributor:
+ * Jeff Walden <jwalden+code@mit.edu>
+ */
+
+//-----------------------------------------------------------------------------
+var BUGNUMBER = 575535;
+var summary = 'Function.prototype.call';
+print(BUGNUMBER + ": " + summary);
+
+/**************
+ * BEGIN TEST *
+ **************/
+
+function expectTypeError(fun, msg)
+{
+ try
+ {
+ fun();
+ assertEq(true, false, "should have thrown a TypeError");
+ }
+ catch (e)
+ {
+ assertEq(e instanceof TypeError, true, msg + "; instead threw " + e);
+ }
+}
+
+function fun() { }
+
+var global = this;
+
+assertEq(Function.prototype.call.length, 1);
+
+
+/* Step 1. */
+var nonfuns = [null, 1, -1, 2.5, "[[Call]]", undefined, true, false, {}];
+for (var i = 0, sz = nonfuns.length; i < sz; i++)
+{
+ var f = function()
+ {
+ Function.prototype.call.apply(nonfuns[i]);
+ };
+ var msg =
+ "expected TypeError calling Function.prototype.call with uncallable this";
+ expectTypeError(f, msg);
+}
+
+
+/* Steps 2-4. */
+function none()
+{
+ assertEq(this, global, "bad this");
+ assertEq(arguments.length, 0, "wrong arguments");
+}
+
+none.call();
+none.call(undefined);
+none.call(null);
+
+var seenThis;
+function strictNone()
+{
+ "use strict";
+ assertEq(this, seenThis, "bad this");
+ assertEq(arguments.length, 0, "wrong arguments");
+}
+
+seenThis = undefined;
+strictNone.call();
+strictNone.call(undefined);
+
+seenThis = null;
+strictNone.call(null);
+
+seenThis = 17;
+strictNone.call(17);
+
+var seenThisBox, args;
+function some()
+{
+ assertEq(this instanceof seenThisBox, true,
+ "this not instanceof " + seenThisBox);
+ assertEq(this.valueOf(), seenThis,
+ "wrong this valueOf()");
+ assertEq(arguments.length, args.length, "wrong arguments count");
+ for (var i = 0; i < args.length; i++)
+ assertEq(arguments[i], args[i], "wrong argument " + i);
+}
+
+seenThis = false;
+seenThisBox = Boolean;
+args = [8, 6, 7, NaN, undefined, 0.3];
+some.call(false, 8, 6, 7, NaN, undefined, 0.3);
+
+var obj = {};
+
+seenThis = "foo";
+seenThisBox = String;
+args = [obj];
+some.call("foo", obj);
+
+seenThis = obj;
+seenThisBox = Object;
+some.call(obj, obj);
+
+function strictSome()
+{
+ "use strict";
+ assertEq(this, seenThis, "wrong this");
+ assertEq(arguments.length, args.length, "wrong arguments count");
+ for (var i = 0; i < args.length; i++)
+ assertEq(arguments[i], args[i], "wrong argument " + i);
+}
+
+seenThis = NaN;
+args = [8, 6, 7, NaN, undefined, 0.3];
+strictSome.call(NaN, 8, 6, 7, NaN, undefined, 0.3);
+
+seenThis = "foo";
+args = [obj];
+strictSome.call("foo", obj);
+
+seenThis = obj;
+strictSome.call(obj, obj);
+
+
+/******************************************************************************/
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+
+print("All tests passed!");