Skip to content

Commit 8335cd6

Browse files
committed
fix: improve reThrowToJava exception handling and runtime retrieval logic
1 parent a4931b1 commit 8335cd6

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ void NativeScriptException::ReThrowToJava() {
7575

7676

7777
if (!m_javaException.IsNull()) {
78-
auto objectManager = Runtime::GetObjectManager(isolate);
79-
auto excClassName = objectManager->GetClassName((jobject) m_javaException);
78+
auto excClassName = ObjectManager::GetClassName((jobject) m_javaException);
8079
if (excClassName == "com/tns/NativeScriptException") {
8180
ex = m_javaException;
8281
} else {
@@ -103,8 +102,7 @@ void NativeScriptException::ReThrowToJava() {
103102
if (ex == nullptr) {
104103
ex = static_cast<jthrowable>(env.NewObject(NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_JSVALUE_CTOR_ID, (jstring) msg, (jstring)stackTrace, reinterpret_cast<jlong>(m_javascriptException)));
105104
} else {
106-
auto objectManager = Runtime::GetObjectManager(isolate);
107-
auto excClassName = objectManager->GetClassName(ex);
105+
auto excClassName = ObjectManager::GetClassName(ex);
108106
if (excClassName != "com/tns/NativeScriptException") {
109107
ex = static_cast<jthrowable>(env.NewObject(NATIVESCRIPTEXCEPTION_CLASS, NATIVESCRIPTEXCEPTION_THROWABLE_CTOR_ID, (jstring) msg, (jstring)stackTrace, ex));
110108
}
@@ -184,9 +182,8 @@ Local<Value> NativeScriptException::WrapJavaToJsException() {
184182
JEnv env;
185183

186184
auto isolate = Isolate::GetCurrent();
187-
auto objectManager = Runtime::GetObjectManager(isolate);
188185

189-
string excClassName = objectManager->GetClassName((jobject) m_javaException);
186+
string excClassName = ObjectManager::GetClassName((jobject) m_javaException);
190187
if (excClassName == "com/tns/NativeScriptException") {
191188
jfieldID fieldID = env.GetFieldID(env.GetObjectClass(m_javaException), "jsValueAddress", "J");
192189
jlong addr = env.GetLongField(m_javaException, fieldID);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,15 +132,15 @@ Runtime* Runtime::GetRuntime(int runtimeId) {
132132
}
133133

134134
Runtime* Runtime::GetRuntime(v8::Isolate* isolate) {
135-
auto runtime = s_isolate2RuntimesCache.at(isolate);
135+
auto it = s_isolate2RuntimesCache.find(isolate);
136136

137-
if (runtime == nullptr) {
137+
if (it == s_isolate2RuntimesCache.end()) {
138138
stringstream ss;
139139
ss << "Cannot find runtime for isolate: " << isolate;
140140
throw NativeScriptException(ss.str());
141141
}
142142

143-
return runtime;
143+
return it->second;
144144
}
145145

146146
Runtime* Runtime::GetRuntimeFromIsolateData(v8::Isolate* isolate) {

0 commit comments

Comments
 (0)