Skip to content
Browse files

New method to see if a function exists or not.

  • Loading branch information...
1 parent ca70a5f commit f1e7c692c1d398d1592b0de6c47ab9da64695245 @ccgus committed Aug 6, 2012
Showing with 13 additions and 0 deletions.
  1. +1 −0 src/JSTalk.h
  2. +12 −0 src/JSTalk.m
View
1 src/JSTalk.h
@@ -30,6 +30,7 @@
- (JSCocoaController*)jsController;
- (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args;
+- (BOOL)hasFunctionNamed:(NSString*)name;
+ (void)listen;
+ (void)resetPlugins;
View
12 src/JSTalk.m
@@ -304,6 +304,18 @@ - (id)callFunctionNamed:(NSString*)name withArguments:(NSArray*)args {
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 {
if (![fileName hasPrefix:@"/"] && [_env objectForKey:@"scriptURL"]) {

0 comments on commit f1e7c69

Please sign in to comment.
Something went wrong with that request. Please try again.