From 723f488dbee3ea812fabf7e451cef86153849024 Mon Sep 17 00:00:00 2001 From: Adam Bird Date: Tue, 25 Jan 2022 00:15:27 -0500 Subject: [PATCH 1/2] fix: runtime crashing during OnUncaughtError --- NativeScript/runtime/Runtime.mm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/NativeScript/runtime/Runtime.mm b/NativeScript/runtime/Runtime.mm index f536ef7e..561f02a3 100644 --- a/NativeScript/runtime/Runtime.mm +++ b/NativeScript/runtime/Runtime.mm @@ -158,10 +158,10 @@ if (AppPackageJson == nil) { NSString* packageJsonPath = [[NSString stringWithUTF8String:RuntimeConfig.ApplicationPath.c_str()] stringByAppendingPathComponent:@"package.json"]; NSData* data = [NSData dataWithContentsOfFile:packageJsonPath]; - AppPackageJson = @{}; if (data) { NSError* error = nil; - AppPackageJson = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; + NSDictionary* dict = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; + AppPackageJson = [[NSDictionary alloc] initWithDictionary:dict]; } } From fc011d3e3eae4f11f81e38e71bd29be0a8eb3eaf Mon Sep 17 00:00:00 2001 From: Adam Bird Date: Tue, 25 Jan 2022 00:15:35 -0500 Subject: [PATCH 2/2] fix: use trycatch on error event handlers --- NativeScript/runtime/NativeScriptException.mm | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/NativeScript/runtime/NativeScriptException.mm b/NativeScript/runtime/NativeScriptException.mm index 96647308..0bb45ecd 100644 --- a/NativeScript/runtime/NativeScriptException.mm +++ b/NativeScript/runtime/NativeScriptException.mm @@ -43,7 +43,12 @@ Local thiz = Object::New(isolate); Local args[] = { error }; Local result; + TryCatch tc(isolate); success = errorHandlerFunc->Call(context, thiz, 1, args).ToLocal(&result); + if (tc.HasCaught()) { + tns::LogError(isolate, tc); + } + tns::Assert(success, isolate); }