mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:07:35 +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
3 changed files with 14 additions and 0 deletions
|
@ -170,6 +170,7 @@ class Script;
|
||||||
class Shape;
|
class Shape;
|
||||||
class Statement;
|
class Statement;
|
||||||
class StringOrSymbol;
|
class StringOrSymbol;
|
||||||
|
class SourceTextModule;
|
||||||
class Symbol;
|
class Symbol;
|
||||||
class Token;
|
class Token;
|
||||||
class Utf16String;
|
class Utf16String;
|
||||||
|
@ -180,6 +181,7 @@ class WrappedFunction;
|
||||||
enum class DeclarationKind;
|
enum class DeclarationKind;
|
||||||
struct AlreadyResolved;
|
struct AlreadyResolved;
|
||||||
struct JobCallback;
|
struct JobCallback;
|
||||||
|
struct ModuleRequest;
|
||||||
struct PromiseCapability;
|
struct PromiseCapability;
|
||||||
|
|
||||||
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
|
// Not included in JS_ENUMERATE_NATIVE_OBJECTS due to missing distinct prototype
|
||||||
|
|
|
@ -241,6 +241,13 @@ public:
|
||||||
|
|
||||||
ScriptOrModule get_active_script_or_module() const;
|
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:
|
private:
|
||||||
explicit VM(OwnPtr<CustomData>);
|
explicit VM(OwnPtr<CustomData>);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
* SPDX-License-Identifier: BSD-2-Clause
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <LibJS/Module.h>
|
||||||
#include <LibJS/Runtime/VM.h>
|
#include <LibJS/Runtime/VM.h>
|
||||||
#include <LibWeb/Bindings/MainThreadVM.h>
|
#include <LibWeb/Bindings/MainThreadVM.h>
|
||||||
|
|
||||||
|
@ -15,6 +16,10 @@ JS::VM& main_thread_vm()
|
||||||
if (!vm) {
|
if (!vm) {
|
||||||
vm = JS::VM::create(make<WebEngineCustomData>());
|
vm = JS::VM::create(make<WebEngineCustomData>());
|
||||||
static_cast<WebEngineCustomData*>(vm->custom_data())->event_loop.set_vm(*vm);
|
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;
|
return *vm;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue