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 b8b20d8c8340c63bd3039a0683446ef1eb4fdf0d..a0781bd3817c2e0d4be37835f0c02063b2e548f1 100644 --- a/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc +++ b/third_party/blink/renderer/bindings/core/v8/v8_initializer.cc @@ -606,7 +606,9 @@ bool JavaScriptCompileHintsMagicEnabledCallback( execution_context); } -v8::MaybeLocal HostImportModuleDynamically( +} + +v8::MaybeLocal V8Initializer::HostImportModuleDynamically( v8::Local context, v8::Local v8_host_defined_options, v8::Local v8_referrer_resource_url, @@ -672,7 +674,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) { ScriptState* script_state = ScriptState::From(context); @@ -699,6 +701,8 @@ void HostGetImportMetaProperties(v8::Local context, meta->CreateDataProperty(context, resolve_key, resolve_value).ToChecked(); } +namespace { + void InitializeV8Common(v8::Isolate* isolate) { // Set up garbage collection before setting up anything else as V8 may trigger // GCs during Blink setup. @@ -718,9 +722,9 @@ void InitializeV8Common(v8::Isolate* isolate) { SharedArrayBufferConstructorEnabledCallback); isolate->SetJavaScriptCompileHintsMagicEnabledCallback( JavaScriptCompileHintsMagicEnabledCallback); - isolate->SetHostImportModuleDynamicallyCallback(HostImportModuleDynamically); + isolate->SetHostImportModuleDynamicallyCallback(V8Initializer::HostImportModuleDynamically); isolate->SetHostInitializeImportMetaObjectCallback( - HostGetImportMetaProperties); + V8Initializer::HostGetImportMetaProperties); isolate->SetMetricsRecorder(std::make_shared(isolate)); V8ContextSnapshot::EnsureInterfaceTemplates(isolate); 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 30a36cf16d4a8f4692ec6a13be1217212390172a..1924f7cef7f5a1f7523c00071639a6c72f9cca70 100644 --- a/third_party/blink/renderer/bindings/core/v8/v8_initializer.h +++ b/third_party/blink/renderer/bindings/core/v8/v8_initializer.h @@ -77,6 +77,17 @@ class CORE_EXPORT V8Initializer { v8::Local context, v8::Local source); + 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,