diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-03-08 16:55:40 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-03-13 09:14:16 +0000 |
commit | b21e7c7bcf23a2715951e4cd96180e4dbf1dcd4d (patch) | |
tree | 42050dbd0723b12a1884a9a53ca2da65e3a4653d /src/api/environment.cc | |
parent | 0e3adddd0d6e5d90b5224c62ef26b561320d1cff (diff) | |
download | android-node-v8-b21e7c7bcf23a2715951e4cd96180e4dbf1dcd4d.tar.gz android-node-v8-b21e7c7bcf23a2715951e4cd96180e4dbf1dcd4d.tar.bz2 android-node-v8-b21e7c7bcf23a2715951e4cd96180e4dbf1dcd4d.zip |
embedding: make `NewIsolate()` API more flexible
Split the API up into its essential parts, namely setting up
the creation parameters for the Isolate, creating it, and performing
Node.js-specific customization afterwards.
PR-URL: https://github.com/nodejs/node/pull/26525
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Diffstat (limited to 'src/api/environment.cc')
-rw-r--r-- | src/api/environment.cc | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc index 421735a82a..9b8e468685 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -161,30 +161,25 @@ void FreeArrayBufferAllocator(ArrayBufferAllocator* allocator) { delete allocator; } -Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { - Isolate::CreateParams params; - params.array_buffer_allocator = allocator; +void SetIsolateCreateParams(Isolate::CreateParams* params, + ArrayBufferAllocator* allocator) { + if (allocator != nullptr) + params->array_buffer_allocator = allocator; double total_memory = uv_get_total_memory(); if (total_memory > 0) { // V8 defaults to 700MB or 1.4GB on 32 and 64 bit platforms respectively. // This default is based on browser use-cases. Tell V8 to configure the // heap based on the actual physical memory. - params.constraints.ConfigureDefaults(total_memory, 0); + params->constraints.ConfigureDefaults(total_memory, 0); } #ifdef NODE_ENABLE_VTUNE_PROFILING - params.code_event_handler = vTune::GetVtuneCodeEventHandler(); + params->code_event_handler = vTune::GetVtuneCodeEventHandler(); #endif +} - Isolate* isolate = Isolate::Allocate(); - if (isolate == nullptr) return nullptr; - - // Register the isolate on the platform before the isolate gets initialized, - // so that the isolate can access the platform during initialization. - per_process::v8_platform.Platform()->RegisterIsolate(isolate, event_loop); - Isolate::Initialize(isolate, params); - +void SetIsolateUpForNode(v8::Isolate* isolate) { isolate->AddMessageListenerWithErrorLevel( OnMessage, Isolate::MessageErrorLevel::kMessageError | @@ -193,7 +188,29 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { isolate->SetMicrotasksPolicy(MicrotasksPolicy::kExplicit); isolate->SetFatalErrorHandler(OnFatalError); isolate->SetAllowWasmCodeGenerationCallback(AllowWasmCodeGenerationCallback); + isolate->SetPromiseRejectCallback(task_queue::PromiseRejectCallback); v8::CpuProfiler::UseDetailedSourcePositionsForProfiling(isolate); +} + +Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { + return NewIsolate(allocator, event_loop, GetMainThreadMultiIsolatePlatform()); +} + +Isolate* NewIsolate(ArrayBufferAllocator* allocator, + uv_loop_t* event_loop, + MultiIsolatePlatform* platform) { + Isolate::CreateParams params; + SetIsolateCreateParams(¶ms, allocator); + + Isolate* isolate = Isolate::Allocate(); + if (isolate == nullptr) return nullptr; + + // Register the isolate on the platform before the isolate gets initialized, + // so that the isolate can access the platform during initialization. + platform->RegisterIsolate(isolate, event_loop); + Isolate::Initialize(isolate, params); + + SetIsolateUpForNode(isolate); return isolate; } |