Permalink
Please sign in to comment.
Browse files
Ported basic plugin functionality over from TEA; tested and debugged …
…errors introduced by Objective-C
- Loading branch information...
Showing
with
1,776 additions
and 0 deletions.
- +2 −0 English.lproj/InfoPlist.strings
- +26 −0 Info.plist
- +1 −0 JSCocoa.framework/Headers
- +1 −0 JSCocoa.framework/JSCocoa
- +1 −0 JSCocoa.framework/Resources
- +36 −0 JSCocoa.framework/Versions/A/Headers/BridgeSupportController.h
- +9 −0 JSCocoa.framework/Versions/A/Headers/JSCocoa.h
- +250 −0 JSCocoa.framework/Versions/A/Headers/JSCocoaController.h
- +94 −0 JSCocoa.framework/Versions/A/Headers/JSCocoaFFIArgument.h
- +43 −0 JSCocoa.framework/Versions/A/Headers/JSCocoaFFIClosure.h
- +75 −0 JSCocoa.framework/Versions/A/Headers/JSCocoaPrivateObject.h
- BIN JSCocoa.framework/Versions/A/JSCocoa
- BIN JSCocoa.framework/Versions/A/Resources/English.lproj/InfoPlist.strings
- +22 −0 JSCocoa.framework/Versions/A/Resources/Info.plist
- +747 −0 JSCocoa.framework/Versions/A/Resources/class.js
- +1 −0 JSCocoa.framework/Versions/Current
- BIN JSCocoaLoader.sugar.xcodeproj/TemplateIcon.icns
- +288 −0 JSCocoaLoader.sugar.xcodeproj/project.pbxproj
- +7 −0 JSCocoaLoader.sugar_Prefix.pch
- +27 −0 source/JSCocoaLoader.h
- +146 −0 source/JSCocoaLoader.m
@@ -0,0 +1,2 @@ | ||
+/* Localized versions of Info.plist keys */ | ||
+ |
26
Info.plist
@@ -0,0 +1,26 @@ | ||
+<?xml version="1.0" encoding="UTF-8"?> | ||
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
+<plist version="1.0"> | ||
+<dict> | ||
+ <key>CFBundleDevelopmentRegion</key> | ||
+ <string>English</string> | ||
+ <key>CFBundleExecutable</key> | ||
+ <string>${EXECUTABLE_NAME}</string> | ||
+ <key>CFBundleName</key> | ||
+ <string>JSCocoaLoader</string> | ||
+ <key>CFBundleIconFile</key> | ||
+ <string></string> | ||
+ <key>CFBundleIdentifier</key> | ||
+ <string>com.onecrayon.jscocoaloader</string> | ||
+ <key>CFBundleInfoDictionaryVersion</key> | ||
+ <string>6.0</string> | ||
+ <key>CFBundlePackageType</key> | ||
+ <string>BNDL</string> | ||
+ <key>CFBundleSignature</key> | ||
+ <string>????</string> | ||
+ <key>CFBundleVersion</key> | ||
+ <string>1.0b1</string> | ||
+ <key>NSPrincipalClass</key> | ||
+ <string>JSCocoaLoader</string> | ||
+</dict> | ||
+</plist> |
@@ -0,0 +1 @@ | ||
+Versions/Current/Headers |
@@ -0,0 +1 @@ | ||
+Versions/Current/JSCocoa |
@@ -0,0 +1 @@ | ||
+Versions/Current/Resources |
@@ -0,0 +1,36 @@ | ||
+// | ||
+// BridgeSupportController.h | ||
+// JSCocoa | ||
+// | ||
+// Created by Patrick Geiller on 08/07/08. | ||
+// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
+// | ||
+ | ||
+#if !TARGET_IPHONE_SIMULATOR && !TARGET_OS_IPHONE | ||
+#import <Cocoa/Cocoa.h> | ||
+#endif | ||
+ | ||
+@interface BridgeSupportController : NSObject { | ||
+ | ||
+ | ||
+ NSMutableArray* paths; | ||
+ NSMutableArray* xmlDocuments; | ||
+ | ||
+ NSMutableDictionary* hash; | ||
+} | ||
+ | ||
++ (id)sharedController; | ||
+ | ||
+- (BOOL)loadBridgeSupport:(NSString*)path; | ||
+- (BOOL)isBridgeSupportLoaded:(NSString*)path; | ||
+- (NSUInteger)bridgeSupportIndexForString:(NSString*)string; | ||
+ | ||
+/* | ||
+- (NSString*)query:(NSString*)name withType:(NSString*)type; | ||
+- (NSString*)query:(NSString*)name withType:(NSString*)type inBridgeSupportFile:(NSString*)file; | ||
+*/ | ||
+- (NSString*)queryName:(NSString*)name; | ||
+- (NSString*)queryName:(NSString*)name type:(NSString*)type; | ||
+ | ||
+ | ||
+@end |
@@ -0,0 +1,9 @@ | ||
+// | ||
+// JSCocoa.h | ||
+// JSCocoa | ||
+// | ||
+// Created by Patrick Geiller on 16/12/08. | ||
+// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
+// | ||
+ | ||
+#import "JSCocoaController.h" |
@@ -0,0 +1,250 @@ | ||
+// | ||
+// JSCocoa.h | ||
+// JSCocoa | ||
+// | ||
+// Created by Patrick Geiller on 09/07/08. | ||
+// Copyright 2008 __MyCompanyName__. All rights reserved. | ||
+// | ||
+#if !TARGET_IPHONE_SIMULATOR && !TARGET_OS_IPHONE | ||
+#import <Cocoa/Cocoa.h> | ||
+#import <JavaScriptCore/JavaScriptCore.h> | ||
+#define MACOSX | ||
+#import <ffi/ffi.h> | ||
+#endif | ||
+#import "BridgeSupportController.h" | ||
+#import "JSCocoaPrivateObject.h" | ||
+#import "JSCocoaFFIArgument.h" | ||
+#import "JSCocoaFFIClosure.h" | ||
+ | ||
+ | ||
+// JS value container, used by methods wanting a straight JSValue and not a converted JS->ObjC value. | ||
+struct JSValueRefAndContextRef | ||
+{ | ||
+ JSValueRef value; | ||
+ JSContextRef ctx; | ||
+}; | ||
+typedef struct JSValueRefAndContextRef JSValueRefAndContextRef; | ||
+ | ||
+// | ||
+// JSCocoaController | ||
+// | ||
+@interface JSCocoaController : NSObject { | ||
+ | ||
+ JSGlobalContextRef ctx; | ||
+ id _delegate; | ||
+} | ||
+ | ||
+@property (assign) id delegate; | ||
+ | ||
++ (id)sharedController; | ||
++ (id)controllerFromContext:(JSContextRef)ctx; | ||
++ (BOOL)hasSharedController; | ||
+- (JSGlobalContextRef)ctx; | ||
++ (void)hazardReport; | ||
+ | ||
+// | ||
+// Evaluation | ||
+// | ||
+- (BOOL)evalJSFile:(NSString*)path; | ||
+- (BOOL)evalJSFile:(NSString*)path toJSValueRef:(JSValueRef*)returnValue; | ||
+- (JSValueRef)evalJSString:(NSString*)script; | ||
+- (JSValueRef)evalJSString:(NSString*)script withScriptURL:(NSString*)url; | ||
++ (BOOL)isMaybeSplitCall:(NSString*)start forClass:(id)class; | ||
+- (JSValueRef)callJSFunction:(JSValueRef)function withArguments:(NSArray*)arguments; | ||
+- (JSValueRef)callJSFunctionNamed:(NSString*)functionName withArguments:arguments, ... NS_REQUIRES_NIL_TERMINATION; | ||
+- (id)unboxJSValueRef:(JSValueRef)jsValue; | ||
+- (BOOL)hasJSFunctionNamed:(NSString*)functionName; | ||
+- (BOOL)setObject:(id)object withName:(id)name; | ||
+- (BOOL)setObject:(id)object withName:(id)name attributes:(JSPropertyAttributes)attributes; | ||
+- (BOOL)removeObjectWithName:(id)name; | ||
+ | ||
+// | ||
+// Framework | ||
+// | ||
+- (BOOL)loadFrameworkWithName:(NSString*)name; | ||
+- (BOOL)loadFrameworkWithName:(NSString*)frameworkName inPath:(NSString*)path; | ||
+ | ||
+// | ||
+// Garbage collection | ||
+// | ||
++ (void)garbageCollect; | ||
+- (void)garbageCollect; | ||
+- (void)unlinkAllReferences; | ||
++ (void)upJSCocoaPrivateObjectCount; | ||
++ (void)downJSCocoaPrivateObjectCount; | ||
++ (int)JSCocoaPrivateObjectCount; | ||
+ | ||
++ (void)upJSValueProtectCount; | ||
++ (void)downJSValueProtectCount; | ||
++ (int)JSValueProtectCount; | ||
+ | ||
++ (void)logInstanceStats; | ||
+- (id)instanceStats; | ||
+ | ||
+// | ||
+// Class handling | ||
+// | ||
++ (BOOL)overloadInstanceMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRefAndContextRef)valueAndContext; | ||
++ (BOOL)overloadClassMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRefAndContextRef)valueAndContext; | ||
+ | ||
++ (BOOL)addClassMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRefAndContextRef)valueAndContext encoding:(char*)encoding; | ||
++ (BOOL)addInstanceMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRefAndContextRef)valueAndContext encoding:(char*)encoding; | ||
+ | ||
+// Tests | ||
+- (int)runTests:(NSString*)path; | ||
+ | ||
+// | ||
+// Autorelease pool | ||
+// | ||
++ (void)allocAutoreleasePool; | ||
++ (void)deallocAutoreleasePool; | ||
+ | ||
+// | ||
+// Global boxer : only one JSValueRef for multiple box requests of one pointer | ||
+// | ||
++ (JSObjectRef)boxedJSObject:(id)o inContext:(JSContextRef)ctx; | ||
++ (void)downBoxedJSObjectCount:(id)o; | ||
+ | ||
+ | ||
+// | ||
+// Various internals | ||
+// | ||
++ (JSObjectRef)jsCocoaPrivateObjectInContext:(JSContextRef)ctx; | ||
++ (NSMutableArray*)parseObjCMethodEncoding:(const char*)typeEncoding; | ||
++ (NSMutableArray*)parseCFunctionEncoding:(NSString*)xml functionName:(NSString**)functionNamePlaceHolder; | ||
+ | ||
++ (void)ensureJSValueIsObjectAfterInstanceAutocall:(JSValueRef)value inContext:(JSContextRef)ctx; | ||
+- (NSString*)formatJSException:(JSValueRef)exception; | ||
+- (id)selectorForJSFunction:(JSObjectRef)function; | ||
+ | ||
+- (BOOL)useAutoCall; | ||
+- (void)setUseAutoCall:(BOOL)b; | ||
+ | ||
+- (const char*)typeEncodingOfMethod:(NSString*)methodName class:(NSString*)className; | ||
+ | ||
+ | ||
+ | ||
+@end | ||
+ | ||
+ | ||
+// | ||
+// JSCocoa delegate methods | ||
+// | ||
+ | ||
+// | ||
+// Error reporting | ||
+// | ||
+@interface NSObject (JSCocoaControllerDelegateMethods) | ||
+- (void) JSCocoa:(JSCocoaController*)controller hadError:(NSString*)error onLineNumber:(NSInteger)lineNumber atSourceURL:(id)url; | ||
+ | ||
+// | ||
+// Getting | ||
+// | ||
+// Check if getting property is allowed | ||
+- (BOOL) JSCocoa:(JSCocoaController*)controller canGetProperty:(NSString*)propertyName ofObject:(id)object inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+// Custom handler for getting properties | ||
+// Return a custom JSValueRef to bypass JSCocoa | ||
+// Return NULL to let JSCocoa handle getProperty | ||
+// Return JSValueMakeNull() to return a Javascript null | ||
+- (JSValueRef) JSCocoa:(JSCocoaController*)controller getProperty:(NSString*)propertyName ofObject:(id)object inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+ | ||
+// | ||
+// Setting | ||
+// | ||
+// Check if setting property is allowed | ||
+- (BOOL) JSCocoa:(JSCocoaController*)controller canSetProperty:(NSString*)propertyName ofObject:(id)object toValue:(JSValueRef)value inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+// Custom handler for setting properties | ||
+// Return YES to indicate you handled setting | ||
+// Return NO to let JSCocoa handle setProperty | ||
+- (BOOL) JSCocoa:(JSCocoaController*)controller setProperty:(NSString*)propertyName ofObject:(id)object toValue:(JSValueRef)value inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+ | ||
+// | ||
+// Calling | ||
+// | ||
+// Check if calling a C function is allowed | ||
+- (BOOL) JSCocoa:(JSCocoaController*)controller canCallFunction:(NSString*)functionName argumentCount:(int)argumentCount arguments:(JSValueRef*)arguments inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+// Check if calling an ObjC method is allowed | ||
+- (BOOL) JSCocoa:(JSCocoaController*)controller canCallMethod:(NSString*)methodName ofObject:(id)object argumentCount:(int)argumentCount arguments:(JSValueRef*)arguments inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+// Custom handler for calling | ||
+// Return YES to indicate you handled calling | ||
+// Return NO to let JSCocoa handle calling | ||
+- (JSValueRef) JSCocoa:(JSCocoaController*)controller callMethod:(NSString*)methodName ofObject:(id)object argumentCount:(int)argumentCount arguments:(JSValueRef*)arguments inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+ | ||
+// | ||
+// Getting global properties (classes, structures, C function names, enums via OSXObject_getProperty) | ||
+// | ||
+// Check if getting property is allowed | ||
+- (BOOL) JSCocoa:(JSCocoaController*)controller canGetGlobalProperty:(NSString*)propertyName inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+// Custom handler for getting properties | ||
+// Return a custom JSValueRef to bypass JSCocoa | ||
+// Return NULL to let JSCocoa handle getProperty | ||
+// Return JSValueMakeNull() to return a Javascript null | ||
+- (JSValueRef) JSCocoa:(JSCocoaController*)controller getGlobalProperty:(NSString*)propertyName inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+ | ||
+// | ||
+// Returning values to Javascript | ||
+// | ||
+// Called before returning any value to Javascript : return a new value or the original one | ||
+//- (JSValueRef) JSCocoa:(JSCocoaController*)controller willReturnValue:(JSValueRef)value inContext:(JSContextRef)ctx exception:(JSValueRef*)exception; | ||
+ | ||
+// | ||
+// Evaling | ||
+// | ||
+// Check if file can be loaded | ||
+- (BOOL)JSCocoa:(JSCocoaController*)controller canLoadJSFile:(NSString*)path; | ||
+// Check if script can be evaluated | ||
+- (BOOL)JSCocoa:(JSCocoaController*)controller canEvaluateScript:(NSString*)script; | ||
+// Called before evalJSString, used to modify script about to be evaluated | ||
+// Return a custom NSString (eg a macro expanded version of the source) | ||
+// Return NULL to let JSCocoa handle evaluation | ||
+- (NSString*)JSCocoa:(JSCocoaController*)controller willEvaluateScript:(NSString*)script; | ||
+ | ||
+@end | ||
+ | ||
+ | ||
+// | ||
+// JSCocoa shorthand | ||
+// | ||
+@interface JSCocoa : JSCocoaController | ||
+@end | ||
+ | ||
+// | ||
+// Boxed object cache : holds one JSObjectRef for each reference to a pointer | ||
+// | ||
+@interface BoxedJSObject : NSObject { | ||
+ JSObjectRef jsObject; | ||
+} | ||
+- (void)setJSObject:(JSObjectRef)o; | ||
+- (JSObjectRef)jsObject; | ||
+ | ||
+@end | ||
+ | ||
+// | ||
+// Helpers | ||
+// | ||
+id NSStringFromJSValue(JSValueRef value, JSContextRef ctx); | ||
+//void* malloc_autorelease(size_t size); | ||
+ | ||
+id JSLocalizedString(id stringName, id firstArg, ...) NS_REQUIRES_NIL_TERMINATION; | ||
+ | ||
+ | ||
+// | ||
+// From PyObjC : when to call objc_msgSendStret, for structure return | ||
+// Depending on structure size & architecture, structures are returned as function first argument (done transparently by ffi) or via registers | ||
+// | ||
+ | ||
+#if defined(__ppc__) | ||
+# define SMALL_STRUCT_LIMIT 4 | ||
+#elif defined(__ppc64__) | ||
+# define SMALL_STRUCT_LIMIT 8 | ||
+#elif defined(__i386__) | ||
+# define SMALL_STRUCT_LIMIT 8 | ||
+#elif defined(__x86_64__) | ||
+# define SMALL_STRUCT_LIMIT 16 | ||
+#elif TARGET_OS_IPHONE | ||
+// TOCHECK | ||
+# define SMALL_STRUCT_LIMIT 4 | ||
+#else | ||
+# error "Unsupported MACOSX platform" | ||
+#endif | ||
+ |

Oops, something went wrong.
0 comments on commit
3ad5e49