mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 07:30:19 +00:00
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:
parent
0b89dbc529
commit
be9d478d92
Notes:
sideshowbarker
2024-07-17 20:28:39 +09:00
Author: https://github.com/davidot Commit: https://github.com/SerenityOS/serenity/commit/be9d478d923 Pull-request: https://github.com/SerenityOS/serenity/pull/11957 Reviewed-by: https://github.com/emanuele6 Reviewed-by: https://github.com/linusg
3 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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>);
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue