Permalink
Browse files

Random hacking.

  • Loading branch information...
1 parent 59a8996 commit decb630f74ed86067c00bcf11cec284517851275 @ccgus committed Jul 24, 2011
@@ -1026,6 +1026,7 @@
);
PREBINDING = NO;
PRODUCT_NAME = jstalk;
+ SDKROOT = macosx10.7;
};
name = Debug;
};
@@ -2,6 +2,10 @@
<!DOCTYPE signatures SYSTEM "file://localhost/System/Library/DTDs/BridgeSupport.dtd">
<signatures version='0.9'>
+<constant name='JSTCGConstCGFloat' type64='d' type='f'/>
+<constant name='JSTCGConstFloat' type='f'/>
+<constant name='JSTCGConstDouble' type='d'/>
+
<!--
<struct name='JSTTestStruct' type='{JSTTestStruct=&quot;b&quot;c&quot;f&quot;f&quot;d&quot;d&quot;i8&quot;c&quot;ui8&quot;C&quot;i16&quot;s&quot;ui16&quot;S&quot;i32&quot;i&quot;ui32&quot;I&quot;i64&quot;q&quot;ui64&quot;Q&quot;next&quot;^{JSTTestStruct}}'/>
-->
@@ -306,9 +306,7 @@ - (void)propertyNamesForObject:(JSObjectRef)jsObject propertyNameAccumulator:(JS
JSPropertyNameAccumulatorAddName(propertyNames, jsString);
JSStringRelease(jsString);
}
-
}
-
}
- (JSValueRef)propertyForObject:(JSObjectRef)jsObject named:(JSStringRef)jsPropertyName outException:(JSValueRef*)exception {
@@ -317,7 +315,13 @@ - (JSValueRef)propertyForObject:(JSObjectRef)jsObject named:(JSStringRef)jsPrope
JSValueRef returnJSObject = 0x00;
JSTRuntimeInfo *info = [JSTBridgeSupportLoader runtimeInfoForSymbol:propertyName];
- debug(@"propertyName: '%@'", propertyName);
+ if ([propertyName isEqual:@"print"]) {
+ return JSObjectMake(_jsContext, _bridgedFunctionClass, @selector(callPrintFWithArguments:argCount:));
+ }
+
+ if ([propertyName isEqual:@"jstassert"]) {
+ return JSObjectMake(_jsContext, _bridgedFunctionClass, @selector(callJSTAssertWithArguments:argCount:));
+ }
if ([propertyName isEqualToString:@"valueOf"] || [propertyName isEqualToString:@"toString"]) {
return [self internalFunctionForJSObject:jsObject functionName:propertyName outException:exception];
@@ -342,12 +346,10 @@ - (JSValueRef)propertyForObject:(JSObjectRef)jsObject named:(JSStringRef)jsPrope
return nil;
}
- id value = [caller objectAtIndex:idx];
+ id value = [caller objectAtIndex:idx];
return [self makeJSObjectWithNSObject:value runtimeInfo:[self runtimeInfoForObject:value]];
}
-
-
if (caller != self) {
// looks like it's a foo.some_objc_method(call, wow, neat);
return [self makeJSStyleBridgedFunction:propertyName onObject:caller];
@@ -371,11 +373,17 @@ - (JSValueRef)propertyForObject:(JSObjectRef)jsObject named:(JSStringRef)jsPrope
fixedDeclaredType = [fixedDeclaredType substringToIndex:[fixedDeclaredType length] - 1];
}
+ debug(@"Got a constant: '%@'", [info symbolName]);
+ debug(@"propertyName: '%@'", propertyName);
+ debug(@"fixedDeclaredType: '%@'", fixedDeclaredType);
+ debug(@"[info jstType]: %d", [info jstType]);
+
+ /*
JSTRuntimeInfo *constInfo = [[JSTBridgeSupportLoader sharedController] runtimeInfoForSymbol:fixedDeclaredType];
if (!constInfo) {
constInfo = info;
}
-
+ */
void *symbol = dlsym(RTLD_DEFAULT, [propertyName UTF8String]);
if (!symbol) {
@@ -384,23 +392,62 @@ - (JSValueRef)propertyForObject:(JSObjectRef)jsObject named:(JSStringRef)jsPrope
return nil;
}
- if ([constInfo jstType] == JSTTypeClass) {
+ debug(@"@encode(double): %s", @encode(double));
+
+ if ([[info typeEncoding] isEqualTo:@"@"]) {
+ id obj = *(id*)symbol;
+ returnJSObject = [self makeJSObjectWithNSObject:obj runtimeInfo:info];
+ }
+ else if ([[info typeEncoding] isEqualTo:@"B"]) {
+ returnJSObject = JSValueMakeBoolean(_jsContext, *(bool*)symbol);
+ }
+ else if ([[info typeEncoding] isEqualTo:@"d"]) {
+ returnJSObject = JSValueMakeNumber(_jsContext, *(double*)symbol);
+ }
+ else if ([[info typeEncoding] isEqualTo:@"f"]) {
+ returnJSObject = JSValueMakeNumber(_jsContext, *(float*)symbol);
+ }
+ else if ([[info typeEncoding] isEqualTo:@"Q"]) {
+ returnJSObject = JSValueMakeNumber(_jsContext, *(unsigned long*)symbol);
+ }
+ else if ([[info typeEncoding] isEqualTo:@"I"]) {
+ returnJSObject = JSValueMakeNumber(_jsContext, *(unsigned int*)symbol);
+ }
+ else if ([[info typeEncoding] hasPrefix:@"{"]) {
+ debug(@"uh, a structupre!");
+ //returnJSObject = JSValueMakeBoolean(_jsContext, *(bool*)symbol);
+ }
+ else {
+ debug(@"Can't find type: %@", [info typeEncoding]);
+ }
+
+ /*
+
+ if ([info jstType] == JSTTypeClass) {
id obj = *(id*)symbol;
- returnJSObject = [self makeJSObjectWithNSObject:obj runtimeInfo:constInfo];
+ returnJSObject = [self makeJSObjectWithNSObject:obj runtimeInfo:info];
}
- else if ([constInfo jstType] == JSTTypeStruct) {
+ else if ([info jstType] == JSTTypeStruct) {
// need to make a JSTStructure, and then return that guy or something.
JSTStructure *structure = [JSTStructure structureWithConstantSymbolAddress:&symbol bridge:self];
- [structure setRuntimeInfo:constInfo];
+ [structure setRuntimeInfo:info];
// ok, now what?
debug(@"it's a structure.");
}
- else if ([[constInfo typeEncoding] isEqualToString:@"B"]) {
+ else if ([info jstType] == JSTTypeConstant) {
+ // something like NSZeroPoint, NSZeroRect, NSThreadWillExitNotification
+
+ debug(@"[constInfo typeEncoding]: '%@'", [info typeEncoding]);
+
+
+ }
+ else if ([[info typeEncoding] isEqualToString:@"B"]) {
returnJSObject = JSValueMakeBoolean(_jsContext, *(bool*)symbol);
}
+ */
}
else if ([info jstType] == JSTTypeEnum) {
returnJSObject = JSValueMakeNumber(_jsContext, [info enumValue]);
@@ -425,7 +472,6 @@ - (JSValueRef)propertyForObject:(JSObjectRef)jsObject named:(JSStringRef)jsPrope
}
}
-
return returnJSObject;
}
@@ -454,9 +500,52 @@ - (BOOL)setPropertyForObject:(JSObjectRef)jsObject named:(JSStringRef)jsProperty
return NO;
}
+- (void)callPrintFWithArguments:(const JSValueRef*)arguments argCount:(size_t)argumentCount {
+
+ if (argumentCount < 1) {
+ return;
+ }
+
+ NSString *s = JSTNSObjectFromValue(self, arguments[0]);
+
+
+ if (![s isKindOfClass:[NSString class]]) {
+ s = [s description];
+ }
+
+ printf("%s\n", [[s description] UTF8String]);
+}
+
+- (void)callJSTAssertWithArguments:(const JSValueRef*)arguments argCount:(size_t)argumentCount {
+
+ if (argumentCount < 2) {
+ return;
+ }
+
+ if (!JSValueToBoolean(_jsContext, arguments[0])) {
+
+
+ NSString *s = JSTNSObjectFromValue(self, arguments[1]);
+
+ if (![s isKindOfClass:[NSString class]]) {
+ s = [s description];
+ }
+
+ printf("*** Assertion Failure! %s\n", [[s description] UTF8String]);
+ }
+}
- (JSValueRef)callFunction:(JSObjectRef)jsFunction onObject:(JSObjectRef)thisObject argCount:(size_t)argumentCount arguments:(const JSValueRef*)arguments outException:(JSValueRef*)exception {
+ if (JSObjectGetPrivate(jsFunction) == @selector(callPrintFWithArguments:argCount:)) {
+ [self callPrintFWithArguments:arguments argCount:argumentCount];
+ return 0x00;
+ }
+ else if (JSObjectGetPrivate(jsFunction) == @selector(callJSTAssertWithArguments:argCount:)) {
+ [self callJSTAssertWithArguments:arguments argCount:argumentCount];
+ return 0x00;
+ }
+
JSTFunction *function = [self functionForJSFunction:jsFunction];
JSTRuntimeInfo *runtimeInfo = [self runtimeInfoForObject:function];
NSString *functionName = [function functionName];
@@ -158,7 +158,11 @@ - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)tagName namespa
[nextObject jstType] == JSTTypeEnum || [nextObject jstType] == JSTTypeFunction ||
[nextObject jstType] == JSTTypeClass) {
- //debug(@"Adding: %@ - %@", [nextObject name], [nextObject type]);
+ /*
+ if ([nextObject jstType] == JSTTypeConstant && !([[nextObject typeEncoding] isEqual:@"@"])) {
+ debug(@"Adding: %@ - %@", [nextObject symbolName], [nextObject typeEncoding]);
+ }
+ */
JSTAssert([nextObject symbolName]);
[_symbolLookup setObject:nextObject forKey:[nextObject symbolName]];
@@ -208,6 +212,8 @@ - (BOOL)loadFrameworkAtPath:(NSString*)frameworkPath {
- (BOOL)loadBridgeSupportAtPath:(NSString*)path {
+ debug(@"path: '%@'", path);
+
NSXMLParser *parser = [[[NSXMLParser alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path]] autorelease];
if (!parser) {
@@ -237,6 +237,9 @@ - (NSString*)description {
else if (_jstType == JSTTypeStruct) {
return [NSString stringWithFormat:@"%@ struct '%@'", prefix, _symbolName];
}
+ else if (_jstType == JSTTypeConstant) {
+ return [NSString stringWithFormat:@"%@ const '%@'", prefix, _symbolName];
+ }
return prefix;
@@ -18,6 +18,10 @@
#import <Cocoa/Cocoa.h>
+APPKIT_EXTERN const CGFloat JSTConstCGFloat;
+APPKIT_EXTERN const float JSTConstFloat;
+APPKIT_EXTERN const double JSTConstDouble;
+
struct JSTTestStruct {
BOOL b;
/*
@@ -55,3 +59,8 @@ typedef struct JSTTestStruct JSTTestStruct;
*/
@end
+
+
+
+
+
@@ -9,10 +9,12 @@
#import "JSTTests.h"
+const CGFloat JSTConstCGFloat = 123.456;
+const CGFloat JSTConstFloat = 123.456;
+const CGFloat JSTConstDouble = 123.456;
@implementation JSTTests
-
- (BOOL)testBoolValue {
return YES;
}
@@ -236,7 +236,7 @@ - (id)executeString:(NSString*)str {
//resultRef = [_jsController evalJSString:[NSString stringWithFormat:@"function print(s) { jstalk.print_(s); } var nil=null; %@", str]];
// quick helper function.
- [_bridge evalJSString:@"function print(s) { objc_msgSend(jstalk, \"print:\", s); }" withPath:nil];
+ //[_bridge evalJSString:@"function print(s) { objc_msgSend(jstalk, \"print:\", s); }" withPath:nil];
resultRef = [_bridge evalJSString:str withPath:nil];
@@ -1,4 +1,4 @@
-function jsassert(val, msg) {
+function jasssert(val, msg) {
if (!val) {
print("Assertion failure!");
print(msg);
@@ -1,7 +1,21 @@
-[jstalk include:"jstsetup.jstalk"];
+print("starting");
NSMakeRect(1, 2, 3, 4);
+jstassert([NSThreadWillExitNotification isEqualToString:"NSThreadWillExitNotification"], "Can't find NSThreadWillExitNotification")
+jstassert(NSASCIIStringEncoding == 1, "Can't find NSASCIIStringEncoding")
+jstassert(!NSDeallocateZombies, "Can't find NSDeallocateZombies");
+jstassert(NSFoundationVersionNumber, "Can't find NSFoundationVersionNumber.")
+jstassert(NSUnderlineByWordMask, "Can't find NSUnderlineByWordMask.")
+jstassert(NSBlack, "Can't find NSBlack.")
+
+
+
+//kCFBooleanFalse - ^{__CFBoolean=}
+//kCFBundleDevelopmentRegionKey - ^{__CFString=}
+//kCFCoreFoundationVersionNumber
+//kCFNull - ^{__CFNull=}
+
var zp = NSZeroPoint;
jsassert(zp, "Can't make a zero point");
jsassert(zp.x == 0, "Can't grab NSZeroPoint");
Oops, something went wrong. Retry.

0 comments on commit decb630

Please sign in to comment.