mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:37:34 +00:00
LibJS: Convert Interpreter::run() to ThrowCompletionOr<Value>
Instead of making it a void function, checking for an exception, and then receiving the relevant result via VM::last_value(), we can consolidate all of this by using completions. This allows us to remove more uses of VM::exception(), and all uses of VM::last_value().
This commit is contained in:
parent
f73afbb5ae
commit
eb60d16549
13 changed files with 62 additions and 56 deletions
|
@ -55,7 +55,7 @@ Sheet::Sheet(Workbook& workbook)
|
|||
warnln("Spreadsheet: Failed to parse runtime code");
|
||||
parser.print_errors();
|
||||
} else {
|
||||
interpreter().run(global_object(), parser.parse_program());
|
||||
(void)interpreter().run(global_object(), parser.parse_program());
|
||||
if (auto* exception = interpreter().exception()) {
|
||||
warnln("Spreadsheet: Failed to run runtime code:");
|
||||
for (auto& traceback_frame : exception->traceback()) {
|
||||
|
@ -164,16 +164,12 @@ Sheet::ValueAndException Sheet::evaluate(StringView source, Cell* on_behalf_of)
|
|||
if (parser.has_errors() || interpreter().exception())
|
||||
return { JS::js_undefined(), interpreter().exception() };
|
||||
|
||||
interpreter().run(global_object(), program);
|
||||
if (interpreter().exception()) {
|
||||
auto result = interpreter().run(global_object(), program);
|
||||
if (result.is_error()) {
|
||||
auto exc = interpreter().exception();
|
||||
return { JS::js_undefined(), exc };
|
||||
}
|
||||
|
||||
auto value = interpreter().vm().last_value();
|
||||
if (value.is_empty())
|
||||
return { JS::js_undefined(), {} };
|
||||
return { value, {} };
|
||||
return { result.value(), {} };
|
||||
}
|
||||
|
||||
Cell* Sheet::at(StringView name)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue