Skip to content

Commit

Permalink
test: using v8::Context::Scope in cctest EnvironmentTestFixture
Browse files Browse the repository at this point in the history
Fixes nodejs#529

PR-URL: nodejs#532
Reviewed-By: Taylor Woll <tawoll@ntdev.microsoft.com>
  • Loading branch information
MSLaguana authored and kfarnung committed May 10, 2018
1 parent 68c92c1 commit 2cd0485
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
1 change: 1 addition & 0 deletions deps/chakrashim/src/v8handlescope.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ HandleScope::HandleScope(Isolate* isolate)
_count(0),
_contextRef(JS_INVALID_REFERENCE),
_addRefRecordHead(nullptr) {
CHAKRA_ASSERT(isolate == Isolate::GetCurrent());
_locals[0] = JS_INVALID_REFERENCE;
current = this;
}
Expand Down
4 changes: 0 additions & 4 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1037,10 +1037,6 @@
'include_dirs': [
'deps/chakrashim/include'
],
'sources!': [
'test/cctest/test_environment.cc', # TODO: Enable these test for node-chakracore
'test/cctest/test_node_postmortem_metadata.cc',
],
'conditions': [
[ 'OS!="win" and chakracore_use_lto=="true"', {
'ldflags': [
Expand Down
17 changes: 10 additions & 7 deletions test/cctest/node_test_fixture.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,11 @@ class NodeTestFixture : public ::testing::Test {
virtual void SetUp() {
isolate_ = v8::Isolate::New(params);
CHECK_NE(isolate_, nullptr);
isolate_->Enter();
}

virtual void TearDown() {
isolate_->Exit();
isolate_->Dispose();
isolate_ = nullptr;
}
Expand All @@ -100,16 +102,16 @@ class EnvironmentTestFixture : public NodeTestFixture {
public:
class Env {
public:
Env(const v8::HandleScope& handle_scope, const Argv& argv) {
auto isolate = handle_scope.GetIsolate();
Env(const v8::HandleScope& handle_scope, const Argv& argv) :
#if ENABLE_TTD_NODE
// TODO(MSLaguana): should we support TTD in cctest?
context_ = node::NewContext(isolate, false);
// TODO(MSLaguana): should we support TTD in cctest?
context_(node::NewContext(handle_scope.GetIsolate(), false)),
#else
context_ = node::NewContext(isolate);
context_(node::NewContext(handle_scope.GetIsolate())),
#endif
context_scope_(context_) {
auto isolate = handle_scope.GetIsolate();
CHECK(!context_.IsEmpty());
context_->Enter();

isolate_data_ = node::CreateIsolateData(isolate,
&NodeTestFixture::current_loop,
Expand All @@ -125,7 +127,6 @@ class EnvironmentTestFixture : public NodeTestFixture {
~Env() {
node::FreeEnvironment(environment_);
node::FreeIsolateData(isolate_data_);
context_->Exit();
}

node::Environment* operator*() const {
Expand All @@ -136,8 +137,10 @@ class EnvironmentTestFixture : public NodeTestFixture {
return context_;
}


private:
v8::Local<v8::Context> context_;
v8::Context::Scope context_scope_;
node::IsolateData* isolate_data_;
node::Environment* environment_;
DISALLOW_COPY_AND_ASSIGN(Env);
Expand Down
1 change: 0 additions & 1 deletion test/cctest/test_platform.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class RepostingTask : public v8::Task {
class PlatformTest : public EnvironmentTestFixture {};

TEST_F(PlatformTest, SkipNewTasksInFlushForegroundTasks) {
v8::Isolate::Scope isolate_scope(isolate_);
const v8::HandleScope handle_scope(isolate_);
const Argv argv;
Env env {handle_scope, argv};
Expand Down

0 comments on commit 2cd0485

Please sign in to comment.