Skip to content

Commit

Permalink
New method to see if a function exists or not.
Browse files Browse the repository at this point in the history
  • Loading branch information
ccgus committed Aug 6, 2012
1 parent ca70a5f commit f1e7c69
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/JSTalk.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@


- (JSCocoaController*)jsController; - (JSCocoaController*)jsController;
- (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args; - (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args;
- (BOOL)hasFunctionNamed:(NSString*)name;


+ (void)listen; + (void)listen;
+ (void)resetPlugins; + (void)resetPlugins;
Expand Down
12 changes: 12 additions & 0 deletions src/JSTalk.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -304,6 +304,18 @@ - (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args {
return returnObject; return returnObject;
} }


- (BOOL)hasFunctionNamed:(NSString*)name {

JSCocoaController *jsController = [self jsController];
JSValueRef exception = nil;
JSStringRef jsFunctionName = JSStringCreateWithUTF8CString([name UTF8String]);
JSValueRef jsFunctionValue = JSObjectGetProperty([jsController ctx], JSContextGetGlobalObject([jsController ctx]), jsFunctionName, &exception);
JSStringRelease(jsFunctionName);


return jsFunctionValue && (JSValueGetType([jsController ctx], jsFunctionValue) == kJSTypeObject);
}

- (void)include:(NSString*)fileName { - (void)include:(NSString*)fileName {


if (![fileName hasPrefix:@"/"] && [_env objectForKey:@"scriptURL"]) { if (![fileName hasPrefix:@"/"] && [_env objectForKey:@"scriptURL"]) {
Expand Down

0 comments on commit f1e7c69

Please sign in to comment.