Skip to content

Commit

Permalink
src: add ability to look up platform based on Environment*
Browse files Browse the repository at this point in the history
This should eventually remove any necessity to use the global-state
`GetMainThreadMultiIsolatePlatform()`.

Backport-PR-URL: #35241
PR-URL: #30467
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
  • Loading branch information
addaleax committed Sep 23, 2020
1 parent a770a35 commit 9b84ee6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/api/environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 6 additions & 1 deletion src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,14 @@ NODE_EXTERN void FreeEnvironment(Environment* env);
NODE_EXTERN Environment* GetCurrentEnvironment(v8::Local<v8::Context> 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(
Expand Down

0 comments on commit 9b84ee6

Please sign in to comment.