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

Method LoadData

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

Source from the content-addressed store, hash-verified

479}
480
481Local<Object> ModuleInternal::LoadData(Isolate* isolate, const string& path) {
482 string frameName("LoadData " + path);
483 tns::instrumentation::Frame frame(frameName);
484 Local<Object> json;
485
486 auto jsonData = Runtime::GetRuntime(m_isolate)->ReadFileText(path);
487
488 TryCatch tc(isolate);
489
490 auto jsonStr = ArgConverter::ConvertToV8String(isolate, jsonData);
491
492 auto context = isolate->GetCurrentContext();
493 auto maybeValue = JSON::Parse(context, jsonStr);
494
495 if (maybeValue.IsEmpty() || tc.HasCaught()) {
496 string errMsg = "Cannot parse JSON file " + path;
497 throw NativeScriptException(tc, errMsg);
498 }
499
500 auto value = maybeValue.ToLocalChecked();
501
502 if (!value->IsObject()) {
503 string errMsg = "JSON is not valid, file=" + path;
504 throw NativeScriptException(errMsg);
505 }
506
507 json = value.As<Object>();
508
509 auto poObj = new Persistent<Object>(isolate, json);
510
511 m_loadedModules.emplace(path, ModuleCacheEntry(poObj, true /* isData */));
512
513 return json;
514}
515
516Local<Value> ModuleInternal::LoadESModule(Isolate* isolate, const std::string& path) {
517 auto context = isolate->GetCurrentContext();

Callers

nothing calls this directly

Calls 6

ModuleCacheEntryClass · 0.85
ReadFileTextMethod · 0.80
ToLocalCheckedMethod · 0.80
emplaceMethod · 0.80
IsEmptyMethod · 0.45

Tested by

no test coverage detected