summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/object-tostring.js
diff options
context:
space:
mode:
Diffstat (limited to 'js/src/jit-test/tests/basic/object-tostring.js')
-rw-r--r--js/src/jit-test/tests/basic/object-tostring.js60
1 files changed, 60 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/object-tostring.js b/js/src/jit-test/tests/basic/object-tostring.js
new file mode 100644
index 0000000000..5f6204d6dd
--- /dev/null
+++ b/js/src/jit-test/tests/basic/object-tostring.js
@@ -0,0 +1,60 @@
+
+function doTest(expected, v) {
+ assertEq(Object.prototype.toString.call(v), expected)
+}
+
+function Dummy() {}
+
+// Basic primitive cases
+doTest("[object Undefined]", undefined);
+doTest("[object Null]", null);
+doTest("[object String]", "");
+doTest("[object Number]", 12);
+doTest("[object Number]", 12.34);
+doTest("[object Boolean]", true);
+doTest("[object Symbol]", Symbol());
+doTest("[object BigInt]", 1234n);
+
+// Exotic objects with builtinTag
+doTest("[object Array]", []);
+(function() {
+ doTest("[object Arguments]", arguments);
+})();
+doTest("[object Function]", () => {});
+doTest("[object Error]", new Error);
+doTest("[object Date]", new Date);
+doTest("[object RegExp]", /i/);
+
+// Exotic objects with @@toStringTag
+doTest("[object Map]", new Map);
+doTest("[object Set]", new Set);
+doTest("[object JSON]", JSON);
+doTest("[object Math]", Math);
+
+// Normal object cases
+doTest("[object Object]", {});
+doTest("[object Object]", new Dummy);
+doTest("[object Foo]", { [Symbol.toStringTag]: "Foo" });
+
+// Test the receiver of Symbol.toStringTag
+let receiver1;
+let object1 = {
+ __proto__: {
+ get [Symbol.toStringTag]() {
+ receiver1 = this;
+ }
+ }
+};
+doTest("[object Object]", object1);
+assertEq(receiver1, object1);
+
+//// BELOW THIS LINE TAMPERS WITH GLOBAL
+
+// Set a toStringTag on the global String.prototype
+let receiver2;
+Object.defineProperty(String.prototype, Symbol.toStringTag, { get: function() {
+ receiver2 = this;
+ return "XString";
+}});
+doTest("[object XString]", "");
+assertEq(Object.getPrototypeOf(receiver2), String.prototype);