Permalink
Browse files

Added an eval box in TestsRunner

  • Loading branch information...
1 parent 2dd3a3d commit 978cfeb373703c2f2f7781f86209694c6f20c769 @parmanoir committed Jan 19, 2011
@@ -438,8 +438,8 @@
</array>
<key>TableOfContents</key>
<array>
- <string>3D97009112084F0E004B5164</string>
- <string>3D97009212084F0E004B5164</string>
+ <string>3DA06643126B41630063F59C</string>
+ <string>3DA06644126B41630063F59C</string>
<string>1C9437FD063B20B00039CFAC</string>
<string>1C9437FE063B20B00039CFAC</string>
<string>1C9437FF063B20B00039CFAC</string>
@@ -692,7 +692,7 @@
<key>TableOfContents</key>
<array>
<string>1C530D52069F1CE1000CFCEE</string>
- <string>3D97009312084F0E004B5164</string>
+ <string>3DA06645126B41630063F59C</string>
<string>1CD0528F0623707200166675</string>
<string>XCMainBuildResultsModuleGUID</string>
</array>
@@ -58,8 +58,8 @@
PBXFileDataSource_Target_ColumnID,
);
};
- PBXPerProjectTemplateStateSaveDate = 302534413;
- PBXWorkspaceStateSaveDate = 302534413;
+ PBXPerProjectTemplateStateSaveDate = 309018970;
+ PBXWorkspaceStateSaveDate = 309018970;
};
sourceControlManager = 3D9D7F5E0EF819CB00D71763 /* Source Control */;
userBuildSettings = {
@@ -295,7 +295,7 @@ typedef struct JSValueRefAndContextRef JSValueRefAndContextRef;
//
// Helpers
//
-id NSStringFromJSValue(JSValueRef value, JSContextRef ctx);
+id NSStringFromJSValue(JSContextRef ctx, JSValueRef value);
//void* malloc_autorelease(size_t size);
// Convert values between contexts (eg user context and webkit page context)
@@ -4766,7 +4766,7 @@ static JSValueRef jsCocoaInfo_getProperty(JSContextRef ctx, JSObjectRef object,
JSValueRef classNameJS = JSObjectGetProperty(ctx, object, classNameProperty, NULL);
JSStringRelease(classNameProperty);
- id className = NSStringFromJSValue(classNameJS, ctx);
+ id className = NSStringFromJSValue(ctx, classNameJS);
// NSLog(@"className=%@", className);
id class = objc_getClass([className UTF8String]);
@@ -4848,7 +4848,7 @@ static void jsCocoaInfo_getPropertyNames(JSContextRef ctx, JSObjectRef object, J
#pragma mark Helpers
-id NSStringFromJSValue(JSValueRef value, JSContextRef ctx)
+id NSStringFromJSValue(JSContextRef ctx, JSValueRef value)
{
if (JSValueIsNull(ctx, value)) return nil;
JSStringRef resultStringJS = JSValueToStringCopy(ctx, value, NULL);
@@ -459,13 +459,13 @@ + (BOOL)fromJSValueRef:(JSValueRef)value inContext:(JSContextRef)ctx typeEncodin
}
case _C_SEL:
{
- id str = NSStringFromJSValue(value, ctx);
+ id str = NSStringFromJSValue(ctx, value);
*(SEL*)ptr = NSSelectorFromString(str);
return YES;
}
case _C_CHARPTR:
{
- id str = NSStringFromJSValue(value, ctx);
+ id str = NSStringFromJSValue(ctx, value);
*(char**)ptr = (char*)[str UTF8String];
return YES;
}
@@ -16,6 +16,9 @@
IBOutlet id window;
IBOutlet id textField;
+ IBOutlet NSTextField* evalText;
+ IBOutlet NSTextField* evalResult;
+
JSCocoa* jsc2;
id topObjects;
@@ -40,6 +43,8 @@
- (IBAction)runSimpleTestFile:(id)sender;
- (IBAction)unlinkAllReferences:(id)sender;
+- (IBAction)eval:(id)sender;
+
- (id)testDelegate;
- (int)dummyValue;
- (id)testCallAPI;
@@ -14,33 +14,18 @@ @implementation ApplicationController
JSCocoaController* jsc = nil;
-//- (void)awakeFromNib
- (void)applicationDidFinishLaunching:(NSNotification *)notification
{
- [JSCocoaController hazardReport];
-
- jsc = nil;
-// jsc = [JSCocoa new];
-// [jsc evalJSFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"js"]];
+ jsc = nil;
+ testNSError = nil;
+ cyclingContext = NO;
+ [JSCocoaController hazardReport];
[[NSApplication sharedApplication] setDelegate:self];
- [self performSelector:@selector(runJSTests:) withObject:nil afterDelay:0];
-
- testNSError = nil;
-
-// NSLog(@"sizeof(int)=%d", sizeof(int));
-// NSLog(@"sizeof(long)=%d", sizeof(long));
-// NSLog(@"sizeof(CGFloat)=%d", sizeof(CGFloat));
NSLog(@"*** Running %@ ***", [JSCocoa runningArchitecture]);
- cyclingContext = NO;
-/*
- id error = nil;
- id url = [NSURL fileURLWithPath:@"/non/existent"];
- BOOL b = [@"hello" writeToURL:url atomically:NO encoding:NSUTF8StringEncoding error:&error];
- NSLog(@"++++++++ %d %@", b, error);
-*/
-// [self dumpEncodings];
+ // Run tests
+// [self performSelector:@selector(runJSTests:) withObject:nil afterDelay:0];
}
- (void)applicationWillTerminate:(NSNotification *)notification
@@ -645,6 +630,36 @@ - (int)get5
//
//
+#pragma mark Eval
+//
+//
+- (IBAction)eval:(id)sender
+{
+ id script = [evalText stringValue];
+
+ if (!jsc)
+ [self cycleContext];
+
+ JSStringRef scriptJS = JSStringCreateWithCFString((CFStringRef)script);
+ JSValueRef exception = NULL;
+ JSValueRef result = JSEvaluateScript([jsc ctx], scriptJS, NULL, NULL, 1, &exception);
+ JSStringRelease(scriptJS);
+
+ id resultString = nil;
+ if (exception)
+ {
+ resultString = [NSString stringWithFormat:@"*** Exception ***\n%@", NSStringFromJSValue([jsc ctx], exception)];
+ }
+ else
+ resultString = NSStringFromJSValue([jsc ctx], result);
+
+ [evalResult setStringValue:resultString];
+}
+
+
+
+//
+//
#pragma mark Delegate test
//
//
@@ -1004,3 +1019,7 @@ + (void)testFunction:(void (^)(NSError *))theBlock {
JSTestBlocks.testFunction_(objcBlock);
*/
+
+
+
+
Oops, something went wrong.

0 comments on commit 978cfeb

Please sign in to comment.