Skip to content

Commit

Permalink
'no context' in finalize is no problem as the context is only used to…
Browse files Browse the repository at this point in the history
… remove the box from the box hash. Context is null because we're being deleted
  • Loading branch information
parmanoir committed Aug 3, 2011
1 parent ebee9c2 commit 0c45a77
Show file tree
Hide file tree
Showing 57 changed files with 11,322 additions and 38,247 deletions.
62 changes: 28 additions & 34 deletions JSCocoa/JSCocoaController.m
Expand Up @@ -345,12 +345,10 @@ - (void)cleanUp
[self unlinkAllReferences]; [self unlinkAllReferences];
JSGarbageCollect(ctx); JSGarbageCollect(ctx);
} }
[self logBoxedObjects];


controllerCount--; controllerCount--;
if (controllerCount == 0) if (controllerCount == 0)
{ {
NSLog(@"OUT");
if (OSXObjectClass) { if (OSXObjectClass) {
JSClassRelease(OSXObjectClass); JSClassRelease(OSXObjectClass);
JSClassRelease(jsCocoaObjectClass); JSClassRelease(jsCocoaObjectClass);
Expand Down Expand Up @@ -390,25 +388,14 @@ - (void)cleanUp
// Remove classes : go backwards to remove child classes first // Remove classes : go backwards to remove child classes first
for (id class in [jsClasses reverseObjectEnumerator]) for (id class in [jsClasses reverseObjectEnumerator])
objc_disposeClassPair([class pointerValue]); objc_disposeClassPair([class pointerValue]);
/*
NSInteger c = [jsClasses count]-1;
NSLog(@"CLASSCOUNT %d", c);
while (c >= 0)
{
id class = [[jsClasses objectAtIndex:c] pointerValue];
NSLog(@"DEALLOC CLASS %@", class);
objc_disposeClassPair(class);
c--;
}
*/
[jsClasses release]; [jsClasses release];
jsClasses = nil; jsClasses = nil;
} }
NSLog(@"DESTROY context");
if (ownsContext) if (ownsContext)
JSGlobalContextRelease(ctx); JSGlobalContextRelease(ctx);


NSLog(@"DESTROY boxedObjects");
[boxedObjects release]; [boxedObjects release];
} }


Expand Down Expand Up @@ -951,7 +938,11 @@ - (BOOL)removeObjectWithName:(id)name
return YES; return YES;
} }


//
//
#pragma mark Loading Frameworks #pragma mark Loading Frameworks
//
//
- (BOOL)loadFrameworkWithName:(NSString*)name - (BOOL)loadFrameworkWithName:(NSString*)name
{ {
// Only check /System/Library/Frameworks for now // Only check /System/Library/Frameworks for now
Expand Down Expand Up @@ -1156,10 +1147,12 @@ + (id)parentObjCClassOfClassName:(NSString*)className
return [jsClassParents objectForKey:className]; return [jsClassParents objectForKey:className];
} }


