From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 8 Mar 2023 13:04:21 -0800 Subject: refactor: expose HostImportModuleDynamically and HostGetImportMetaProperties to embedders This is so that Electron can blend Blink's and Node's implementations of these isolate handlers. diff --git a/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc b/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc index b2144b96a5ebcf16811756f8f9dff7d7625faee7..061cde41e69265871b8237c11ebd4c7323616c5f 100644 --- a/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc +++ b/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc @@ -623,7 +623,9 @@ bool WasmJSPromiseIntegrationEnabledCallback(v8::Local context) { execution_context); } -v8::MaybeLocal HostImportModuleDynamically( +} + +v8::MaybeLocal V8Initializer::HostImportModuleDynamically( v8::Local context, v8::Local v8_host_defined_options, v8::Local v8_referrer_resource_url, @@ -701,7 +703,7 @@ v8::MaybeLocal HostImportModuleDynamically( } // https://html.spec.whatwg.org/C/#hostgetimportmetaproperties -void HostGetImportMetaProperties(v8::Local context, +void V8Initializer::HostGetImportMetaProperties(v8::Local context, v8::Local module, v8::Local meta) { v8::Isolate* isolate = context->GetIsolate(); @@ -744,9 +746,6 @@ std::ostream& operator<<(std::ostream& os, const PrintV8OOM& oom_details) { return os; } -} // namespace - -// static void V8Initializer::InitializeV8Common(v8::Isolate* isolate) { // Set up garbage collection before setting up anything else as V8 may trigger // GCs during Blink setup. @@ -766,9 +765,9 @@ void V8Initializer::InitializeV8Common(v8::Isolate* isolate) { isolate->SetWasmJSPIEnabledCallback(WasmJSPromiseIntegrationEnabledCallback); isolate->SetSharedArrayBufferConstructorEnabledCallback( SharedArrayBufferConstructorEnabledCallback); - isolate->SetHostImportModuleDynamicallyCallback(HostImportModuleDynamically); + isolate->SetHostImportModuleDynamicallyCallback(V8Initializer::HostImportModuleDynamically); isolate->SetHostInitializeImportMetaObjectCallback( - HostGetImportMetaProperties); + V8Initializer::HostGetImportMetaProperties); isolate->SetMetricsRecorder(std::make_shared(isolate)); #if BUILDFLAG(IS_WIN) diff --git a/third_party/blink/renderer/bindings/core/v8/v8_initializer.h b/third_party/blink/renderer/bindings/core/v8/v8_initializer.h index 2e0fd8cdef733677f8e1d32b3d8e0c635e0a5052..1df4517f9b5926c1dc5333aa6fc9cc1290256c70 100644 --- a/third_party/blink/renderer/bindings/core/v8/v8_initializer.h +++ b/third_party/blink/renderer/bindings/core/v8/v8_initializer.h @@ -84,6 +84,17 @@ class CORE_EXPORT V8Initializer { v8::Local data); static void PromiseRejectHandlerInMainThread(v8::PromiseRejectMessage data); + static v8::MaybeLocal HostImportModuleDynamically( + v8::Local context, + v8::Local v8_host_defined_options, + v8::Local v8_referrer_resource_url, + v8::Local v8_specifier, + v8::Local v8_import_assertions); + + static void HostGetImportMetaProperties(v8::Local context, + v8::Local module, + v8::Local meta); + static void WasmAsyncResolvePromiseCallback( v8::Isolate* isolate, v8::Local context,