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

Method RequireCallbackImpl

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

Source from the content-addressed store, hash-verified

181}
182
183void ModuleInternal::RequireCallbackImpl(const v8::FunctionCallbackInfo<v8::Value>& args) {
184 auto isolate = args.GetIsolate();
185
186 if (args.Length() != 2) {
187 throw NativeScriptException(string("require should be called with two parameters"));
188 }
189 if (!args[0]->IsString()) {
190 throw NativeScriptException(string("require's first parameter should be string"));
191 }
192 if (!args[1]->IsString()) {
193 throw NativeScriptException(string("require's second parameter should be string"));
194 }
195
196 string moduleName = ArgConverter::ConvertToString(args[0].As<String>());
197 tns::instrumentation::Frame frame("RequireCallback " + moduleName);
198 string callingModuleDirName = ArgConverter::ConvertToString(args[1].As<String>());
199 auto isData = false;
200
201 auto moduleObj = LoadImpl(isolate, moduleName, callingModuleDirName, isData);
202
203 if (isData) {
204 assert(!moduleObj.IsEmpty());
205
206 args.GetReturnValue().Set(moduleObj);
207 } else {
208 auto context = isolate->GetCurrentContext();
209 Local<Value> exportsVal;
210 moduleObj->Get(context, ArgConverter::ConvertToV8String(isolate, "exports")).ToLocal(&exportsVal);
211
212 assert(!exportsVal.IsEmpty());
213
214 auto exportsObj = exportsVal.As<Object>();
215 args.GetReturnValue().Set(exportsObj);
216 }
217}
218
219void ModuleInternal::RequireNativeCallback(const v8::FunctionCallbackInfo<v8::Value>& args) {
220 TNSPERF();

Callers 1

RequireCallbackMethod · 0.80

Calls 9

IsStringMethod · 0.80
GetReturnValueMethod · 0.80
ToLocalMethod · 0.80
GetIsolateMethod · 0.45
LengthMethod · 0.45
IsEmptyMethod · 0.45
SetMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected