MCPcopy Create free account
hub / github.com/NativeScript/android / GetRequireFunction

Method GetRequireFunction

test-app/runtime/src/main/cpp/ModuleInternal.cpp:132–164  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

130}
131
132Local<Function> ModuleInternal::GetRequireFunction(Isolate* isolate, const string& dirName) {
133 TNSPERF();
134 Local<Function> requireFunc;
135
136 auto itFound = m_requireCache.find(dirName);
137
138 if (itFound != m_requireCache.end()) {
139 requireFunc = Local<Function>::New(isolate, *itFound->second);
140 } else {
141 auto requireFuncFactory = Local<Function>::New(isolate, *m_requireFactoryFunction);
142
143 auto context = isolate->GetCurrentContext();
144
145 auto requireInternalFunc = Local<Function>::New(isolate, *m_requireFunction);
146
147 Local<Value> args[2] {
148 requireInternalFunc, ArgConverter::ConvertToV8String(isolate, dirName)
149 };
150 Local<Value> result;
151 auto thiz = Object::New(isolate);
152 auto success = requireFuncFactory->Call(context, thiz, 2, args).ToLocal(&result);
153
154 assert(success && !result.IsEmpty() && result->IsFunction());
155
156 requireFunc = result.As<Function>();
157
158 auto poFunc = new Persistent<Function>(isolate, requireFunc);
159
160 m_requireCache.emplace(dirName, poFunc);
161 }
162
163 return requireFunc;
164}
165
166void ModuleInternal::RequireCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
167 try {

Callers

nothing calls this directly

Calls 7

NewFunction · 0.85
ToLocalMethod · 0.80
emplaceMethod · 0.80
findMethod · 0.45
endMethod · 0.45
CallMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected