Right now when we're interpreting the AST we utilize JsResult as a wrapper for any error that originates on execution. This has its advantages; we can propagate type errors and throw errors with ? and return any value generated from a native function with ease. However, #672 showed us that having no distinction between a value returned from a native function and a value returned from AST interpretation is suboptimal.
The spec solves this problem with Completion Records, which are a way to separate values generated from native functions and values generated from the execution of Javascript code.
This technique also allows us to eliminate InterpreterState from the Context, essentially removing state that we needed to maintain by hand, like in:
|
context |
|
.executor() |
|
.set_current_state(InterpreterState::Return); |
|
result |
or
|
context |
|
.executor() |
|
.set_current_state(InterpreterState::Executing); |
To implement CompletionRecords we would need to make a big refactor to the AST. Here's a non-exhaustive list in an arbitrary order of the required tasks:
Right now when we're interpreting the AST we utilize
JsResultas a wrapper for any error that originates on execution. This has its advantages; we can propagate type errors andthrowerrors with?and return any value generated from a native function with ease. However, #672 showed us that having no distinction between a value returned from a native function and a value returned from AST interpretation is suboptimal.The spec solves this problem with
Completion Records, which are a way to separate values generated from native functions and values generated from the execution of Javascript code.This technique also allows us to eliminate
InterpreterStatefrom theContext, essentially removing state that we needed to maintain by hand, like in:boa/boa/src/syntax/ast/node/return_smt/mod.rs
Lines 70 to 73 in a11a8a9
or
boa/boa/src/syntax/ast/node/statement_list/mod.rs
Lines 121 to 123 in a11a8a9
To implement
CompletionRecordswe would need to make a big refactor to the AST. Here's a non-exhaustive list in an arbitrary order of the required tasks:CompletionRecordstruct type with its associated methods from the specrunfrom theExecutabletrait return aJsResult<CompletionRecord>.CompletionRecordof every AST node evaluation.InterpreterStatefrom theContexttype. (We can reuse the type as the[[Type]]field of aCompletionRecord)