Skip to content

Commit 9b84ee6

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()`. Backport-PR-URL: #35241 PR-URL: #30467 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Gireesh Punathil <[email protected]>
1 parent a770a35 commit 9b84ee6

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

Diff for: src/api/environment.cc

+8
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,14 @@ MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
474474
return per_process::v8_platform.Platform();
475475
}
476476

477+
MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env) {
478+
return GetMultiIsolatePlatform(env->isolate_data());
479+
}
480+
481+
MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env) {
482+
return env->platform();
483+
}
484+
477485
MultiIsolatePlatform* CreatePlatform(
478486
int thread_pool_size,
479487
node::tracing::TracingController* tracing_controller) {

Diff for: src/node.h

+6-1
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,14 @@ NODE_EXTERN void FreeEnvironment(Environment* env);
456456
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> context);
457457

458458
// This returns the MultiIsolatePlatform used in the main thread of Node.js.
459-
// If NODE_USE_V8_PLATFORM haven't been defined when Node.js was built,
459+
// If NODE_USE_V8_PLATFORM has not been defined when Node.js was built,
460460
// it returns nullptr.
461+
// TODO(addaleax): Deprecate in favour of GetMultiIsolatePlatform().
461462
NODE_EXTERN MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform();
463+
// This returns the MultiIsolatePlatform used for an Environment or IsolateData
464+
// instance, if one exists.
465+
NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(Environment* env);
466+
NODE_EXTERN MultiIsolatePlatform* GetMultiIsolatePlatform(IsolateData* env);
462467

463468
// Legacy variants of MultiIsolatePlatform::Create().
464469
NODE_EXTERN MultiIsolatePlatform* CreatePlatform(

0 commit comments

Comments
 (0)