1
1
#include " node.h"
2
- #include " v8.h"
3
2
#include " uv.h"
3
+ #include " v8.h"
4
4
5
5
#include < assert.h>
6
- #include < vector>
7
6
#include < memory>
7
+ #include < vector>
8
8
9
9
namespace {
10
10
11
11
void RunInCallbackScope (const v8::FunctionCallbackInfo<v8::Value>& args) {
12
12
v8::Isolate* isolate = args.GetIsolate ();
13
+ v8::Local<v8::Context> context = isolate->GetCurrentContext ();
14
+ node::Environment* env = node::GetCurrentEnvironment (context);
13
15
14
16
assert (args.Length () == 4 );
15
17
assert (args[0 ]->IsObject ());
@@ -22,11 +24,11 @@ void RunInCallbackScope(const v8::FunctionCallbackInfo<v8::Value>& args) {
22
24
args[2 ].As <v8::Number>()->Value ()
23
25
};
24
26
25
- node::CallbackScope scope (isolate , args[0 ].As <v8::Object>(), asyncContext);
27
+ node::CallbackScope scope (env , args[0 ].As <v8::Object>(), asyncContext);
26
28
v8::Local<v8::Function> fn = args[3 ].As <v8::Function>();
27
29
28
30
v8::MaybeLocal<v8::Value> ret =
29
- fn->Call (isolate-> GetCurrentContext () , args[0 ], 0 , nullptr );
31
+ fn->Call (context , args[0 ], 0 , nullptr );
30
32
31
33
if (!ret.IsEmpty ())
32
34
args.GetReturnValue ().Set (ret.ToLocalChecked ());
@@ -35,12 +37,14 @@ void RunInCallbackScope(const v8::FunctionCallbackInfo<v8::Value>& args) {
35
37
static void Callback (uv_work_t * req, int ignored) {
36
38
v8::Isolate* isolate = v8::Isolate::GetCurrent ();
37
39
v8::HandleScope scope (isolate);
38
- node::CallbackScope callback_scope (isolate, v8::Object::New (isolate),
40
+ v8::Local<v8::Context> context = isolate->GetCurrentContext ();
41
+ node::Environment* env = node::GetCurrentEnvironment (context);
42
+ node::CallbackScope callback_scope (env, v8::Object::New (isolate),
39
43
node::async_context{0 , 0 });
40
44
std::unique_ptr<v8::Global<v8::Promise::Resolver>> persistent {
41
45
static_cast <v8::Global<v8::Promise::Resolver>*>(req->data ) };
42
46
v8::Local<v8::Promise::Resolver> local = persistent->Get (isolate);
43
- local->Resolve (isolate-> GetCurrentContext () ,
47
+ local->Resolve (context ,
44
48
v8::Undefined (isolate)).ToChecked ();
45
49
delete req;
46
50
}
0 commit comments