mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-29 04:09:13 +00:00
LibJS: Include identifier information in nullish property write access
When a PutById / PutByValue bytecode operation results in accessing a nullish object, we now include the name of the property and the object being accessed in the exception message (if available). This should make it easier to debug live websites. For example, the following errors would all previously produce a generic error message of "ToObject on null or undefined": > foo = null > foo.bar = 1 Uncaught exception: [TypeError] Cannot access property "bar" on null object "foo" at <unknown> > foo = { bar: undefined } > foo.bar.baz = 1 Uncaught exception: [TypeError] Cannot access property "baz" on undefined object "foo.bar" at <unknown> Note we certainly don't capture all possible nullish property write accesses here. This just covers cases I've seen most on live websites; we can cover more cases as they arise.
This commit is contained in:
parent
9bbd3103a8
commit
22fdcfbc50
Notes:
sideshowbarker
2024-07-17 08:55:54 +09:00
Author: https://github.com/trflynn89
Commit: 22fdcfbc50
Pull-request: https://github.com/SerenityOS/serenity/pull/23763
5 changed files with 42 additions and 12 deletions
|
@ -489,16 +489,17 @@ Bytecode::CodeGenerationErrorOr<Optional<Bytecode::Operand>> AssignmentExpressio
|
|||
generator.emit_set_variable(identifier, rval);
|
||||
} else if (is<MemberExpression>(*lhs)) {
|
||||
auto& expression = static_cast<MemberExpression const&>(*lhs);
|
||||
auto base_identifier = generator.intern_identifier_for_expression(expression.object());
|
||||
|
||||
if (expression.is_computed()) {
|
||||
if (!lhs_is_super_expression)
|
||||
generator.emit<Bytecode::Op::PutByValue>(*base, *computed_property, rval);
|
||||
generator.emit<Bytecode::Op::PutByValue>(*base, *computed_property, rval, Bytecode::Op::PropertyKind::KeyValue, move(base_identifier));
|
||||
else
|
||||
generator.emit<Bytecode::Op::PutByValueWithThis>(*base, *computed_property, *this_value, rval);
|
||||
} else if (expression.property().is_identifier()) {
|
||||
auto identifier_table_ref = generator.intern_identifier(verify_cast<Identifier>(expression.property()).string());
|
||||
if (!lhs_is_super_expression)
|
||||
generator.emit<Bytecode::Op::PutById>(*base, identifier_table_ref, rval, Bytecode::Op::PropertyKind::KeyValue, generator.next_property_lookup_cache());
|
||||
generator.emit<Bytecode::Op::PutById>(*base, identifier_table_ref, rval, Bytecode::Op::PropertyKind::KeyValue, generator.next_property_lookup_cache(), move(base_identifier));
|
||||
else
|
||||
generator.emit<Bytecode::Op::PutByIdWithThis>(*base, *this_value, identifier_table_ref, rval, Bytecode::Op::PropertyKind::KeyValue, generator.next_property_lookup_cache());
|
||||
} else if (expression.property().is_private_identifier()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue