summaryrefslogtreecommitdiff
path: root/src/node_main_instance.h
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/node_main_instance.h
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/node_main_instance.h')
-rw-r--r--src/node_main_instance.h48
1 files changed, 42 insertions, 6 deletions
diff --git a/src/node_main_instance.h b/src/node_main_instance.h
index f140edcfd7..0a8be137a0 100644
--- a/src/node_main_instance.h
+++ b/src/node_main_instance.h
@@ -3,6 +3,7 @@
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
+#include <cstddef>
#include "node.h"
#include "util.h"
#include "uv.h"
@@ -14,12 +15,35 @@ namespace node {
// We may be able to create an abstract class to reuse some of the routines.
class NodeMainInstance {
public:
- NodeMainInstance(const NodeMainInstance&) = delete;
- NodeMainInstance& operator=(const NodeMainInstance&) = delete;
- NodeMainInstance(NodeMainInstance&&) = delete;
- NodeMainInstance& operator=(NodeMainInstance&&) = delete;
+ // To create a main instance that does not own the isoalte,
+ // The caller needs to do:
+ //
+ // Isolate* isolate = Isolate::Allocate();
+ // platform->RegisterIsolate(isolate, loop);
+ // isolate->Initialize(...);
+ // isolate->Enter();
+ // NodeMainInstance* main_instance =
+ // NodeMainInstance::Create(isolate, loop, args, exec_args);
+ //
+ // When tearing it down:
+ //
+ // main_instance->Cleanup(); // While the isolate is entered
+ // isolate->Exit();
+ // isolate->Dispose();
+ // platform->UnregisterIsolate(isolate);
+ //
+ // After calling Dispose() the main_instance is no longer accessible.
+ static NodeMainInstance* Create(v8::Isolate* isolate,
+ uv_loop_t* event_loop,
+ MultiIsolatePlatform* platform,
+ const std::vector<std::string>& args,
+ const std::vector<std::string>& exec_args);
+ void Dispose();
- NodeMainInstance(uv_loop_t* event_loop,
+ // Create a main instance that owns the isolate
+ NodeMainInstance(v8::Isolate::CreateParams* params,
+ uv_loop_t* event_loop,
+ MultiIsolatePlatform* platform,
const std::vector<std::string>& args,
const std::vector<std::string>& exec_args);
~NodeMainInstance();
@@ -27,16 +51,28 @@ class NodeMainInstance {
// Start running the Node.js instances, return the exit code when finished.
int Run();
- private:
// TODO(joyeecheung): align this with the CreateEnvironment exposed in node.h
// and the environment creation routine in workers somehow.
std::unique_ptr<Environment> CreateMainEnvironment(int* exit_code);
+ private:
+ NodeMainInstance(const NodeMainInstance&) = delete;
+ NodeMainInstance& operator=(const NodeMainInstance&) = delete;
+ NodeMainInstance(NodeMainInstance&&) = delete;
+ NodeMainInstance& operator=(NodeMainInstance&&) = delete;
+
+ NodeMainInstance(v8::Isolate* isolate,
+ uv_loop_t* event_loop,
+ MultiIsolatePlatform* platform,
+ const std::vector<std::string>& args,
+ const std::vector<std::string>& exec_args);
std::vector<std::string> args_;
std::vector<std::string> exec_args_;
std::unique_ptr<ArrayBufferAllocator> array_buffer_allocator_;
v8::Isolate* isolate_;
+ MultiIsolatePlatform* platform_;
std::unique_ptr<IsolateData> isolate_data_;
+ bool owns_isolate_ = false;
};
} // namespace node