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

Method LoadImpl

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

Source from the content-addressed store, hash-verified

257}
258
259Local<Object> ModuleInternal::LoadImpl(Isolate* isolate, const string& moduleName, const string& baseDir, bool& isData) {
260 auto pathKind = GetModulePathKind(moduleName);
261 auto cachePathKey = (pathKind == ModulePathKind::Global) ? moduleName : (baseDir + "*" + moduleName);
262
263 Local<Object> result;
264
265 DEBUG_WRITE(">>LoadImpl cachePathKey=%s", cachePathKey.c_str());
266
267 auto it = m_loadedModules.find(cachePathKey);
268
269 if (it == m_loadedModules.end()) {
270 std::string path;
271
272 // Search App System libs
273 std::string sys_lib("system_lib://");
274 if (moduleName.rfind(sys_lib, 0) == 0) {
275 auto pos = moduleName.find(sys_lib);
276 path = std::string(moduleName);
277 path.replace(pos, sys_lib.length(), "");
278 } else {
279 // Handle tilde path resolution before calling Java path resolution
280 std::string resolvedModuleName = moduleName;
281 if (!moduleName.empty() && moduleName[0] == '~') {
282 // Convert ~/path to ApplicationPath/path
283 std::string tail = moduleName.size() >= 2 && moduleName[1] == '/' ? moduleName.substr(2) : moduleName.substr(1);
284 resolvedModuleName = Constants::APP_ROOT_FOLDER_PATH + "/" + tail;
285
286 // For .mjs files with tilde paths, use resolved path directly
287 if (Util::EndsWith(resolvedModuleName, ".mjs")) {
288 path = resolvedModuleName;
289 } else {
290 // For non-.mjs files, still use Java resolution with the resolved name
291 JEnv env;
292 JniLocalRef jsModulename(env.NewStringUTF(resolvedModuleName.c_str()));
293 JniLocalRef jsBaseDir(env.NewStringUTF(baseDir.c_str()));
294 JniLocalRef jsModulePath(
295 env.CallStaticObjectMethod(MODULE_CLASS, RESOLVE_PATH_METHOD_ID,
296 (jstring) jsModulename, (jstring) jsBaseDir));
297
298 path = ArgConverter::jstringToString((jstring) jsModulePath);
299 }
300 } else {
301 JEnv env;
302 JniLocalRef jsModulename(env.NewStringUTF(moduleName.c_str()));
303 JniLocalRef jsBaseDir(env.NewStringUTF(baseDir.c_str()));
304 JniLocalRef jsModulePath(
305 env.CallStaticObjectMethod(MODULE_CLASS, RESOLVE_PATH_METHOD_ID,
306 (jstring) jsModulename, (jstring) jsBaseDir));
307
308 path = ArgConverter::jstringToString((jstring) jsModulePath);
309 }
310 }
311
312 auto it2 = m_loadedModules.find(path);
313
314 if (it2 == m_loadedModules.end()) {
315 if (Util::EndsWith(path, ".js") || Util::EndsWith(path, ".mjs") || Util::EndsWith(path, ".so")) {
316 isData = false;

Callers

nothing calls this directly

Calls 9

NewFunction · 0.85
NewStringUTFMethod · 0.80
findMethod · 0.45
endMethod · 0.45
lengthMethod · 0.45
emptyMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected