mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-11 12:06:07 +00:00
LibJS: Support computed member expressions in nullish object exceptions
This commit is contained in:
parent
51f5fa1437
commit
2d603c7c3f
Notes:
sideshowbarker
2024-07-16 23:51:07 +09:00
Author: https://github.com/trflynn89
Commit: 2d603c7c3f
Pull-request: https://github.com/SerenityOS/serenity/pull/23802
2 changed files with 19 additions and 3 deletions
|
@ -461,9 +461,10 @@ static Optional<ByteString> expression_identifier(Expression const& expression)
|
|||
builder.append(*identifer);
|
||||
|
||||
if (auto identifer = expression_identifier(member_expression.property()); identifer.has_value()) {
|
||||
if (!builder.is_empty())
|
||||
builder.append('.');
|
||||
builder.append(*identifer);
|
||||
if (member_expression.is_computed())
|
||||
builder.appendff("[{}]", *identifer);
|
||||
else
|
||||
builder.appendff(".{}", *identifer);
|
||||
}
|
||||
|
||||
return builder.to_byte_string();
|
||||
|
|
|
@ -43,6 +43,7 @@ test("null/undefined object key", () => {
|
|||
test("null/undefined array index", () => {
|
||||
[null, undefined].forEach(value => {
|
||||
let foo = [value];
|
||||
let index = 0;
|
||||
|
||||
expect(() => {
|
||||
foo[0].bar;
|
||||
|
@ -51,5 +52,19 @@ test("null/undefined array index", () => {
|
|||
expect(() => {
|
||||
foo[0].bar = 1;
|
||||
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object`);
|
||||
|
||||
expect(() => {
|
||||
foo[index].bar;
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
`Cannot access property "bar" on ${value} object "foo[index]"`
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
foo[index].bar = 1;
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
`Cannot access property "bar" on ${value} object "foo[index]"`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue