From 9b84ee64801dadc826c3d1f2e5063aeeeafd561e Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 27 Feb 2020 21:13:59 -0800 Subject: [PATCH] src: add ability to look up platform based on `Environment*` This should eventually remove any necessity to use the global-state `GetMainThreadMultiIsolatePlatform()`. Backport-PR-URL: https://github.com/nodejs/node/pull/35241 PR-URL: https://github.com/nodejs/node/pull/30467 Reviewed-By: James M Snell Reviewed-By: Gireesh Punathil --- src/api/environment.cc | 8 ++++++++ src/node.h | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/api/environment.cc b/src/api/environment.cc index 81be9f7dfea..a4b688dde7e 100644 --- a/src/api/environment.cc +++ b/src/api/environment.cc @@ -474,6 +474,14 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() { return per_process::v8_platform.Platform(); } +MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env) { + return GetMultiIsolatePlatform(env->isolate_data()); +} + +MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env) { + return env->platform(); +} + MultiIsolatePlatform* CreatePlatform( int thread_pool_size, node::tracing::TracingController* tracing_controller) { diff --git a/src/node.h b/src/node.h index 7a8709f7d62..023e60dafd6 100644 --- a/src/node.h +++ b/src/node.h @@ -456,9 +456,14 @@ NODE_EXTERN void FreeEnvironment(Environment* env); NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local context); // This returns the MultiIsolatePlatform used in the main thread of Node.js. -// If NODE_USE_V8_PLATFORM haven't been defined when Node.js was built, +// If NODE_USE_V8_PLATFORM has not been defined when Node.js was built, // it returns nullptr. +// TODO(addaleax): Deprecate in favour of GetMultiIsolatePlatform(). NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform(); +// This returns the MultiIsolatePlatform used for an Environment or IsolateData +// instance, if one exists. +NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env); +NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env); // Legacy variants of MultiIsolatePlatform::Create(). NODE_EXTERN MultiIsolatePlatform* CreatePlatform(