diff options
author | Anna Henningsen <anna@addaleax.net> | 2018-09-12 15:01:50 +0200 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2018-09-17 17:20:27 +0200 |
commit | 4286dcf17f062034117043a2640b620210b61f57 (patch) | |
tree | de227e8bb7bee72778a2e7bd98f08991839bf866 /test/cctest | |
parent | c33e27dc3caf5a5b7954706fe6ecde1e4f82534d (diff) | |
download | android-node-v8-4286dcf17f062034117043a2640b620210b61f57.tar.gz android-node-v8-4286dcf17f062034117043a2640b620210b61f57.tar.bz2 android-node-v8-4286dcf17f062034117043a2640b620210b61f57.zip |
src: refactor `Environment::GetCurrent()` usage
Make `Environment::GetCurrent()` return `nullptr` if the current
`Context` is not a Node.js context, and for the relevant usage of
this function, either:
- Switch to the better `GetCurrent(args)` variant
- Turn functions in to no-ops where it makes sense
- Make it a `CHECK`, i.e. an API requirement, where it make sense
- Leave a `TODO` comment for verifying what, if anything, is to be done
PR-URL: https://github.com/nodejs/node/pull/22819
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'test/cctest')
-rw-r--r-- | test/cctest/test_environment.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/test/cctest/test_environment.cc b/test/cctest/test_environment.cc index 07170ac267..fa0f94a5ad 100644 --- a/test/cctest/test_environment.cc +++ b/test/cctest/test_environment.cc @@ -70,6 +70,26 @@ TEST_F(EnvironmentTest, MultipleEnvironmentsPerIsolate) { EXPECT_TRUE(called_cb_2); } +TEST_F(EnvironmentTest, NonNodeJSContext) { + const v8::HandleScope handle_scope(isolate_); + const Argv argv; + Env test_env {handle_scope, argv}; + + EXPECT_EQ(node::Environment::GetCurrent(v8::Local<v8::Context>()), nullptr); + + node::Environment* env = *test_env; + EXPECT_EQ(node::Environment::GetCurrent(isolate_), env); + EXPECT_EQ(node::Environment::GetCurrent(env->context()), env); + + v8::Local<v8::Context> context = v8::Context::New(isolate_); + EXPECT_EQ(node::Environment::GetCurrent(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::Environment::GetCurrent(isolate_), nullptr); +} + static void at_exit_callback1(void* arg) { called_cb_1 = true; if (arg) { |