From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- js/src/jit-test/tests/basic/object-tostring.js | 60 ++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 js/src/jit-test/tests/basic/object-tostring.js (limited to 'js/src/jit-test/tests/basic/object-tostring.js') 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); -- cgit v1.2.3