mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 23:17:45 +00:00
LibJS: Add Object::get_without_side_effects()
Similar to Value::to_string_without_side_effects() this is mostly a regular object property lookup, but with the guarantee that it will be side-effect free, i.e. no accessors or native property functions will be called. This is needed when we want to access user-controlled object properties for debug logging, for example. The specific use case will be error objects which will soon no longer have internal name/message properties, so we need to guarantee that printing an error, which may already be the result of an exception, won't blow up in our face :^)
This commit is contained in:
parent
9ec4defdd2
commit
6e9eb0a284
4 changed files with 23 additions and 11 deletions
|
@ -325,9 +325,13 @@ bool ProxyObject::has_property(const PropertyName& name) const
|
|||
return trap_result.to_boolean();
|
||||
}
|
||||
|
||||
Value ProxyObject::get(const PropertyName& name, Value receiver) const
|
||||
Value ProxyObject::get(const PropertyName& name, Value receiver, bool without_side_effects) const
|
||||
{
|
||||
auto& vm = this->vm();
|
||||
if (without_side_effects) {
|
||||
// Sorry, we're not going to call anything on this proxy.
|
||||
return js_string(vm, "<ProxyObject>");
|
||||
}
|
||||
if (m_is_revoked) {
|
||||
vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyRevoked);
|
||||
return {};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue