mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:17:35 +00:00
LibJS: Convert internal_set() to ThrowCompletionOr
This commit is contained in:
parent
6c2b974db2
commit
e5409c6ead
19 changed files with 66 additions and 69 deletions
|
@ -40,7 +40,7 @@ JS::ThrowCompletionOr<JS::Value> DebuggerGlobalJSObject::internal_get(JS::Proper
|
|||
return vm().throw_completion<JS::TypeError>(const_cast<DebuggerGlobalJSObject&>(*this), move(error_string));
|
||||
}
|
||||
|
||||
bool DebuggerGlobalJSObject::internal_set(JS::PropertyName const& property_name, JS::Value value, JS::Value receiver)
|
||||
JS::ThrowCompletionOr<bool> DebuggerGlobalJSObject::internal_set(JS::PropertyName const& property_name, JS::Value value, JS::Value receiver)
|
||||
{
|
||||
if (m_variables.is_empty() || !property_name.is_string())
|
||||
return Base::internal_set(property_name, value, receiver);
|
||||
|
@ -55,8 +55,7 @@ bool DebuggerGlobalJSObject::internal_set(JS::PropertyName const& property_name,
|
|||
if (debugger_value.has_value())
|
||||
return Debugger::the().session()->poke((u32*)target_variable.location_data.address, debugger_value.value());
|
||||
auto error_string = String::formatted("Cannot convert JS value {} to variable {} of type {}", value.to_string_without_side_effects(), property_name.as_string(), target_variable.type_name);
|
||||
vm().throw_exception<JS::TypeError>(const_cast<DebuggerGlobalJSObject&>(*this), error_string);
|
||||
return {};
|
||||
return vm().throw_completion<JS::TypeError>(const_cast<DebuggerGlobalJSObject&>(*this), move(error_string));
|
||||
}
|
||||
|
||||
Optional<JS::Value> DebuggerGlobalJSObject::debugger_to_js(const Debug::DebugInfo::VariableInfo& variable) const
|
||||
|
|
|
@ -22,7 +22,7 @@ public:
|
|||
DebuggerGlobalJSObject();
|
||||
|
||||
virtual JS::ThrowCompletionOr<JS::Value> internal_get(JS::PropertyName const&, JS::Value receiver) const override;
|
||||
virtual bool internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;
|
||||
virtual JS::ThrowCompletionOr<bool> internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;
|
||||
|
||||
Optional<JS::Value> debugger_to_js(const Debug::DebugInfo::VariableInfo&) const;
|
||||
Optional<u32> js_to_debugger(JS::Value value, const Debug::DebugInfo::VariableInfo&) const;
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
#include "DebuggerVariableJSObject.h"
|
||||
#include "Debugger.h"
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Error.h>
|
||||
#include <LibJS/Runtime/PrimitiveString.h>
|
||||
#include <LibJS/Runtime/PropertyName.h>
|
||||
|
@ -28,30 +29,26 @@ DebuggerVariableJSObject::~DebuggerVariableJSObject()
|
|||
{
|
||||
}
|
||||
|
||||
bool DebuggerVariableJSObject::internal_set(const JS::PropertyName& property_name, JS::Value value, JS::Value)
|
||||
JS::ThrowCompletionOr<bool> DebuggerVariableJSObject::internal_set(const JS::PropertyName& property_name, JS::Value value, JS::Value)
|
||||
{
|
||||
if (!property_name.is_string()) {
|
||||
vm().throw_exception<JS::TypeError>(global_object(), String::formatted("Invalid variable name {}", property_name.to_string()));
|
||||
return false;
|
||||
}
|
||||
auto& vm = this->vm();
|
||||
|
||||
if (!property_name.is_string())
|
||||
return vm.throw_completion<JS::TypeError>(global_object(), String::formatted("Invalid variable name {}", property_name.to_string()));
|
||||
|
||||
auto name = property_name.as_string();
|
||||
auto it = m_variable_info.members.find_if([&](auto& variable) {
|
||||
return variable->name == name;
|
||||
});
|
||||
|
||||
if (it.is_end()) {
|
||||
vm().throw_exception<JS::TypeError>(global_object(), String::formatted("Variable of type {} has no property {}", m_variable_info.type_name, property_name));
|
||||
return false;
|
||||
}
|
||||
if (it.is_end())
|
||||
return vm.throw_completion<JS::TypeError>(global_object(), String::formatted("Variable of type {} has no property {}", m_variable_info.type_name, property_name));
|
||||
|
||||
auto& member = **it;
|
||||
auto new_value = debugger_object().js_to_debugger(value, member);
|
||||
if (!new_value.has_value()) {
|
||||
auto string_error = String::formatted("Cannot convert JS value {} to variable {} of type {}", value.to_string_without_side_effects(), name, member.type_name);
|
||||
vm().throw_exception<JS::TypeError>(global_object(), string_error);
|
||||
return false;
|
||||
}
|
||||
if (!new_value.has_value())
|
||||
return vm.throw_completion<JS::TypeError>(global_object(), String::formatted("Cannot convert JS value {} to variable {} of type {}", value.to_string_without_side_effects(), name, member.type_name));
|
||||
|
||||
Debugger::the().session()->poke((u32*)member.location_data.address, new_value.value());
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
|
||||
#include "DebuggerGlobalJSObject.h"
|
||||
#include <LibDebug/DebugInfo.h>
|
||||
#include <LibJS/Runtime/Completion.h>
|
||||
#include <LibJS/Runtime/Object.h>
|
||||
|
||||
namespace HackStudio {
|
||||
|
@ -24,7 +25,7 @@ public:
|
|||
|
||||
virtual const char* class_name() const override { return m_variable_info.type_name.characters(); }
|
||||
|
||||
bool internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;
|
||||
JS::ThrowCompletionOr<bool> internal_set(JS::PropertyName const&, JS::Value value, JS::Value receiver) override;
|
||||
|
||||
private:
|
||||
DebuggerGlobalJSObject& debugger_object() const;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue