#include "node.h" #include "v8.h" #include #include namespace { void RunInCallbackScope(const v8::FunctionCallbackInfo& args) { v8::Isolate* isolate = args.GetIsolate(); assert(args.Length() == 4); assert(args[0]->IsObject()); assert(args[1]->IsNumber()); assert(args[2]->IsNumber()); assert(args[3]->IsFunction()); node::async_context asyncContext = { args[1].As()->Value(), args[2].As()->Value() }; node::CallbackScope scope(isolate, args[0].As(), asyncContext); v8::Local fn = args[3].As(); v8::MaybeLocal ret = fn->Call(isolate->GetCurrentContext(), args[0], 0, nullptr); if (!ret.IsEmpty()) args.GetReturnValue().Set(ret.ToLocalChecked()); } void Initialize(v8::Local exports) { NODE_SET_METHOD(exports, "runInCallbackScope", RunInCallbackScope); } } // namespace NODE_MODULE(binding, Initialize)