summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorLinus Groh <mail@linusgroh.de>2021-04-02 21:00:37 +0200
committerAndreas Kling <kling@serenityos.org>2021-04-02 22:24:30 +0200
commite875513ff7e34be086d6d8f3c8d77a2f208660f2 (patch)
treec41d778022ffe8ac4824f5dd33c515ab332dcabd /Userland/Libraries/LibJS/Tests
parentd6cffb82a25973d59312afccf63e958660b30449 (diff)
downloadserenity-e875513ff7e34be086d6d8f3c8d77a2f208660f2.zip
LibJS: Use empty value for Reference unresolvable state, not undefined
This fixes an issue where `undefined.foo = "bar"` would throw a ReferenceError instead of a TypeError as undefined was also used for truly unresolvable references (e.g. `foo() = "bar"`). I also made the various error messages here a bit nicer, just "primitive value" is not very helpful.
Diffstat (limited to 'Userland/Libraries/LibJS/Tests')
-rw-r--r--Userland/Libraries/LibJS/Tests/strict-mode-errors.js18
1 files changed, 16 insertions, 2 deletions
diff --git a/Userland/Libraries/LibJS/Tests/strict-mode-errors.js b/Userland/Libraries/LibJS/Tests/strict-mode-errors.js
index ada52e359f..8c8d756c4f 100644
--- a/Userland/Libraries/LibJS/Tests/strict-mode-errors.js
+++ b/Userland/Libraries/LibJS/Tests/strict-mode-errors.js
@@ -4,12 +4,26 @@ test("basic functionality", () => {
[true, false, "foo", 123].forEach(primitive => {
expect(() => {
primitive.foo = "bar";
- }).toThrowWithMessage(TypeError, "Cannot assign property foo to primitive value");
+ }).toThrowWithMessage(
+ TypeError,
+ `Cannot set property 'foo' of ${typeof primitive} '${primitive}'`
+ );
+ expect(() => {
+ primitive[Symbol.hasInstance] = 123;
+ }).toThrowWithMessage(
+ TypeError,
+ `Cannot set property 'Symbol(Symbol.hasInstance)' of ${typeof primitive} '${primitive}'`
+ );
+ });
+ [null, undefined].forEach(primitive => {
+ expect(() => {
+ primitive.foo = "bar";
+ }).toThrowWithMessage(TypeError, `Cannot set property 'foo' of ${primitive}`);
expect(() => {
primitive[Symbol.hasInstance] = 123;
}).toThrowWithMessage(
TypeError,
- "Cannot assign property Symbol(Symbol.hasInstance) to primitive value"
+ `Cannot set property 'Symbol(Symbol.hasInstance)' of ${primitive}`
);
});
});