Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding a try/catch around callFunctionNamed:, and made sure we're set…

… as the current JSTalk object.
  • Loading branch information...
commit eb006c533eba166575480290ace808b2bd8429ff 1 parent 301d7a5
@ccgus authored
Showing with 21 additions and 11 deletions.
  1. +21 −11 src/JSTalk.m
View
32 src/JSTalk.m
@@ -299,19 +299,29 @@ - (id)executeString:(NSString*)str {
- (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args {
- JSCocoaController *jsController = [self jsController];
- JSContextRef ctx = [jsController ctx];
-
- JSValueRef exception = 0x00;
- JSStringRef functionName = JSStringCreateWithUTF8CString([name UTF8String]);
- JSValueRef functionValue = JSObjectGetProperty(ctx, JSContextGetGlobalObject(ctx), functionName, &exception);
-
- JSStringRelease(functionName);
+ id returnObject;
- JSValueRef returnValue = [jsController callJSFunction:functionValue withArguments:args];
+ @try {
+ [self pushAsCurrentJSTalk];
+ JSCocoaController *jsController = [self jsController];
+ JSContextRef ctx = [jsController ctx];
+
+ JSValueRef exception = 0x00;
+ JSStringRef functionName = JSStringCreateWithUTF8CString([name UTF8String]);
+ JSValueRef functionValue = JSObjectGetProperty(ctx, JSContextGetGlobalObject(ctx), functionName, &exception);
+
+ JSStringRelease(functionName);
+
+ JSValueRef returnValue = [jsController callJSFunction:functionValue withArguments:args];
+
+ [JSCocoaFFIArgument unboxJSValueRef:returnValue toObject:&returnObject inContext:ctx];
+ }
+ @catch (NSException * e) {
+ NSLog(@"Exception: %@", e);
+ [self print:[e description]];
+ }
- id returnObject;
- [JSCocoaFFIArgument unboxJSValueRef:returnValue toObject:&returnObject inContext:ctx];
+ [self popAsCurrentJSTalk];
return returnObject;
}
Please sign in to comment.
Something went wrong with that request. Please try again.