mirror of
https://github.com/RGBCube/serenity
synced 2025-05-28 07:55:07 +00:00
LibJS: Improve error messages for primitive strict mode property access
Using ErrorType::ReferencePrimitiveSetProperty the errors for primitives now look like "Cannot set property 'foo' of number '123'". The strict-mode-errors test has been adjusted and re-enabled.
This commit is contained in:
parent
b9c9315bcb
commit
eaf8c2e398
3 changed files with 19 additions and 15 deletions
|
@ -1,23 +1,19 @@
|
|||
"use strict";
|
||||
|
||||
test.xfail("basic functionality", () => {
|
||||
[true, false, "foo", 123].forEach(primitive => {
|
||||
test("basic functionality", () => {
|
||||
[true, false, "foo", 123, 123n, null, undefined].forEach(primitive => {
|
||||
let description = `${typeof primitive} '${primitive}${
|
||||
typeof primitive == "bigint" ? "n" : ""
|
||||
}'`;
|
||||
if (primitive == null) description = String(primitive);
|
||||
expect(() => {
|
||||
primitive.foo = "bar";
|
||||
}).toThrowWithMessage(TypeError, `Cannot set property 'foo' of ${primitive}`);
|
||||
}).toThrowWithMessage(TypeError, `Cannot set property 'foo' of ${description}`);
|
||||
expect(() => {
|
||||
primitive[Symbol.hasInstance] = 123;
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
`Cannot set property 'Symbol(Symbol.hasInstance)' of ${primitive}`
|
||||
`Cannot set property 'Symbol(Symbol.hasInstance)' of ${description}`
|
||||
);
|
||||
});
|
||||
[null, undefined].forEach(primitive => {
|
||||
expect(() => {
|
||||
primitive.foo = "bar";
|
||||
}).toThrowWithMessage(TypeError, `${primitive} cannot be converted to an object`);
|
||||
expect(() => {
|
||||
primitive[Symbol.hasInstance] = 123;
|
||||
}).toThrowWithMessage(TypeError, `${primitive} cannot be converted to an object`);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue