Skip to content

Commit

Permalink
[TIMOB-26007] Handle more exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
Gary Mathews committed May 3, 2018
1 parent 6c861d6 commit 5a0b51e
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 19 deletions.
6 changes: 2 additions & 4 deletions iphone/Classes/KrollBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -434,9 +434,8 @@ - (void)evalFileOnThread:(NSString *)path context:(KrollContext *)context_
}
}
if (exception != NULL) {
id excm = [KrollObject toID:context value:exception];
evaluationError = YES;
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:jsContext exception:exception]];
}

TiStringRelease(jsCode);
Expand Down Expand Up @@ -734,8 +733,7 @@ - (KrollWrapper *)loadCommonJSModule:(NSString *)code withSourceURL:(NSURL *)sou
[eval release];

if (exception != NULL) {
id excm = [KrollObject toID:context value:exception];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:[context context] exception:exception]];
return nil;
}
/*
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/KrollCallback.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,7 @@ - (id)call:(NSArray *)args thisObject:(id)thisObject_
TiValueRef exception = NULL;
TiValueRef retVal = TiObjectCallAsFunction(jsContext, function, tp, [args count], _args, &exception);
if (exception != NULL) {
id excm = [KrollObject toID:context value:exception];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:jsContext exception:exception]];
}
if (top != NULL) {
TiValueUnprotect(jsContext, tp);
Expand Down
6 changes: 2 additions & 4 deletions iphone/Classes/KrollContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -656,8 +656,7 @@ - (void)invoke:(KrollContext *)context
[self jsInvokeInContext:context exception:&exception];

if (exception != NULL) {
id excm = [KrollObject toID:context value:exception];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:[context context] exception:exception]];
pthread_mutex_unlock(&KrollEntryLock);
@throw excm;
}
Expand All @@ -671,8 +670,7 @@ - (id)invokeWithResult:(KrollContext *)context
TiValueRef result = [self jsInvokeInContext:context exception:&exception];

if (exception != NULL) {
id excm = [KrollObject toID:context value:exception];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:[context context] exception:exception]];
pthread_mutex_unlock(&KrollEntryLock);
@throw excm;
}
Expand Down
6 changes: 2 additions & 4 deletions iphone/Classes/KrollObject.m
Original file line number Diff line number Diff line change
Expand Up @@ -1100,8 +1100,7 @@ - (void)invokeCallbackForKey:(NSString *)key withObject:(NSDictionary *)eventDat
TiValueRef jsEventData = ConvertIdTiValue(context, eventData);
TiValueRef result = TiObjectCallAsFunction(jsContext, jsCallback, [_thisObject jsobject], 1, &jsEventData, &exception);
if (exception != NULL) {
id excm = [KrollObject toID:context value:exception];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:jsContext exception:exception]];
}

if (block != nil) {
Expand Down Expand Up @@ -1361,8 +1360,7 @@ - (void)triggerEvent:(NSString *)eventName withObject:(NSDictionary *)eventData
TiValueRef exception = NULL;
TiObjectCallAsFunction(jsContext, (TiObjectRef)currentCallback, [thisObject jsobject], 1, &jsEventData, &exception);
if (exception != NULL) {
id excm = [KrollObject toID:context value:exception];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:jsContext exception:exception]];
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions iphone/Classes/KrollTimer.m
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ - (void)invokeWithCondition:(NSConditionLock *)invokeCond
TiValueRef exception = NULL;
TiObjectCallAsFunction(context, function, jsThis, 0, NULL, &exception);
if (exception != NULL) {
id excm = [KrollObject toID:kroll value:exception];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:context exception:exception]];
}
[invokeCond unlockWithCondition:1];
}
Expand Down
4 changes: 1 addition & 3 deletions iphone/Classes/TiBindingEvent.m
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,7 @@ void TiBindingEventProcess(TiBindingRunLoop runloop, void *payload)
TiValueRef exception = NULL;
TiObjectCallAsFunction(context, (TiObjectRef)currentCallback, (TiObjectRef)eventTargetRef, 1, (TiValueRef *)&eventObjectRef, &exception);
if (exception != NULL) {
id excm = TiBindingTiValueToNSObject(context, exception);
[excm setValue:[TiUtils stackFromException:context exception:exception] forKey:@"backtrace"];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:excm]];
[[TiExceptionHandler defaultExceptionHandler] reportScriptError:[TiUtils scriptErrorValue:context exception:exception]];
}
#ifndef TI_USE_KROLL_THREAD
},
Expand Down
1 change: 1 addition & 0 deletions iphone/Classes/TiUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,7 @@ typedef enum {

+ (WebFont *)fontValue:(id)value;

+ (TiScriptError *)scriptErrorValue:(TiContextRef)context exception:(TiValueRef)exception;
+ (TiScriptError *)scriptErrorValue:(id)value;

+ (NSTextAlignment)textAlignmentValue:(id)alignment;
Expand Down
8 changes: 8 additions & 0 deletions iphone/Classes/TiUtils.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#import "TiProxy.h"
#import "TiUtils.h"
#import "WebFont.h"
#import "TiBindingTiValue.h"

// for checking version
#import <sys/utsname.h>
Expand Down Expand Up @@ -1252,6 +1253,13 @@ + (WebFont *)fontValue:(id)value
return [self fontValue:value def:[WebFont defaultFont]];
}

+ (TiScriptError *)scriptErrorValue:(TiContextRef)context exception:(TiValueRef)exception;
{
id excm = TiBindingTiValueToNSObject(context, exception);
[excm setValue:[TiUtils stackFromException:context exception:exception] forKey:@"backtrace"];
return [self scriptErrorValue: excm];
}

+ (TiScriptError *)scriptErrorValue:(id)value;
{
if ((value == nil) || (value == [NSNull null])) {
Expand Down

0 comments on commit 5a0b51e

Please sign in to comment.