Skip to content

Commit 15ea13c

Browse files
authored
Fix cyclic dependency in early-thrown NativeScriptException and throw error if missing metadata folder (#1470)
1 parent 5a056f5 commit 15ea13c

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

test-app/runtime/src/main/cpp/MetadataNode.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "Runtime.h"
1212
#include <sstream>
1313
#include <cctype>
14+
#include <dirent.h>
1415
#include "ManualInstrumentation.h"
1516

1617
#include "v8.h"
@@ -1698,6 +1699,12 @@ void MetadataNode::BuildMetadata(const string& filesPath) {
16981699

16991700
string baseDir = filesPath;
17001701
baseDir.append("/metadata");
1702+
1703+
DIR* dir = opendir(baseDir.c_str());
1704+
if(dir == nullptr){
1705+
throw NativeScriptException(string("metadata folder couldn't be opened!"));
1706+
}
1707+
17011708
string nodesFile = baseDir + "/treeNodeStream.dat";
17021709
string namesFile = baseDir + "/treeStringsStream.dat";
17031710
string valuesFile = baseDir + "/treeValueStream.dat";

test-app/runtime/src/main/cpp/NativeScriptException.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,10 @@ void NativeScriptException::ReThrowToJava() {
7171
JEnv env;
7272

7373
auto isolate = Isolate::GetCurrent();
74-
auto objectManager = Runtime::GetObjectManager(isolate);
74+
7575

7676
if (!m_javaException.IsNull()) {
77+
auto objectManager = Runtime::GetObjectManager(isolate);
7778
auto excClassName = objectManager->GetClassName((jobject) m_javaException);
7879
if (excClassName == "com/tns/NativeScriptException") {
7980
ex = m_javaException;
@@ -101,6 +102,7 @@ void NativeScriptException::ReThrowToJava() {
101102
if (ex == nullptr) {
102103
ex = static_cast<jthrowable>(env.NewObject(NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_JSVALUE_CTOR_ID, (jstring) msg, (jstring)stackTrace, reinterpret_cast<jlong>(m_javascriptException)));
103104
} else {
105+
auto objectManager = Runtime::GetObjectManager(isolate);
104106
auto excClassName = objectManager->GetClassName(ex);
105107
if (excClassName != "com/tns/NativeScriptException") {
106108
ex = static_cast<jthrowable>(env.NewObject(NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_THROWABLE_CTOR_ID, (jstring) msg, (jstring)stackTrace, ex));

0 commit comments

Comments
 (0)