@@ -28,15 +28,24 @@ TEST_F(LinkedBindingTest, SimpleTest) {
28
28
29
29
v8::Local<v8::Context> context = isolate_->GetCurrentContext ();
30
30
31
- const char * run_script =
32
- " process._linkedBinding('cctest_linkedbinding').key" ;
33
- v8::Local<v8::Script> script = v8::Script::Compile (
34
- context,
35
- v8::String::NewFromOneByte (isolate_,
36
- reinterpret_cast <const uint8_t *>(run_script))
37
- .ToLocalChecked ())
38
- .ToLocalChecked ();
39
- v8::Local<v8::Value> completion_value = script->Run (context).ToLocalChecked ();
31
+ v8::Local<v8::Value> completion_value =
32
+ node::LoadEnvironment (
33
+ *test_env,
34
+ [&](const node::StartExecutionCallbackInfo& info)
35
+ -> v8::MaybeLocal<v8::Value> {
36
+ const char * run_script =
37
+ " process._linkedBinding('cctest_linkedbinding').key" ;
38
+ v8::Local<v8::Script> script =
39
+ v8::Script::Compile (
40
+ context,
41
+ v8::String::NewFromOneByte (
42
+ isolate_, reinterpret_cast <const uint8_t *>(run_script))
43
+ .ToLocalChecked ())
44
+ .ToLocalChecked ();
45
+ return script->Run (context);
46
+ })
47
+ .ToLocalChecked ();
48
+
40
49
v8::String::Utf8Value utf8val (isolate_, completion_value);
41
50
CHECK_NOT_NULL (*utf8val);
42
51
CHECK_EQ (strcmp (*utf8val, " value" ), 0 );
@@ -69,15 +78,24 @@ TEST_F(LinkedBindingTest, LocallyDefinedLinkedBindingTest) {
69
78
70
79
v8::Local<v8::Context> context = isolate_->GetCurrentContext ();
71
80
72
- const char * run_script =
73
- " process._linkedBinding('local_linked').key" ;
74
- v8::Local<v8::Script> script = v8::Script::Compile (
75
- context,
76
- v8::String::NewFromOneByte (isolate_,
77
- reinterpret_cast <const uint8_t *>(run_script))
78
- .ToLocalChecked ())
79
- .ToLocalChecked ();
80
- v8::Local<v8::Value> completion_value = script->Run (context).ToLocalChecked ();
81
+ v8::Local<v8::Value> completion_value =
82
+ node::LoadEnvironment (
83
+ *test_env,
84
+ [&](const node::StartExecutionCallbackInfo& info)
85
+ -> v8::MaybeLocal<v8::Value> {
86
+ const char * run_script =
87
+ " process._linkedBinding('local_linked').key" ;
88
+ v8::Local<v8::Script> script =
89
+ v8::Script::Compile (
90
+ context,
91
+ v8::String::NewFromOneByte (
92
+ isolate_, reinterpret_cast <const uint8_t *>(run_script))
93
+ .ToLocalChecked ())
94
+ .ToLocalChecked ();
95
+ return script->Run (context);
96
+ })
97
+ .ToLocalChecked ();
98
+
81
99
v8::String::Utf8Value utf8val (isolate_, completion_value);
82
100
CHECK_NOT_NULL (*utf8val);
83
101
CHECK_EQ (strcmp (*utf8val, " value" ), 0 );
@@ -113,15 +131,24 @@ TEST_F(LinkedBindingTest, LocallyDefinedLinkedBindingNapiTest) {
113
131
114
132
v8::Local<v8::Context> context = isolate_->GetCurrentContext ();
115
133
116
- const char * run_script =
117
- " process._linkedBinding('local_linked_napi').hello" ;
118
- v8::Local<v8::Script> script = v8::Script::Compile (
119
- context,
120
- v8::String::NewFromOneByte (isolate_,
121
- reinterpret_cast <const uint8_t *>(run_script))
122
- .ToLocalChecked ())
123
- .ToLocalChecked ();
124
- v8::Local<v8::Value> completion_value = script->Run (context).ToLocalChecked ();
134
+ v8::Local<v8::Value> completion_value =
135
+ node::LoadEnvironment (
136
+ *test_env,
137
+ [&](const node::StartExecutionCallbackInfo& info)
138
+ -> v8::MaybeLocal<v8::Value> {
139
+ const char * run_script =
140
+ " process._linkedBinding('local_linked_napi').hello" ;
141
+ v8::Local<v8::Script> script =
142
+ v8::Script::Compile (
143
+ context,
144
+ v8::String::NewFromOneByte (
145
+ isolate_, reinterpret_cast <const uint8_t *>(run_script))
146
+ .ToLocalChecked ())
147
+ .ToLocalChecked ();
148
+ return script->Run (context);
149
+ })
150
+ .ToLocalChecked ();
151
+
125
152
v8::String::Utf8Value utf8val (isolate_, completion_value);
126
153
CHECK_NOT_NULL (*utf8val);
127
154
CHECK_EQ (strcmp (*utf8val, " world" ), 0 );
@@ -169,17 +196,25 @@ TEST_F(LinkedBindingTest, LocallyDefinedLinkedBindingNapiInstanceDataTest) {
169
196
AddLinkedBinding (*test_env, local_linked_napi_id);
170
197
171
198
v8::Local<v8::Context> context = isolate_->GetCurrentContext ();
172
-
173
- const char * run_script =
174
- " process._linkedBinding('local_linked_napi_id').hello" ;
175
- v8::Local<v8::Script> script = v8::Script::Compile (
176
- context,
177
- v8::String::NewFromOneByte (isolate_,
178
- reinterpret_cast <const uint8_t *>(run_script))
179
- .ToLocalChecked ())
180
- .ToLocalChecked ();
181
199
v8::Local<v8::Value> completion_value =
182
- script->Run (context).ToLocalChecked ();
200
+ node::LoadEnvironment (
201
+ *test_env,
202
+ [&](const node::StartExecutionCallbackInfo& info)
203
+ -> v8::MaybeLocal<v8::Value> {
204
+ const char * run_script =
205
+ " process._linkedBinding('local_linked_napi_id').hello" ;
206
+ v8::Local<v8::Script> script =
207
+ v8::Script::Compile (
208
+ context,
209
+ v8::String::NewFromOneByte (
210
+ isolate_,
211
+ reinterpret_cast <const uint8_t *>(run_script))
212
+ .ToLocalChecked ())
213
+ .ToLocalChecked ();
214
+ return script->Run (context);
215
+ })
216
+ .ToLocalChecked ();
217
+
183
218
CHECK (completion_value->IsExternal ());
184
219
instance_data = static_cast <int *>(
185
220
completion_value.As <v8::External>()->Value ());
@@ -206,16 +241,26 @@ TEST_F(LinkedBindingTest, ManyBindingsTest) {
206
241
207
242
v8::Local<v8::Context> context = isolate_->GetCurrentContext ();
208
243
209
- const char * run_script =
210
- " for (let i = 1; i <= 5; i++)process._linkedBinding(`local_linked${i}`);"
211
- " process._linkedBinding('local_linked_napi').hello" ;
212
- v8::Local<v8::Script> script = v8::Script::Compile (
213
- context,
214
- v8::String::NewFromOneByte (isolate_,
215
- reinterpret_cast <const uint8_t *>(run_script))
216
- .ToLocalChecked ())
217
- .ToLocalChecked ();
218
- v8::Local<v8::Value> completion_value = script->Run (context).ToLocalChecked ();
244
+ v8::Local<v8::Value> completion_value =
245
+ node::LoadEnvironment (
246
+ *test_env,
247
+ [&](const node::StartExecutionCallbackInfo& info)
248
+ -> v8::MaybeLocal<v8::Value> {
249
+ const char * run_script =
250
+ " for (let i = 1; i <= 5; "
251
+ " i++)process._linkedBinding(`local_linked${i}`);"
252
+ " process._linkedBinding('local_linked_napi').hello" ;
253
+ v8::Local<v8::Script> script =
254
+ v8::Script::Compile (
255
+ context,
256
+ v8::String::NewFromOneByte (
257
+ isolate_, reinterpret_cast <const uint8_t *>(run_script))
258
+ .ToLocalChecked ())
259
+ .ToLocalChecked ();
260
+ return script->Run (context);
261
+ })
262
+ .ToLocalChecked ();
263
+
219
264
v8::String::Utf8Value utf8val (isolate_, completion_value);
220
265
CHECK_NOT_NULL (*utf8val);
221
266
CHECK_EQ (strcmp (*utf8val, " world" ), 0 );
0 commit comments