Skip to content

Commit 7e0264d

Browse files
committed
src: add ability to look up platform based on Environment*
This should eventually remove any necessity to use the global-state `GetMainThreadMultiIsolatePlatform()`. PR-URL: #30467 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
1 parent d7f1107 commit 7e0264d

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/api/environment.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -487,6 +487,14 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
487487
return per_process::v8_platform.Platform();
488488
}
489489

490+
MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env) {
491+
return GetMultiIsolatePlatform(env->isolate_data());
492+
}
493+
494+
MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env) {
495+
return env->platform();
496+
}
497+
490498
MultiIsolatePlatform* CreatePlatform(
491499
int thread_pool_size,
492500
node::tracing::TracingController* tracing_controller) {

src/node.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,14 @@ NODE_EXTERN void FreeEnvironment(Environment* env);
477477
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
478478

479479
// This returns the MultiIsolatePlatform used in the main thread of Node.js.
480-
// If NODE_USE_V8_PLATFORM haven't been defined when Node.js was built,
480+
// If NODE_USE_V8_PLATFORM has not been defined when Node.js was built,
481481
// it returns nullptr.
482+
// TODO(addaleax): Deprecate in favour of GetMultiIsolatePlatform().
482483
NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform();
484+
// This returns the MultiIsolatePlatform used for an Environment or IsolateData
485+
// instance, if one exists.
486+
NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env);
487+
NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env);
483488

484489
// Legacy variants of MultiIsolatePlatform::Create().
485490
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(

0 commit comments

Comments
 (0)