MainThreadVM.cpp 795 B

123456789101112131415161718192021222324252627
  1. /*
  2. * Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibJS/Module.h>
  7. #include <LibJS/Runtime/VM.h>
  8. #include <LibWeb/Bindings/MainThreadVM.h>
  9. namespace Web::Bindings {
  10. JS::VM& main_thread_vm()
  11. {
  12. static RefPtr<JS::VM> vm;
  13. if (!vm) {
  14. vm = JS::VM::create(make<WebEngineCustomData>());
  15. static_cast<WebEngineCustomData*>(vm->custom_data())->event_loop.set_vm(*vm);
  16. vm->host_resolve_imported_module = [&](JS::ScriptOrModule, JS::ModuleRequest const&) -> JS::ThrowCompletionOr<NonnullRefPtr<JS::Module>> {
  17. return vm->throw_completion<JS::InternalError>(vm->current_realm()->global_object(), JS::ErrorType::NotImplemented, "Modules in the browser");
  18. };
  19. }
  20. return *vm;
  21. }
  22. }