mirror of
https://github.com/RGBCube/serenity
synced 2025-06-28 21:22:08 +00:00
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.
This commit is contained in:
parent
d6cffb82a2
commit
e875513ff7
4 changed files with 39 additions and 15 deletions
|
@ -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 assign property Symbol(Symbol.hasInstance) to primitive value"
|
||||
`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 set property 'Symbol(Symbol.hasInstance)' of ${primitive}`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue