mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
LibJS: Support numeric literal expressions in nullish object exceptions
This commit is contained in:
parent
2d603c7c3f
commit
bfcfe6ce35
Notes:
sideshowbarker
2024-07-16 23:34:49 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/bfcfe6ce35 Pull-request: https://github.com/SerenityOS/serenity/pull/23802
3 changed files with 16 additions and 2 deletions
|
@ -91,6 +91,7 @@ public:
|
|||
virtual bool is_import_call() const { return false; }
|
||||
virtual bool is_array_expression() const { return false; }
|
||||
virtual bool is_object_expression() const { return false; }
|
||||
virtual bool is_numeric_literal() const { return false; }
|
||||
virtual bool is_string_literal() const { return false; }
|
||||
virtual bool is_update_expression() const { return false; }
|
||||
virtual bool is_call_expression() const { return false; }
|
||||
|
@ -1182,6 +1183,8 @@ public:
|
|||
virtual Value value() const override { return m_value; }
|
||||
|
||||
private:
|
||||
virtual bool is_numeric_literal() const override { return true; }
|
||||
|
||||
Value m_value;
|
||||
};
|
||||
|
||||
|
|
|
@ -453,6 +453,11 @@ static Optional<ByteString> expression_identifier(Expression const& expression)
|
|||
return identifier.string();
|
||||
}
|
||||
|
||||
if (expression.is_numeric_literal()) {
|
||||
auto const& literal = static_cast<NumericLiteral const&>(expression);
|
||||
return literal.value().to_string_without_side_effects().to_byte_string();
|
||||
}
|
||||
|
||||
if (expression.is_member_expression()) {
|
||||
auto const& member_expression = static_cast<MemberExpression const&>(expression);
|
||||
StringBuilder builder;
|
||||
|
|
|
@ -47,11 +47,17 @@ test("null/undefined array index", () => {
|
|||
|
||||
expect(() => {
|
||||
foo[0].bar;
|
||||
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object`);
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
`Cannot access property "bar" on ${value} object "foo[0]"`
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
foo[0].bar = 1;
|
||||
}).toThrowWithMessage(TypeError, `Cannot access property "bar" on ${value} object`);
|
||||
}).toThrowWithMessage(
|
||||
TypeError,
|
||||
`Cannot access property "bar" on ${value} object "foo[0]"`
|
||||
);
|
||||
|
||||
expect(() => {
|
||||
foo[index].bar;
|
||||
|
|
Loading…
Reference in a new issue