MCPcopy Index your code
hub / github.com/nodejs/node-addon-api / RunWithContext

Function RunWithContext

test/run_script.cc:24–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22}
23
24Value RunWithContext(const CallbackInfo& info) {
25 Env env = info.Env();
26
27 Array keys = MaybeUnwrap(info[1].As<Object>().GetPropertyNames());
28 std::string code = "(";
29 for (unsigned int i = 0; i < keys.Length(); i++) {
30 if (i != 0) code += ",";
31 code += MaybeUnwrap(keys.Get(i)).As<String>().Utf8Value();
32 }
33 code += ") => " + info[0].As<String>().Utf8Value();
34
35 Value ret = MaybeUnwrap(env.RunScript(code));
36 Function fn = ret.As<Function>();
37 std::vector<napi_value> args;
38 for (unsigned int i = 0; i < keys.Length(); i++) {
39 Value key = MaybeUnwrap(keys.Get(i));
40 args.push_back(MaybeUnwrap(info[1].As<Object>().Get(key)));
41 }
42 return MaybeUnwrap(fn.Call(args));
43}
44
45} // end anonymous namespace
46

Callers

nothing calls this directly

Calls 6

MaybeUnwrapFunction · 0.85
EnvMethod · 0.80
GetPropertyNamesMethod · 0.80
LengthMethod · 0.80
GetMethod · 0.80
CallMethod · 0.80

Tested by

no test coverage detected