mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-30 20:59:16 +00:00
LibJS: Include identifier information in nullish property read access
When a GetById / GetByValue 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 Uncaught exception: [TypeError] Cannot access property "bar" on null object "foo" at <unknown> > foo = { bar: undefined } > foo.bar.baz Uncaught exception: [TypeError] Cannot access property "baz" on undefined object "foo.bar" at <unknown> Note we certainly don't capture all possible nullish property read 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
f6ea4bbff8
commit
9bbd3103a8
Notes:
sideshowbarker
2024-07-16 23:03:06 +09:00
Author: https://github.com/trflynn89
Commit: 9bbd3103a8
Pull-request: https://github.com/SerenityOS/serenity/pull/23763
9 changed files with 137 additions and 17 deletions
|
@ -629,11 +629,12 @@ private:
|
|||
|
||||
class GetById final : public Instruction {
|
||||
public:
|
||||
GetById(Operand dst, Operand base, IdentifierTableIndex property, u32 cache_index)
|
||||
GetById(Operand dst, Operand base, IdentifierTableIndex property, Optional<IdentifierTableIndex> base_identifier, u32 cache_index)
|
||||
: Instruction(Type::GetById, sizeof(*this))
|
||||
, m_dst(dst)
|
||||
, m_base(base)
|
||||
, m_property(property)
|
||||
, m_base_identifier(move(base_identifier))
|
||||
, m_cache_index(cache_index)
|
||||
{
|
||||
}
|
||||
|
@ -650,6 +651,7 @@ private:
|
|||
Operand m_dst;
|
||||
Operand m_base;
|
||||
IdentifierTableIndex m_property;
|
||||
Optional<IdentifierTableIndex> m_base_identifier;
|
||||
u32 m_cache_index { 0 };
|
||||
};
|
||||
|
||||
|
@ -874,11 +876,12 @@ private:
|
|||
|
||||
class GetByValue final : public Instruction {
|
||||
public:
|
||||
explicit GetByValue(Operand dst, Operand base, Operand property)
|
||||
GetByValue(Operand dst, Operand base, Operand property, Optional<IdentifierTableIndex> base_identifier = {})
|
||||
: Instruction(Type::GetByValue, sizeof(*this))
|
||||
, m_dst(dst)
|
||||
, m_base(base)
|
||||
, m_property(property)
|
||||
, m_base_identifier(move(base_identifier))
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -889,10 +892,13 @@ public:
|
|||
Operand base() const { return m_base; }
|
||||
Operand property() const { return m_property; }
|
||||
|
||||
Optional<DeprecatedFlyString const&> base_identifier(Bytecode::Interpreter const&) const;
|
||||
|
||||
private:
|
||||
Operand m_dst;
|
||||
Operand m_base;
|
||||
Operand m_property;
|
||||
Optional<IdentifierTableIndex> m_base_identifier;
|
||||
};
|
||||
|
||||
class GetByValueWithThis final : public Instruction {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue