| 479 | } |
| 480 | |
| 481 | Local<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 | |
| 516 | Local<Value> ModuleInternal::LoadESModule(Isolate* isolate, const std::string& path) { |
| 517 | auto context = isolate->GetCurrentContext(); |
nothing calls this directly
no test coverage detected