@@ -53,49 +53,46 @@ struct Argv {
53
53
int nr_args_;
54
54
};
55
55
56
- extern uv_loop_t current_loop;
57
56
58
57
class NodeTestFixture : public ::testing::Test {
59
- public:
60
- static uv_loop_t * CurrentLoop () { return ¤t_loop; }
61
-
62
- node::MultiIsolatePlatform* Platform () const { return platform_; }
63
-
64
58
protected:
59
+ static std::unique_ptr<v8::ArrayBuffer::Allocator> allocator;
60
+ static std::unique_ptr<v8::TracingController> tracing_controller;
61
+ static std::unique_ptr<node::NodePlatform> platform;
62
+ static v8::Isolate::CreateParams params;
63
+ static uv_loop_t current_loop;
65
64
v8::Isolate* isolate_;
66
65
67
- virtual void SetUp () {
66
+ static void SetUpTestCase () {
67
+ platform.reset (new node::NodePlatform (4 , nullptr ));
68
+ tracing_controller.reset (new v8::TracingController ());
69
+ allocator.reset (v8::ArrayBuffer::Allocator::NewDefaultAllocator ());
70
+ params.array_buffer_allocator = allocator.get ();
71
+ node::tracing::TraceEventHelper::SetTracingController (
72
+ tracing_controller.get ());
68
73
CHECK_EQ (0 , uv_loop_init (¤t_loop));
69
- platform_ = new node::NodePlatform (8 , nullptr );
70
- v8::V8::InitializePlatform (platform_);
74
+ v8::V8::InitializePlatform (platform.get ());
71
75
v8::V8::Initialize ();
72
- v8::Isolate::CreateParams params_;
73
- params_.array_buffer_allocator = allocator_.get ();
74
- isolate_ = v8::Isolate::New (params_);
75
-
76
- // As the TracingController is stored globally, we only need to create it
77
- // one time for all tests.
78
- if (node::tracing::TraceEventHelper::GetTracingController () == nullptr ) {
79
- node::tracing::TraceEventHelper::SetTracingController (
80
- new v8::TracingController ());
81
- }
82
76
}
83
77
84
- virtual void TearDown () {
85
- platform_ ->Shutdown ();
78
+ static void TearDownTestCase () {
79
+ platform ->Shutdown ();
86
80
while (uv_loop_alive (¤t_loop)) {
87
81
uv_run (¤t_loop, UV_RUN_ONCE);
88
82
}
89
83
v8::V8::ShutdownPlatform ();
90
- delete platform_;
91
- platform_ = nullptr ;
92
84
CHECK_EQ (0 , uv_loop_close (¤t_loop));
93
85
}
94
86
95
- private:
96
- node::NodePlatform* platform_ = nullptr ;
97
- std::unique_ptr<v8::ArrayBuffer::Allocator> allocator_{
98
- v8::ArrayBuffer::Allocator::NewDefaultAllocator ()};
87
+ virtual void SetUp () {
88
+ isolate_ = v8::Isolate::New (params);
89
+ CHECK_NE (isolate_, nullptr );
90
+ }
91
+
92
+ virtual void TearDown () {
93
+ isolate_->Dispose ();
94
+ isolate_ = nullptr ;
95
+ }
99
96
};
100
97
101
98
@@ -112,8 +109,8 @@ class EnvironmentTestFixture : public NodeTestFixture {
112
109
context_->Enter ();
113
110
114
111
isolate_data_ = node::CreateIsolateData (isolate,
115
- NodeTestFixture::CurrentLoop () ,
116
- test_fixture-> Platform ());
112
+ & NodeTestFixture::current_loop ,
113
+ platform. get ());
117
114
CHECK_NE (nullptr , isolate_data_);
118
115
environment_ = node::CreateEnvironment (isolate_data_,
119
116
context_,
0 commit comments