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()`.

PR-URL: #30467
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
  • Loading branch information
addaleax committed Mar 21, 2020
1 parent d7f1107 commit 7e0264d
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 @@ -487,6 +487,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 @@ -477,9 +477,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 7e0264d

Please sign in to comment.