MCPcopy Create free account
hub / github.com/NodeRT/NodeRT / CreateCallbackObjectInDomain

Function CreateCallbackObjectInDomain

src/NodeRTLib/ProjectFiles/NodeRtUtils.cpp:84–114  ·  view source on GitHub ↗

creates an object with the following structure: { "callback" : [callback fuction] "domain" : [the domain in which the async function/event was called/registered] (this is optional) }

Source from the content-addressed store, hash-verified

82// called/registered] (this is optional)
83// }
84Local<v8::Object> CreateCallbackObjectInDomain(Local<v8::Function> callback) {
85 EscapableHandleScope scope;
86
87 // get the current domain:
88 MaybeLocal<v8::Object> callbackObject = Nan::New<Object>();
89
90 Nan::Set(callbackObject.ToLocalChecked(),
91 Nan::New<String>("callback").ToLocalChecked(), callback);
92
93 MaybeLocal<Value> processVal =
94 Nan::Get(Nan::GetCurrentContext()->Global(),
95 Nan::New<String>("process").ToLocalChecked());
96 v8::Local<Object> process =
97 Nan::To<Object>(processVal.ToLocalChecked()).ToLocalChecked();
98 if (process.IsEmpty() || Nan::Equals(process, Undefined()).FromMaybe(true)) {
99 return scope.Escape(callbackObject.ToLocalChecked());
100 }
101
102 MaybeLocal<Value> currentDomain =
103 Nan::Get(process, Nan::New<String>("domain").ToLocalChecked());
104
105 if (!currentDomain.IsEmpty() &&
106 !Nan::Equals(currentDomain.ToLocalChecked(), Undefined())
107 .FromMaybe(true)) {
108 Nan::Set(callbackObject.ToLocalChecked(),
109 Nan::New<String>("domain").ToLocalChecked(),
110 currentDomain.ToLocalChecked());
111 }
112
113 return scope.Escape(callbackObject.ToLocalChecked());
114}
115
116// Calls the callback in the appropriate domwin, expects an object in the
117// following format:

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected