Commit a2cbab1b authored by jan.krems's avatar jan.krems Committed by Commit bot

[api] Expose Isolate::SetHostImportModuleDynamicallyCallback

This allows embedders to delay initialization of the module system until after
the isolate was created.

BUG=v8:6428
R=gsathya@chromium.org

Review-Url: https://codereview.chromium.org/2897103002
Cr-Commit-Position: refs/heads/master@{#45546}
parent c05ca9d7
......@@ -6620,8 +6620,7 @@ class V8_EXPORT Isolate {
add_histogram_sample_callback(nullptr),
array_buffer_allocator(nullptr),
external_references(nullptr),
allow_atomics_wait(true),
host_import_module_dynamically_callback_(nullptr) {}
allow_atomics_wait(true) {}
/**
* The optional entry_hook allows the host application to provide the
......@@ -6684,16 +6683,6 @@ class V8_EXPORT Isolate {
* this isolate. This can also be configured via SetAllowAtomicsWait.
*/
bool allow_atomics_wait;
/**
* This is an unfinished experimental feature, and is only exposed
* here for internal testing purposes. DO NOT USE.
*
* This specifies the callback called by the upcoming dynamic
* import() language feature to load modules.
*/
HostImportModuleDynamicallyCallback
host_import_module_dynamically_callback_;
};
......@@ -6884,6 +6873,16 @@ class V8_EXPORT Isolate {
void SetAbortOnUncaughtExceptionCallback(
AbortOnUncaughtExceptionCallback callback);
/**
* This is an unfinished experimental feature, and is only exposed
* here for internal testing purposes. DO NOT USE.
*
* This specifies the callback called by the upcoming dynamic
* import() language feature to load modules.
*/
void SetHostImportModuleDynamicallyCallback(
HostImportModuleDynamicallyCallback callback);
/**
* Optional notification that the system is running low on memory.
* V8 uses these notifications to guide heuristics.
......
......@@ -8343,11 +8343,6 @@ Isolate* IsolateNewImpl(internal::Isolate* isolate,
isolate->set_api_external_references(params.external_references);
isolate->set_allow_atomics_wait(params.allow_atomics_wait);
if (params.host_import_module_dynamically_callback_ != nullptr) {
isolate->SetHostImportModuleDynamicallyCallback(
params.host_import_module_dynamically_callback_);
}
SetResourceConstraints(isolate, params.constraints);
// TODO(jochen): Once we got rid of Isolate::Current(), we can remove this.
Isolate::Scope isolate_scope(v8_isolate);
......@@ -8397,6 +8392,11 @@ void Isolate::SetAbortOnUncaughtExceptionCallback(
isolate->SetAbortOnUncaughtExceptionCallback(callback);
}
void Isolate::SetHostImportModuleDynamicallyCallback(
HostImportModuleDynamicallyCallback callback) {
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(this);
isolate->SetHostImportModuleDynamicallyCallback(callback);
}
Isolate::DisallowJavascriptExecutionScope::DisallowJavascriptExecutionScope(
Isolate* isolate,
......
......@@ -481,9 +481,9 @@ ScriptCompiler::CachedData* CompileForCachedData(
}
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
create_params.host_import_module_dynamically_callback_ =
Shell::HostImportModuleDynamically;
Isolate* temp_isolate = Isolate::New(create_params);
temp_isolate->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
ScriptCompiler::CachedData* result = NULL;
{
Isolate::Scope isolate_scope(temp_isolate);
......@@ -2313,9 +2313,9 @@ base::Thread::Options SourceGroup::GetThreadOptions() {
void SourceGroup::ExecuteInThread() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
create_params.host_import_module_dynamically_callback_ =
Shell::HostImportModuleDynamically;
Isolate* isolate = Isolate::New(create_params);
isolate->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
Shell::EnsureEventLoopInitialized(isolate);
D8Console console(isolate);
......@@ -2458,9 +2458,9 @@ void Worker::WaitForThread() {
void Worker::ExecuteInThread() {
Isolate::CreateParams create_params;
create_params.array_buffer_allocator = Shell::array_buffer_allocator;
create_params.host_import_module_dynamically_callback_ =
Shell::HostImportModuleDynamically;
Isolate* isolate = Isolate::New(create_params);
isolate->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
D8Console console(isolate);
debug::SetConsoleDelegate(isolate, &console);
{
......@@ -3107,9 +3107,6 @@ int Shell::Main(int argc, char* argv[]) {
create_params.add_histogram_sample_callback = AddHistogramSample;
}
create_params.host_import_module_dynamically_callback_ =
Shell::HostImportModuleDynamically;
if (i::trap_handler::UseTrapHandler()) {
if (!v8::V8::RegisterDefaultSignalHandler()) {
fprintf(stderr, "Could not register signal handler");
......@@ -3118,6 +3115,8 @@ int Shell::Main(int argc, char* argv[]) {
}
Isolate* isolate = Isolate::New(create_params);
isolate->SetHostImportModuleDynamicallyCallback(
Shell::HostImportModuleDynamically);
D8Console console(isolate);
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment