diff options
author | Linus Groh <mail@linusgroh.de> | 2021-06-27 22:17:05 +0100 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-06-27 22:17:05 +0100 |
commit | 63a12753780b6330d7ca6b6e80f1dde9b07bd973 (patch) | |
tree | a08befeded0136fc2d23f92af5cea3eeaebcac3a /Userland/Libraries/LibJS | |
parent | 844efde54b670e0b3570c833ec031cffa231503a (diff) | |
download | serenity-63a12753780b6330d7ca6b6e80f1dde9b07bd973.zip |
LibJS/Tests: Improve valueToString() output
This regressed recently and would only output a bunch of '[object Foo]',
the reason being that String(value) failed in some cases - which is
easily fixed by trying that first and using Object.prototype.toString()
as a fallback in the case of an exception :^)
Diffstat (limited to 'Userland/Libraries/LibJS')
-rw-r--r-- | Userland/Libraries/LibJS/Tests/test-common.js | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/Userland/Libraries/LibJS/Tests/test-common.js b/Userland/Libraries/LibJS/Tests/test-common.js index 3c0eec4f11..9141fbe53c 100644 --- a/Userland/Libraries/LibJS/Tests/test-common.js +++ b/Userland/Libraries/LibJS/Tests/test-common.js @@ -51,7 +51,14 @@ class ExpectationError extends Error { return true; }; - const valueToString = value => Object.prototype.toString.call(value); + const valueToString = value => { + try { + return String(value); + } catch { + // e.g for objects without a prototype, the above throws. + return Object.prototype.toString.call(value); + } + }; class Expector { constructor(target, inverted) { |