//
//
#pragma mark Common encoding parsing #pragma mark Common encoding parsing
// //
// This is parsed from method_getTypeEncoding
// //
// This is parsed from method_getTypeEncoding
// Later : Use method_copyArgumentType ? // Later : Use method_copyArgumentType ?
+ (NSMutableArray*)parseObjCMethodEncoding:(const char*)typeEncoding + (NSMutableArray*)parseObjCMethodEncoding:(const char*)typeEncoding
{ {
Expand Down Expand Up @@ -1315,9 +1308,11 @@ + (NSMutableArray*)parseCFunctionEncoding:(NSString*)xml functionName:(NSString*







//
//
#pragma mark Class Creation #pragma mark Class Creation

//
//
+ (Class)createClass:(char*)className parentClass:(char*)parentClass + (Class)createClass:(char*)className parentClass:(char*)parentClass
{ {
Class class = objc_getClass(className); Class class = objc_getClass(className);
Expand Down Expand Up @@ -1804,6 +1799,8 @@ - (BOOL)isFunctionVariadic:(id)functionName
return isVariadic; return isVariadic;
} }




#pragma mark Boxed object hash #pragma mark Boxed object hash


//+ (JSObjectRef)boxedJSObject:(id)o inContext:(JSContextRef)ctx //+ (JSObjectRef)boxedJSObject:(id)o inContext:(JSContextRef)ctx
Expand Down Expand Up @@ -2002,18 +1999,14 @@ - (int)runTests:(NSString*)path withSelector:(SEL)sel {
id files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil]; id files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:path error:nil];
id predicate= [NSPredicate predicateWithFormat:@"SELF ENDSWITH[c] '.js'"]; id predicate= [NSPredicate predicateWithFormat:@"SELF ENDSWITH[c] '.js'"];
files = [files filteredArrayUsingPredicate:predicate]; files = [files filteredArrayUsingPredicate:predicate];

// Execute in test order, not finder order
files = [files sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
// NSLog(@"files=%@", files);

if ([files count] == 0) if ([files count] == 0)
return [JSCocoaController log:@"no test files found"], 0; return [JSCocoaController log:@"no test files found"], 0;


// Execute in test order, not finder order
files = [files sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
for (id file in files) { for (id file in files) {
id filePath = [NSString stringWithFormat:@"%@/%@", path, file]; id filePath = [NSString stringWithFormat:@"%@/%@", path, file];
NSLog(@">>>evaling %@", filePath); // NSLog(@">>>evaling %@", filePath);
// BOOL evaled = [self evalJSFile:filePath];


id evaled = nil; id evaled = nil;
@try { @try {
Expand Down Expand Up @@ -3281,14 +3274,12 @@ static void jsCocoaObject_finalize(JSObjectRef object)
id jsc = nil; id jsc = nil;
JSContextRef ctx = [private ctx]; JSContextRef ctx = [private ctx];


if (!ctx) { if (ctx)
NSLog(@"+++++++NO CONTEXT, NO DELETE");
} else {
jsc = [JSCocoa controllerFromContext:ctx]; jsc = [JSCocoa controllerFromContext:ctx];
} // We will be called during garbage collection before dealloc occurs.
if (!jsc) { // The __jsc__ variable will be gone, therefore controllerFromContext will yield 0.
NSLog(@"*******NO CONTEXT+++++++++++"); // Not a problem since it's only used to remove the object from the boxedObjects hash,
} // and dealloc will occur soon after.


// //
// If a boxed object is being destroyed, remove it from the cache // If a boxed object is being destroyed, remove it from the cache
Expand Down Expand Up @@ -4996,8 +4987,11 @@ static void jsCocoaInfo_getPropertyNames(JSContextRef ctx, JSObjectRef object, J
} }





//
#pragma mark Helpers //
#pragma mark Global helpers
//
//


id NSStringFromJSValue(JSContextRef ctx, JSValueRef value) id NSStringFromJSValue(JSContextRef ctx, JSValueRef value)
{ {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions TestsRunner/ApplicationController.m
Expand Up @@ -22,7 +22,6 @@ - (id)init {
return nil; return nil;


test_unit = test_delegate = test_webview = test_autocall = YES; test_unit = test_delegate = test_webview = test_autocall = YES;
test_webview = NO;


return self; return self;
} }
Expand Down Expand Up @@ -149,7 +148,7 @@ - (IBAction)runJSTests:(id)sender
[jsc loadFrameworkWithName:@"WebKit"]; [jsc loadFrameworkWithName:@"WebKit"];
webViewClass = objc_getClass("WebView"); webViewClass = objc_getClass("WebView");
} }
if (webViewClass && test_webview) if (webViewClass)
{ {
// NSLog(@"Testing initing from a WebView"); // NSLog(@"Testing initing from a WebView");
// Load nib // Load nib
Expand Down Expand Up @@ -188,7 +187,8 @@ - (IBAction)runJSTests:(id)sender
} }
else else
{ {
NSLog(@"WebKit not loaded - cannot test JSCocoa inited from a WebView"); if (test_webview)
NSLog(@"WebKit not loaded - cannot test JSCocoa inited from a WebView");
} }




Expand Down Expand Up @@ -240,8 +240,6 @@ - (IBAction)runJSTests:(id)sender
id r = [o performSelector:[@"だけを追加する:" UTF8String] withObject:[NSNumber numberWithInt:7]]; id r = [o performSelector:[@"だけを追加する:" UTF8String] withObject:[NSNumber numberWithInt:7]];
NSLog(@"r=%@", r); NSLog(@"r=%@", r);
*/ */
NSLog(@"DOUBLE CYCLE");
// [self cycleContext];
} }




Expand Down Expand Up @@ -956,9 +954,11 @@ - (void)finishTest37:(BOOL)b




NSLog(@"JSC2 not deallocated"); NSLog(@"JSC2 not deallocated");

NSLog(@"unlinking...");
[jsc2 unlinkAllReferences]; [jsc2 unlinkAllReferences];
NSLog(@"collecting...");
[jsc2 garbageCollect]; [jsc2 garbageCollect];
NSLog(@"releasing...");
[jsc2 release]; [jsc2 release];
jsc2 = nil; jsc2 = nil;


Expand Down

0 comments on commit 0c45a77

Please sign in to comment.