summaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorJoyee Cheung <joyeec9h3@gmail.com>2019-04-19 12:50:38 +0800
committerJoyee Cheung <joyeec9h3@gmail.com>2019-04-23 11:25:56 +0800
commit70d887e95717a6b89135bf5cfd7b6394f451abe7 (patch)
treebf48961163bca1c6b3863b703ecca00b1af30731 /src/api
parentd66c7e347042053740ef8cd54b7ea76eb4de53d5 (diff)
downloadandroid-node-v8-70d887e95717a6b89135bf5cfd7b6394f451abe7.tar.gz
android-node-v8-70d887e95717a6b89135bf5cfd7b6394f451abe7.tar.bz2
android-node-v8-70d887e95717a6b89135bf5cfd7b6394f451abe7.zip
src: allow creating NodeMainInstance that does not own the isolate
Allows instantiating a NodeMainInstance with an isolate whose initialization and disposal are controlled by the caller. PR-URL: https://github.com/nodejs/node/pull/27321 Refs: https://github.com/nodejs/node/issues/17058 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/api')
-rw-r--r--src/api/environment.cc36
1 files changed, 26 insertions, 10 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc
index 0543e0323d..9a29ad1e5e 100644
--- a/src/api/environment.cc
+++ b/src/api/environment.cc
@@ -183,17 +183,33 @@ void SetIsolateCreateParamsForNode(Isolate::CreateParams* params) {
#endif
}
+void SetIsolateUpForNode(v8::Isolate* isolate, IsolateSettingCategories cat) {
+ switch (cat) {
+ case IsolateSettingCategories::kErrorHandlers:
+ isolate->AddMessageListenerWithErrorLevel(
+ OnMessage,
+ Isolate::MessageErrorLevel::kMessageError |
+ Isolate::MessageErrorLevel::kMessageWarning);
+ isolate->SetAbortOnUncaughtExceptionCallback(
+ ShouldAbortOnUncaughtException);
+ isolate->SetFatalErrorHandler(OnFatalError);
+ break;
+ case IsolateSettingCategories::kMisc:
+ isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit);
+ isolate->SetAllowWasmCodeGenerationCallback(
+ AllowWasmCodeGenerationCallback);
+ isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback);
+ v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
+ break;
+ default:
+ UNREACHABLE();
+ break;
+ }
+}
+
void SetIsolateUpForNode(v8::Isolate* isolate) {
- isolate->AddMessageListenerWithErrorLevel(
- OnMessage,
- Isolate::MessageErrorLevel::kMessageError |
- Isolate::MessageErrorLevel::kMessageWarning);
- isolate->SetAbortOnUncaughtExceptionCallback(ShouldAbortOnUncaughtException);
- isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit);
- isolate->SetFatalErrorHandler(OnFatalError);
- isolate->SetAllowWasmCodeGenerationCallback(AllowWasmCodeGenerationCallback);
- isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback);
- v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate);
+ SetIsolateUpForNode(isolate, IsolateSettingCategories::kErrorHandlers);
+ SetIsolateUpForNode(isolate, IsolateSettingCategories::kMisc);
}
Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) {