LibJS: Add host layering point related to modules to VM

Also make HostResolveImportedModule fail on the browser to prevent
module loading for now.
This commit is contained in:
davidot 2022-01-18 19:14:25 +01:00 committed by Linus Groh
parent 0b89dbc529
commit be9d478d92
Notes: sideshowbarker 2024-07-17 20:28:39 +09:00
3 changed files with 14 additions and 0 deletions

View file

@ -170,6 +170,7 @@ class Script;
class Shape;
class Statement;
class StringOrSymbol;
class SourceTextModule;
class Symbol;
class Token;
class Utf16String;
@ -180,6 +181,7 @@ class WrappedFunction;
enum class DeclarationKind;
struct AlreadyResolved;
struct JobCallback;
struct ModuleRequest;
struct PromiseCapability;
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype

View file

@ -241,6 +241,13 @@ public:
ScriptOrModule get_active_script_or_module() const;
Function<ThrowCompletionOr<NonnullRefPtr<Module>>(ScriptOrModule, ModuleRequest const&)> host_resolve_imported_module;
Function<void(ScriptOrModule, ModuleRequest const&, PromiseCapability)> host_import_module_dynamically;
Function<void(ScriptOrModule, ModuleRequest const&, PromiseCapability, Promise*)> host_finish_dynamic_import;
Function<HashMap<PropertyKey, Value>(SourceTextModule const&)> host_get_import_meta_properties;
Function<void(Object*, SourceTextModule const&)> host_finalize_import_meta;
private:
explicit VM(OwnPtr<CustomData>);

View file

@ -4,6 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibJS/Module.h>
#include <LibJS/Runtime/VM.h>
#include <LibWeb/Bindings/MainThreadVM.h>
@ -15,6 +16,10 @@ JS::VM& main_thread_vm()
if (!vm) {
vm = JS::VM::create(make<WebEngineCustomData>());
static_cast<WebEngineCustomData*>(vm->custom_data())->event_loop.set_vm(*vm);
vm->host_resolve_imported_module = [&](JS::ScriptOrModule, JS::ModuleRequest const&) -> JS::ThrowCompletionOr<NonnullRefPtr<JS::Module>> {
return vm->throw_completion<JS::InternalError>(vm->current_realm()->global_object(), JS::ErrorType::NotImplemented, "Modules in the browser");
};
}
return *vm;
}