Skip to content

Commit 5635fa5

Browse files
author
Mihail Slavchev
committed
replace ASSERT_MESSAGE with V8 exception (issue #221)
1 parent fa1fdb5 commit 5635fa5

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

src/jni/com_tns_Platform.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -266,11 +266,19 @@ extern "C" jobject Java_com_tns_Platform_runScript(JNIEnv *_env, jobject obj, js
266266

267267
void AppInitCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
268268
{
269-
ASSERT_MESSAGE(args.Length() == 1, "Application should be initialized with single parameter");
270-
ASSERT_MESSAGE(args[0]->IsObject(), "Application should be initialized with single object parameter containing overridden methods");
271-
272269
auto isolate = Isolate::GetCurrent();
273270

271+
if (args.Length() != 1)
272+
{
273+
isolate->ThrowException(ConvertToV8String("Application should be initialized with single parameter"));
274+
return;
275+
}
276+
if (!args[0]->IsObject())
277+
{
278+
isolate->ThrowException(ConvertToV8String("Application should be initialized with single object parameter containing overridden methods"));
279+
return;
280+
}
281+
274282
// TODO: find another way to get "com/tns/NativeScriptApplication" metadata (move it to more appropriate place)
275283
auto node = MetadataNode::GetOrCreate("com/tns/NativeScriptApplication");
276284
auto appInstance = node->CreateJSWrapper(isolate);
@@ -281,7 +289,11 @@ void AppInitCallback(const v8::FunctionCallbackInfo<v8::Value>& args)
281289
DEBUG_WRITE("Application object implementation object is with id: %d", implementationObject->GetIdentityHash());
282290
implementationObject->SetPrototype(appInstance->GetPrototype());
283291
bool appSuccess = appInstance->SetPrototype(implementationObject);
284-
ASSERT_MESSAGE(appSuccess == true, "Application could not be initialized correctly");
292+
if (!appSuccess)
293+
{
294+
isolate->ThrowException(ConvertToV8String("Application could not be initialized correctly"));
295+
return;
296+
}
285297

286298
jweak applicationObject = g_objectManager->GetJavaObjectByID(AppJavaObjectID);
287299

0 commit comments

Comments
 (0)