mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 04:07:44 +00:00
LibJS: Implement HostResolveImportedModule for LibJS
This loads modules with relative paths from the referencing module. In this commit the only way to run a module is via the interpreter which can link and evaluate a module (and all its dependencies).
This commit is contained in:
parent
1b8ccf9a66
commit
779e677467
4 changed files with 210 additions and 6 deletions
|
@ -130,11 +130,31 @@ ThrowCompletionOr<Value> Interpreter::run(Script& script_record)
|
|||
return *result.value();
|
||||
}
|
||||
|
||||
ThrowCompletionOr<Value> Interpreter::run(SourceTextModule&)
|
||||
ThrowCompletionOr<Value> Interpreter::run(SourceTextModule& module)
|
||||
{
|
||||
auto* error = InternalError::create(global_object(), "Can't run modules directly yet :^(");
|
||||
vm().throw_exception(global_object(), Value { error });
|
||||
return throw_completion(error);
|
||||
// FIXME: This is not a entry point as defined in the spec, but is convenient.
|
||||
// To avoid work we use link_and_eval_module however that can already be
|
||||
// dangerous if the vm loaded other modules.
|
||||
auto& vm = this->vm();
|
||||
VERIFY(!vm.exception());
|
||||
|
||||
VM::InterpreterExecutionScope scope(*this);
|
||||
|
||||
auto evaluated_or_error = vm.link_and_eval_module({}, module);
|
||||
// This error does not set vm.exception so we set that here for the stuff that needs it
|
||||
if (evaluated_or_error.is_throw_completion()) {
|
||||
auto* error = vm.heap().allocate<Exception>(global_object(), *(evaluated_or_error.throw_completion().value()));
|
||||
vm.set_exception(*error);
|
||||
return evaluated_or_error.throw_completion();
|
||||
}
|
||||
VERIFY(!vm.exception());
|
||||
|
||||
vm.run_queued_promise_jobs();
|
||||
|
||||
vm.run_queued_finalization_registry_cleanup_jobs();
|
||||
|
||||
VERIFY(!vm.exception());
|
||||
return js_undefined();
|
||||
}
|
||||
|
||||
GlobalObject& Interpreter::global_object()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue