diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-14 14:41:04 +0800 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2019-04-17 02:44:24 +0800 |
commit | cab1dc5bb346b6c4d0e02e6785715af6ff6fb090 (patch) | |
tree | 9978077693ef273f3d19bf2b4f1a9e1cc9df1582 /src/api | |
parent | c6c37e9e850fa2a30b12a0d0fd0dfe144eda0959 (diff) | |
download | android-node-v8-cab1dc5bb346b6c4d0e02e6785715af6ff6fb090.tar.gz android-node-v8-cab1dc5bb346b6c4d0e02e6785715af6ff6fb090.tar.bz2 android-node-v8-cab1dc5bb346b6c4d0e02e6785715af6ff6fb090.zip |
src: use RAII to manage the main isolate data
This patch encapsulates the main isolate management into a
NodeMainInstance class that manages the resources with RAII
and controls the Isolate::CreateParams (which is necessary
for deserializing snapshots with external references)
PR-URL: https://github.com/nodejs/node/pull/27220
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'src/api')
-rw-r--r-- | src/api/environment.cc | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/api/environment.cc b/src/api/environment.cc index 70228b77d8..0543e0323d 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -169,11 +169,7 @@ void FreeArrayBufferAllocator(ArrayBufferAllocator* allocator) { delete allocator; } -void SetIsolateCreateParams(Isolate::CreateParams* params, - ArrayBufferAllocator* allocator) { - if (allocator != nullptr) - params->array_buffer_allocator = allocator; - +void SetIsolateCreateParamsForNode(Isolate::CreateParams* params) { const uint64_t total_memory = uv_get_total_memory(); if (total_memory > 0) { // V8 defaults to 700MB or 1.4GB on 32 and 64 bit platforms respectively. @@ -204,25 +200,33 @@ Isolate* NewIsolate(ArrayBufferAllocator* allocator, uv_loop_t* event_loop) { return NewIsolate(allocator, event_loop, GetMainThreadMultiIsolatePlatform()); } -Isolate* NewIsolate(ArrayBufferAllocator* allocator, +// TODO(joyeecheung): we may want to expose this, but then we need to be +// careful about what we override in the params. +Isolate* NewIsolate(Isolate::CreateParams* params, 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); + SetIsolateCreateParamsForNode(params); + Isolate::Initialize(isolate, *params); SetIsolateUpForNode(isolate); return isolate; } +Isolate* NewIsolate(ArrayBufferAllocator* allocator, + uv_loop_t* event_loop, + MultiIsolatePlatform* platform) { + Isolate::CreateParams params; + if (allocator != nullptr) params.array_buffer_allocator = allocator; + return NewIsolate(¶ms, event_loop, platform); +} + IsolateData* CreateIsolateData(Isolate* isolate, uv_loop_t* loop, MultiIsolatePlatform* platform, |