Skip to content

Commit

Permalink
src,test: add public wrapper for Environment::GetCurrent
Browse files Browse the repository at this point in the history
PR-URL: #23676
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Refael Ackermann <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
Signed-off-by: Beth Griggs <[email protected]>
  • Loading branch information
codebytere authored and BethGriggs committed Apr 8, 2019
1 parent 7cceecf commit c2dab8e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2801,6 +2801,11 @@ void FreeEnvironment(Environment* env) {
}


Environment* GetCurrentEnvironment(Local<Context> context) {
return Environment::GetCurrent(context);
}


MultiIsolatePlatform* GetMainThreadMultiIsolatePlatform() {
return v8_platform.Platform();
}
Expand Down
3 changes: 3 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,9 @@ NODE_EXTERN Environment* CreateEnvironment(IsolateData* isolate_data,
NODE_EXTERN void LoadEnvironment(Environment* env);
NODE_EXTERN void FreeEnvironment(Environment* env);

// This may return nullptr if context is not associated with a Node instance.
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,
// it returns nullptr.
Expand Down
3 changes: 3 additions & 0 deletions test/cctest/test_environment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ TEST_F(EnvironmentTest, NonNodeJSContext) {
node::Environment* env = *test_env;
EXPECT_EQ(node::Environment::GetCurrent(isolate_), env);
EXPECT_EQ(node::Environment::GetCurrent(env->context()), env);
EXPECT_EQ(node::GetCurrentEnvironment(env->context()), env);

v8::Local<v8::Context> context = v8::Context::New(isolate_);
EXPECT_EQ(node::Environment::GetCurrent(context), nullptr);
EXPECT_EQ(node::GetCurrentEnvironment(context), nullptr);
EXPECT_EQ(node::Environment::GetCurrent(isolate_), env);

v8::Context::Scope context_scope(context);
EXPECT_EQ(node::Environment::GetCurrent(context), nullptr);
EXPECT_EQ(node::GetCurrentEnvironment(context), nullptr);
EXPECT_EQ(node::Environment::GetCurrent(isolate_), nullptr);
}

Expand Down

0 comments on commit c2dab8e

Please sign in to comment.