|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Shelley Vohr < [email protected]> |
| 3 | +Date: Mon, 5 Oct 2020 16:05:45 -0700 |
| 4 | +Subject: chore: expose v8 initialization isolate callbacks |
| 5 | + |
| 6 | +Exposes v8 initializer callbacks to Electron so that we can call them |
| 7 | +directly. We expand upon and adapt their behavior, so allows us to |
| 8 | +ensure that we stay in sync with Node.js default behavior. |
| 9 | + |
| 10 | +This will be upstreamed. |
| 11 | + |
| 12 | +diff --git a/src/api/environment.cc b/src/api/environment.cc |
| 13 | +index cf6115d04ba3c184937c5db85c9d7ebc78ed3db7..a8ee97729858b40179e6bce58cfbacf1a6980340 100644 |
| 14 | +--- a/src/api/environment.cc |
| 15 | ++++ b/src/api/environment.cc |
| 16 | +@@ -30,14 +30,16 @@ using v8::PropertyDescriptor; |
| 17 | + using v8::String; |
| 18 | + using v8::Value; |
| 19 | + |
| 20 | +-static bool AllowWasmCodeGenerationCallback(Local<Context> context, |
| 21 | ++// static |
| 22 | ++bool Environment::AllowWasmCodeGenerationCallback(Local<Context> context, |
| 23 | + Local<String>) { |
| 24 | + Local<Value> wasm_code_gen = |
| 25 | + context->GetEmbedderData(ContextEmbedderIndex::kAllowWasmCodeGeneration); |
| 26 | + return wasm_code_gen->IsUndefined() || wasm_code_gen->IsTrue(); |
| 27 | + } |
| 28 | + |
| 29 | +-static bool ShouldAbortOnUncaughtException(Isolate* isolate) { |
| 30 | ++// static |
| 31 | ++bool Environment::ShouldAbortOnUncaughtException(Isolate* isolate) { |
| 32 | + DebugSealHandleScope scope(isolate); |
| 33 | + Environment* env = Environment::GetCurrent(isolate); |
| 34 | + return env != nullptr && |
| 35 | +@@ -47,7 +49,8 @@ static bool ShouldAbortOnUncaughtException(Isolate* isolate) { |
| 36 | + !env->inside_should_not_abort_on_uncaught_scope(); |
| 37 | + } |
| 38 | + |
| 39 | +-static MaybeLocal<Value> PrepareStackTraceCallback(Local<Context> context, |
| 40 | ++// static |
| 41 | ++MaybeLocal<Value> Environment::PrepareStackTraceCallback(Local<Context> context, |
| 42 | + Local<Value> exception, |
| 43 | + Local<Array> trace) { |
| 44 | + Environment* env = Environment::GetCurrent(context); |
| 45 | +@@ -221,7 +224,7 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) { |
| 46 | + |
| 47 | + auto* abort_callback = s.should_abort_on_uncaught_exception_callback ? |
| 48 | + s.should_abort_on_uncaught_exception_callback : |
| 49 | +- ShouldAbortOnUncaughtException; |
| 50 | ++ Environment::ShouldAbortOnUncaughtException; |
| 51 | + isolate->SetAbortOnUncaughtExceptionCallback(abort_callback); |
| 52 | + |
| 53 | + auto* fatal_error_cb = s.fatal_error_callback ? |
| 54 | +@@ -229,7 +232,7 @@ void SetIsolateErrorHandlers(v8::Isolate* isolate, const IsolateSettings& s) { |
| 55 | + isolate->SetFatalErrorHandler(fatal_error_cb); |
| 56 | + |
| 57 | + auto* prepare_stack_trace_cb = s.prepare_stack_trace_callback ? |
| 58 | +- s.prepare_stack_trace_callback : PrepareStackTraceCallback; |
| 59 | ++ s.prepare_stack_trace_callback : Environment::PrepareStackTraceCallback; |
| 60 | + isolate->SetPrepareStackTraceCallback(prepare_stack_trace_cb); |
| 61 | + } |
| 62 | + |
| 63 | +@@ -237,7 +240,7 @@ void SetIsolateMiscHandlers(v8::Isolate* isolate, const IsolateSettings& s) { |
| 64 | + isolate->SetMicrotasksPolicy(s.policy); |
| 65 | + |
| 66 | + auto* allow_wasm_codegen_cb = s.allow_wasm_code_generation_callback ? |
| 67 | +- s.allow_wasm_code_generation_callback : AllowWasmCodeGenerationCallback; |
| 68 | ++ s.allow_wasm_code_generation_callback : Environment::AllowWasmCodeGenerationCallback; |
| 69 | + isolate->SetAllowWasmCodeGenerationCallback(allow_wasm_codegen_cb); |
| 70 | + |
| 71 | + if ((s.flags & SHOULD_NOT_SET_PROMISE_REJECTION_CALLBACK) == 0) { |
| 72 | +diff --git a/src/env.h b/src/env.h |
| 73 | +index 4fe2eb3b7699efcab87c377743a955effbbfd9de..2bb196d199bd9b6c27d9de8ca7e5a9bffad0c788 100644 |
| 74 | +--- a/src/env.h |
| 75 | ++++ b/src/env.h |
| 76 | +@@ -904,6 +904,13 @@ class Environment : public MemoryRetainer { |
| 77 | + void Exit(int code); |
| 78 | + void ExitEnv(); |
| 79 | + |
| 80 | ++ static bool AllowWasmCodeGenerationCallback(v8::Local<v8::Context> context, |
| 81 | ++ v8::Local<v8::String>); |
| 82 | ++ static bool ShouldAbortOnUncaughtException(v8::Isolate* isolate); |
| 83 | ++ static v8::MaybeLocal<v8::Value> PrepareStackTraceCallback(v8::Local<v8::Context> context, |
| 84 | ++ v8::Local<v8::Value> exception, |
| 85 | ++ v8::Local<v8::Array> trace); |
| 86 | ++ |
| 87 | + // Register clean-up cb to be called on environment destruction. |
| 88 | + inline void RegisterHandleCleanup(uv_handle_t* handle, |
| 89 | + HandleCleanupCb cb, |
0 commit comments