diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/object-tostring.js | |
parent | Initial commit. (diff) | |
download | firefox-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/basic/object-tostring.js')
-rw-r--r-- | js/src/jit-test/tests/basic/object-tostring.js | 60 |
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); |