|
@@ -0,0 +1,89 @@
|
|
|
+From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
|
+From: Shelley Vohr <[email protected]>
|
|
|
+Date: Mon, 5 Oct 2020 16:05:45 -0700
|
|
|
+Subject: chore: expose v8 initialization isolate callbacks
|
|
|
+
|
|
|
+Exposes v8 initializer callbacks to Electron so that we can call them
|
|
|
+directly. We expand upon and adapt their behavior, so allows us to
|
|
|
+ensure that we stay in sync with Node.js default behavior.
|
|
|
+
|
|
|
+This will be upstreamed.
|
|
|
+
|
|
|
+diff --git a/src/api/environment.cc b/src/api/environment.cc
|
|
|
+index cf6115d04ba3c184937c5db85c9d7ebc78ed3db7..a8ee97729858b40179e6bce58cfbacf1a6980340 100644
|
|
|
+--- a/src/api/environment.cc
|
|
|
++++ b/src/api/environment.cc
|
|
|
+@@ -30,14 +30,16 @@ using v8::PropertyDescriptor;
|
|
|
+ using v8::String;
|
|
|
+ using v8::Value;
|
|
|
+
|
|
|
+-static bool AllowWasmCodeGenerationCallback(Local<Context> context,
|
|
|
++// static
|
|
|
++bool Environment::AllowWasmCodeGenerationCallback(Local<Context> context,
|
|
|
+ Local<String>) {
|
|
|
+ Local<Value> wasm_code_gen =
|
|
|
+ context->GetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration);
|
|
|
+ return wasm_code_gen->IsUndefined() || wasm_code_gen->IsTrue();
|
|
|
+ }
|
|
|
+
|
|
|
+-static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
|
|
|
++// static
|
|
|
++bool Environment::ShouldAbortOnUncaughtException(Isolate* isolate) {
|
|
|
+ DebugSealHandleScope scope(isolate);
|
|
|
+ Environment* env = Environment::GetCurrent(isolate);
|
|
|
+ return env != nullptr &&
|
|
|
+@@ -47,7 +49,8 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) {
|
|
|
+ !env->inside_should_not_abort_on_uncaught_scope();
|
|
|
+ }
|
|
|
+
|
|
|
+-static MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context,
|
|
|
++// static
|
|
|
++MaybeLocal<Value> Environment::PrepareStackTraceCallback(Local<Context> context,
|
|
|
+ Local<Value> exception,
|
|
|
+ Local<Array> trace) {
|
|
|
+ Environment* env = Environment::GetCurrent(context);
|
|
|
+@@ -221,7 +224,7 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
|
|
|
+
|
|
|
+ auto* abort_callback = s.should_abort_on_uncaught_exception_callback ?
|
|
|
+ s.should_abort_on_uncaught_exception_callback :
|
|
|
+- ShouldAbortOnUncaughtException;
|
|
|
++ Environment::ShouldAbortOnUncaughtException;
|
|
|
+ isolate->SetAbortOnUncaughtExceptionCallback(abort_callback);
|
|
|
+
|
|
|
+ auto* fatal_error_cb = s.fatal_error_callback ?
|
|
|
+@@ -229,7 +232,7 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
|
|
|
+ isolate->SetFatalErrorHandler(fatal_error_cb);
|
|
|
+
|
|
|
+ auto* prepare_stack_trace_cb = s.prepare_stack_trace_callback ?
|
|
|
+- s.prepare_stack_trace_callback : PrepareStackTraceCallback;
|
|
|
++ s.prepare_stack_trace_callback : Environment::PrepareStackTraceCallback;
|
|
|
+ isolate->SetPrepareStackTraceCallback(prepare_stack_trace_cb);
|
|
|
+ }
|
|
|
+
|
|
|
+@@ -237,7 +240,7 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) {
|
|
|
+ isolate->SetMicrotasksPolicy(s.policy);
|
|
|
+
|
|
|
+ auto* allow_wasm_codegen_cb = s.allow_wasm_code_generation_callback ?
|
|
|
+- s.allow_wasm_code_generation_callback : AllowWasmCodeGenerationCallback;
|
|
|
++ s.allow_wasm_code_generation_callback : Environment::AllowWasmCodeGenerationCallback;
|
|
|
+ isolate->SetAllowWasmCodeGenerationCallback(allow_wasm_codegen_cb);
|
|
|
+
|
|
|
+ if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) {
|
|
|
+diff --git a/src/env.h b/src/env.h
|
|
|
+index 4fe2eb3b7699efcab87c377743a955effbbfd9de..2bb196d199bd9b6c27d9de8ca7e5a9bffad0c788 100644
|
|
|
+--- a/src/env.h
|
|
|
++++ b/src/env.h
|
|
|
+@@ -904,6 +904,13 @@ class Environment : public MemoryRetainer {
|
|
|
+ void Exit(int code);
|
|
|
+ void ExitEnv();
|
|
|
+
|
|
|
++ static bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context,
|
|
|
++ v8::Local<v8::String>);
|
|
|
++ static bool ShouldAbortOnUncaughtException(v8::Isolate* isolate);
|
|
|
++ static v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(v8::Local<v8::Context> context,
|
|
|
++ v8::Local<v8::Value> exception,
|
|
|
++ v8::Local<v8::Array> trace);
|
|
|
++
|
|
|
+ // Register clean-up cb to be called on environment destruction.
|
|
|
+ inline void RegisterHandleCleanup(uv_handle_t* handle,
|
|
|
+ HandleCleanupCb cb,
|