mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-24 10:12:25 -05:00
LibJS: Fix incorrect exception checks in ProxyObject
We must *never* call some method that expects a non-empty value on the result of a function call without checking for exceptions first. It won't work reliably. Fixes #3939.
This commit is contained in:
parent
cfce6b37be
commit
8afe1c8165
Notes:
sideshowbarker
2024-07-19 01:34:04 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/8afe1c81651 Pull-request: https://github.com/SerenityOS/serenity/pull/3940 Issue: https://github.com/SerenityOS/serenity/issues/3939
1 changed files with 17 additions and 17 deletions
|
@ -138,8 +138,8 @@ bool ProxyObject::set_prototype(Object* object)
|
|||
return false;
|
||||
}
|
||||
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target), Value(object)).to_boolean();
|
||||
if (vm().exception() || !trap_result)
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target), Value(object));
|
||||
if (vm().exception() || !trap_result.to_boolean())
|
||||
return false;
|
||||
if (m_target.is_extensible())
|
||||
return true;
|
||||
|
@ -169,15 +169,15 @@ bool ProxyObject::is_extensible() const
|
|||
return {};
|
||||
}
|
||||
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean();
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target));
|
||||
if (vm().exception())
|
||||
return false;
|
||||
if (trap_result != m_target.is_extensible()) {
|
||||
if (trap_result.to_boolean() != m_target.is_extensible()) {
|
||||
if (!vm().exception())
|
||||
vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyIsExtensibleReturn);
|
||||
return false;
|
||||
}
|
||||
return trap_result;
|
||||
return trap_result.to_boolean();
|
||||
}
|
||||
|
||||
bool ProxyObject::prevent_extensions()
|
||||
|
@ -196,15 +196,15 @@ bool ProxyObject::prevent_extensions()
|
|||
return {};
|
||||
}
|
||||
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target)).to_boolean();
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target));
|
||||
if (vm().exception())
|
||||
return false;
|
||||
if (trap_result && m_target.is_extensible()) {
|
||||
if (trap_result.to_boolean() && m_target.is_extensible()) {
|
||||
if (!vm().exception())
|
||||
vm().throw_exception<TypeError>(global_object(), ErrorType::ProxyPreventExtensionsReturn);
|
||||
return false;
|
||||
}
|
||||
return trap_result;
|
||||
return trap_result.to_boolean();
|
||||
}
|
||||
|
||||
Optional<PropertyDescriptor> ProxyObject::get_own_property_descriptor(const PropertyName& name) const
|
||||
|
@ -278,8 +278,8 @@ bool ProxyObject::define_property(const StringOrSymbol& property_name, const Obj
|
|||
return false;
|
||||
}
|
||||
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target), property_name.to_value(vm()), Value(const_cast<Object*>(&descriptor))).to_boolean();
|
||||
if (vm().exception() || !trap_result)
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target), property_name.to_value(vm()), Value(const_cast<Object*>(&descriptor)));
|
||||
if (vm().exception() || !trap_result.to_boolean())
|
||||
return false;
|
||||
auto target_desc = m_target.get_own_property_descriptor(property_name);
|
||||
if (vm().exception())
|
||||
|
@ -329,10 +329,10 @@ bool ProxyObject::has_property(const PropertyName& name) const
|
|||
return false;
|
||||
}
|
||||
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(vm(), name.to_string())).to_boolean();
|
||||
auto trap_result = vm().call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(vm(), name.to_string()));
|
||||
if (vm().exception())
|
||||
return false;
|
||||
if (!trap_result) {
|
||||
if (!trap_result.to_boolean()) {
|
||||
auto target_desc = m_target.get_own_property_descriptor(name);
|
||||
if (vm().exception())
|
||||
return false;
|
||||
|
@ -348,7 +348,7 @@ bool ProxyObject::has_property(const PropertyName& name) const
|
|||
}
|
||||
}
|
||||
}
|
||||
return trap_result;
|
||||
return trap_result.to_boolean();
|
||||
}
|
||||
|
||||
Value ProxyObject::get(const PropertyName& name, Value) const
|
||||
|
@ -402,8 +402,8 @@ bool ProxyObject::put(const PropertyName& name, Value value, Value)
|
|||
vm.throw_exception<TypeError>(global_object(), ErrorType::ProxyInvalidTrap, "set");
|
||||
return false;
|
||||
}
|
||||
auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(vm, name.to_string()), value, Value(const_cast<ProxyObject*>(this))).to_boolean();
|
||||
if (vm.exception() || !trap_result)
|
||||
auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(vm, name.to_string()), value, Value(const_cast<ProxyObject*>(this)));
|
||||
if (vm.exception() || !trap_result.to_boolean())
|
||||
return false;
|
||||
auto target_desc = m_target.get_own_property_descriptor(name);
|
||||
if (vm.exception())
|
||||
|
@ -437,10 +437,10 @@ Value ProxyObject::delete_property(const PropertyName& name)
|
|||
return {};
|
||||
}
|
||||
|
||||
auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(vm, name.to_string())).to_boolean();
|
||||
auto trap_result = vm.call(trap.as_function(), Value(&m_handler), Value(&m_target), js_string(vm, name.to_string()));
|
||||
if (vm.exception())
|
||||
return {};
|
||||
if (!trap_result)
|
||||
if (!trap_result.to_boolean())
|
||||
return Value(false);
|
||||
auto target_desc = m_target.get_own_property_descriptor(name);
|
||||
if (vm.exception())
|
||||
|
|
Loading…
Add table
Reference in a new issue