fix: isolate callbacks in node_bindings (#23261)
* fix: isolate callbacks in node_bindings * clarify microtask policy comment
This commit is contained in:
parent
e5fe81ac15
commit
979c291847
2 changed files with 41 additions and 5 deletions
|
@ -164,7 +164,7 @@ int NodeMain(int argc, char* argv[]) {
|
||||||
exec_argc, exec_argv);
|
exec_argc, exec_argv);
|
||||||
CHECK_NE(nullptr, env);
|
CHECK_NE(nullptr, env);
|
||||||
|
|
||||||
// TODO(codebytere): we shouldn't have to call this - upstream?
|
// This needs to be called before the inspector is initialized.
|
||||||
env->InitializeDiagnostics();
|
env->InitializeDiagnostics();
|
||||||
|
|
||||||
// This is needed in order to enable v8 host weakref hooks.
|
// This is needed in order to enable v8 host weakref hooks.
|
||||||
|
|
|
@ -219,6 +219,23 @@ void SetNodeOptions(base::Environment* env) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void HostCleanupFinalizationGroupCallback(
|
||||||
|
v8::Local<v8::Context> context,
|
||||||
|
v8::Local<v8::FinalizationGroup> group) {
|
||||||
|
node::Environment* env = node::Environment::GetCurrent(context);
|
||||||
|
if (env == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
env->RegisterFinalizationGroupForCleanup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
|
||||||
|
v8::Local<v8::String>) {
|
||||||
|
v8::Local<v8::Value> wasm_code_gen = context->GetEmbedderData(
|
||||||
|
node::ContextEmbedderIndex::kAllowWasmCodeGeneration);
|
||||||
|
return wasm_code_gen->IsUndefined() || wasm_code_gen->IsTrue();
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
namespace electron {
|
namespace electron {
|
||||||
|
@ -394,15 +411,34 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (browser_env_ == BrowserEnvironment::BROWSER) {
|
if (browser_env_ == BrowserEnvironment::BROWSER) {
|
||||||
// SetAutorunMicrotasks is no longer called in node::CreateEnvironment
|
// This policy requires that microtask checkpoints be explicitly invoked.
|
||||||
// so instead call it here to match expected node behavior
|
// Node.js requires this.
|
||||||
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);
|
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);
|
||||||
} else {
|
} else {
|
||||||
// Node uses the deprecated SetAutorunMicrotasks(false) mode, we should
|
// Match Blink's behavior by allowing microtasks invocation to be controlled
|
||||||
// switch to use the scoped policy to match blink's behavior.
|
// by MicrotasksScope objects.
|
||||||
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
|
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This needs to be called before the inspector is initialized.
|
||||||
|
env->InitializeDiagnostics();
|
||||||
|
|
||||||
|
// Ensure that WeakRefs work properly by specifying the callback to be called
|
||||||
|
// when FinalizationRegistries are ready to be cleaned up and require
|
||||||
|
// FinalizationGroup::Cleanup() to be called in a future task.
|
||||||
|
context->GetIsolate()->SetHostCleanupFinalizationGroupCallback(
|
||||||
|
HostCleanupFinalizationGroupCallback);
|
||||||
|
|
||||||
|
// Set the callback to invoke to check if wasm code generation should be
|
||||||
|
// allowed.
|
||||||
|
context->GetIsolate()->SetAllowWasmCodeGenerationCallback(
|
||||||
|
AllowWasmCodeGenerationCallback);
|
||||||
|
|
||||||
|
// Generate more detailed source positions to code objects. This results in
|
||||||
|
// better results when mapping profiling samples to script source.
|
||||||
|
v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(
|
||||||
|
context->GetIsolate());
|
||||||
|
|
||||||
gin_helper::Dictionary process(context->GetIsolate(), env->process_object());
|
gin_helper::Dictionary process(context->GetIsolate(), env->process_object());
|
||||||
process.SetReadOnly("type", process_type);
|
process.SetReadOnly("type", process_type);
|
||||||
process.Set("resourcesPath", resources_path);
|
process.Set("resourcesPath", resources_path);
|
||||||
|
|
Loading…
Reference in a new issue