Browse files

Fixed WebView context crash (37, manually unlink before destroying th…

…e webView) and NSArray functions (39, class method privateFunctionInContext badly translated as privateObject instead of privateFunction))
  • Loading branch information...
1 parent 0a8714e commit 965cc437be43af635817c49c16699b0fd5b5b3ac @parmanoir committed Aug 3, 2011
Showing with 28,619 additions and 12,434 deletions.
  1. +78 −46 JSCocoa/JSCocoaController.m
  2. +5 −5 JSCocoa/JSCocoaFFIArgument.m
  3. +1 −1 JSCocoa/JSCocoaFFIClosure.m
  4. +5 −0 JSCocoa/JSCocoaLib.m
  5. +4 −4 JSCocoa/JSCocoaPrivateObject.m
  6. +2 −1 JSCocoa/class.js
  7. 0 Tests/{ → ! stock}/37 init from webview.js
  8. 0 Tests/{! stock → }/40 ObjJ syntax.js
  9. 0 Tests/{! stock → }/41 class inner js functions.js
  10. 0 Tests/{! stock → }/42 return if.js
  11. 0 Tests/{! stock → }/43 @ string and selector.js
  12. 0 Tests/{! stock → }/44 instanceWith.js
  13. 0 Tests/{! stock → }/45 ƒ function shortcut.js
  14. 0 Tests/{! stock → }/46 exceptions.js
  15. 0 Tests/{! stock → }/47 ObjJ syntax super.js
  16. 0 Tests/{! stock → }/48 ObjJ syntax compatibility.js
  17. 0 Tests/{! stock → }/49 out pointer.js
  18. 0 Tests/{! stock → }/50 setValueForKey op.js
  19. 0 Tests/{! stock → }/51 ObjC blocks.js
  20. 0 Tests/{! stock → }/52 line and sourceURL.js
  21. 0 Tests/{! stock → }/53 Unicode ObjC classes.js
  22. 0 Tests/{! stock → }/54 custom indexed access.js
  23. 0 Tests/{! stock → }/55 javascript method override.js
  24. 0 Tests/{! stock → }/56 whitespace.js
  25. +3 −2 Tests/Resources/37 inited from webview.html
  26. +32 −13 TestsRunner/ApplicationController.m
  27. +6 −4 TestsRunner/English.lproj/MainMenu.xib
  28. +28,482 −12,353 ...tsRunner.xcodeproj/project.xcworkspace/xcuserdata/mini.xcuserdatad/UserInterfaceState.xcuserstate
  29. +1 −1 TestsRunner/TestsRunner.xcodeproj/xcuserdata/mini.xcuserdatad/xcschemes/TestsRunner.xcscheme
  30. +0 −4 TestsRunner/main.m
View
124 JSCocoa/JSCocoaController.m
@@ -135,7 +135,7 @@ @implementation JSCocoaController
//
- (id)initWithGlobalContext:(JSGlobalContextRef)_ctx
{
- NSLog(@"JSCocoa : %llx spawning with context %llx", self, _ctx);
+ NSLog(@"JSCocoa : %p spawning with context %p", self, _ctx);
self = [super init];
controllerCount++;
@@ -308,7 +308,7 @@ - (id)initWithGlobalContext:(JSGlobalContextRef)_ctx
ownsContext = NO;
[JSCocoa updateCustomCallPaths];
- NSLog(@"JSCocoa spawned with context %llx", ctx);
+ NSLog(@"JSCocoa spawned with context %p", ctx);
return self;
}
@@ -325,11 +325,19 @@ - (id)init
//
- (void)cleanUp
{
- NSLog(@"JSCocoa : %llx dying", self);
+ NSLog(@"JSCocoa : %p dying", self);
[boxedObjects release];
[self setUseSafeDealloc:NO];
- [self unlinkAllReferences];
- JSGarbageCollect(ctx);
+
+ // Cleanup if we created the JavascriptCore context.
+ // If not, let user do it. In a WebView, this method will be called during JS GC,
+ // and trying to execute more JS code will fail.
+ // User must clean up manually by calling unlinkAllReferences then destroying the webView
+ if (ownsContext) {
+ [self unlinkAllReferences];
+ JSGarbageCollect(ctx);
+ JSGlobalContextRelease(ctx);
+ }
controllerCount--;
if (controllerCount == 0)
@@ -384,13 +392,11 @@ - (void)cleanUp
}
- if (ownsContext)
- JSGlobalContextRelease(ctx);
}
- (oneway void)release
{
- NSLog(@"jsc %llx OUT\n***\n%@\n***\n", self, [NSThread callStackSymbols]);
+ NSLog(@"jsc %p OUT\n***\n%@\n***\n", self, [NSThread callStackSymbols]);
//NSLog(@"RET!"); return;
// Each controller adds itself to its Javascript context, therefore retain count will be two when user last calls release.
// We check for this and clean up references then call GC, which will lower retain count to 1.
@@ -401,10 +407,14 @@ - (oneway void)release
// This will take retain count from 2 to 1, readying this instance for deallocation
// Only collect if we own the context, has a WebView might be deallocating us while it's collecting its garbage
+
+ NSLog(@"COMMENTED RELEASE : need to remove our variable");
+/*
if (ownsContext) {
[self unlinkAllReferences];
[self garbageCollect];
}
+*/
}
[super release];
}
@@ -439,7 +449,7 @@ + (id)sharedController
// Why ? if init is calling sharedController, the pointer won't have been set and it will call itself over and over again.
//
JSCocoaSingleton = [self alloc];
-// NSLog(@"JSCocoa : allocating shared instance %llx", JSCocoaSingleton);
+// NSLog(@"JSCocoa : allocating shared instance %p", JSCocoaSingleton);
[JSCocoaSingleton init];
}
}
@@ -459,7 +469,7 @@ + (id)controllerFromContext:(JSContextRef)ctx
id jsc = nil;
[JSCocoaFFIArgument unboxJSValueRef:jsValue toObject:&jsc inContext:ctx];
// Commented as it falsely reports failure when controller is cleaning up while being deallocated
-// if (!jsc) NSLog(@"controllerFromContext couldn't find found the JSCocoaController in ctx %llx", ctx);
+// if (!jsc) NSLog(@"controllerFromContext couldn't find found the JSCocoaController in ctx %p", ctx);
return jsc;
}
@@ -1418,7 +1428,7 @@ + (BOOL)addMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRe
id jsc = [JSCocoaController controllerFromContext:valueAndContext.ctx];
id keyForClassAndMethod = [NSString stringWithFormat:@"%@ %@", class, methodName];
- id keyForFunction = [NSString stringWithFormat:@"%llx", valueAndContext.value];
+ id keyForFunction = [NSString stringWithFormat:@"%p", valueAndContext.value];
id privateObject = [[JSCocoaPrivateObject alloc] init];
[privateObject setJSValueRef:valueAndContext.value ctx:[jsc ctx]];
@@ -1437,7 +1447,7 @@ + (BOOL)addMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRe
SEL selector = NSSelectorFromString(methodName);
id keyForClassAndMethod = [NSString stringWithFormat:@"%@ %@", class, methodName];
- id keyForFunction = [NSString stringWithFormat:@"%llx", valueAndContext.value];
+ id keyForFunction = [NSString stringWithFormat:@"%p", valueAndContext.value];
id existingMethodForJSFunction = [closureHash valueForKey:keyForFunction];
if (existingMethodForJSFunction)
@@ -1446,7 +1456,7 @@ + (BOOL)addMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRe
return NO;
}
-// NSLog(@"keyForFunction=%llx for %@.%@", keyForFunction, class, methodName);
+// NSLog(@"keyForFunction=%p for %@.%@", keyForFunction, class, methodName);
id jsc = [JSCocoaController controllerFromContext:valueAndContext.ctx];
JSContextRef ctx = [jsc ctx];
@@ -1459,7 +1469,7 @@ + (BOOL)addMethod:(NSString*)methodName class:(Class)class jsFunction:(JSValueRe
// Closure cleanup - dangerous as instances might still be around AND IF dealloc/release is overloaded
if (existingPrivateObject)
{
- id keyForExistingFunction = [NSString stringWithFormat:@"%llx", [existingPrivateObject jsValueRef]];
+ id keyForExistingFunction = [NSString stringWithFormat:@"%p", [existingPrivateObject jsValueRef]];
[closureHash removeObjectForKey:keyForExistingFunction];
[jsFunctionSelectors removeObjectForKey:keyForExistingFunction];
@@ -1781,16 +1791,16 @@ - (BOOL)isFunctionVariadic:(id)functionName
//+ (JSObjectRef)boxedJSObject:(id)o inContext:(JSContextRef)ctx
- (JSObjectRef)boxObject:(id)o
{
- NSLog(@"QUICK FIX : key is ctx+llx, AND ctx is always the global context");
+// NSLog(@"QUICK FIX : key is ctx+llx, AND ctx is always the global context");
- id key = [NSString stringWithFormat:@"%llx", o];
+ id key = [NSString stringWithFormat:@"%p", o];
id value= [boxedObjects valueForKey:key];
- NSLog(@"boxing (in ctx %llx) %@ (key %@)", ctx, o, key);
+// NSLog(@"boxing (in ctx %p) %@ (key %@)", ctx, o, key);
// If object is boxed, up its usage count and return it
if (value)
{
- NSLog(@"CACHE HIT %@", key);
+// NSLog(@"CACHE HIT %@", key);
// NSLog(@"upusage %@ (rc=%d) %d", o, [o retainCount], [value usageCount]);
return [value jsObject];
}
@@ -1828,12 +1838,12 @@ - (JSObjectRef)boxObject:(id)o
}
- (BOOL)isObjectBoxed:(id)o {
- id key = [NSString stringWithFormat:@"%llx", o];
+ id key = [NSString stringWithFormat:@"%p", o];
return !![boxedObjects valueForKey:key];
}
- (void)deleteBoxOfObject:(id)o {
- id key = [NSString stringWithFormat:@"%llx", o];
+ id key = [NSString stringWithFormat:@"%p", o];
id value= [boxedObjects valueForKey:key];
if (!value)
return;
@@ -1843,7 +1853,7 @@ - (void)deleteBoxOfObject:(id)o {
/*
+ (void)downBoxedJSObjectCount:(id)o
{
- id key = [NSString stringWithFormat:@"%llx", o];
+ id key = [NSString stringWithFormat:@"%p", o];
id value = [boxedObjects valueForKey:key];
if (!value)
return;
@@ -1859,12 +1869,12 @@ + (id)boxedObjects
#pragma mark Helpers
- (id)selectorForJSFunction:(JSObjectRef)function
{
- return [jsFunctionSelectors valueForKey:[NSString stringWithFormat:@"%llx", function]];
+ return [jsFunctionSelectors valueForKey:[NSString stringWithFormat:@"%p", function]];
}
- (id)classForJSFunction:(JSObjectRef)function
{
- return [jsFunctionClasses valueForKey:[NSString stringWithFormat:@"%llx", function]];
+ return [jsFunctionClasses valueForKey:[NSString stringWithFormat:@"%p", function]];
}
//
@@ -2037,10 +2047,12 @@ - (void)garbageCollect {
//
- (void)unlinkAllReferences
{
- NSLog(@"WARNING ! Must build an array of first (Object.keys(this)), THEN an exception for each while we try to delete them");
// Null and delete every reference to every live object
// [self evalJSString:@"for (var i in this) { log('DELETE ' + i); this[i] = null; delete this[i]; }"];
- [self evalJSString:@"for (var i in this) { this[i] = null; delete this[i]; }"];
+// [self evalJSString:@"for (var i in this) { this[i] = null; delete this[i]; }"];
+
+ id del = @"var keys = Object.keys(this); var c = keys.length; for (var i=0; i<c; i++) { try { this[keys[i]] = null } catch(e) {} }";
+ [self evalJSString:del];
// Everything is now collectable !
}
@@ -2052,7 +2064,7 @@ - (void)safeDeallocInstance:(id)sender
// This code might re-box the instance ...
[sender safeDealloc];
// So, clean it up
- [boxedObjects removeObjectForKey:[NSString stringWithFormat:@"%llx", sender]];
+ [boxedObjects removeObjectForKey:[NSString stringWithFormat:@"%p", sender]];
// sender is retained by performSelector, object will be destroyed upon function exit
}
@@ -2139,7 +2151,35 @@ + (void)logInstanceStats
- (void)logBoxedObjects
{
NSLog(@"====%ld boxedObjects====", (long)[[boxedObjects allKeys] count]);
- NSLog(@"%@", boxedObjects);
+ for (NSString* key in boxedObjects) {
+ BoxedJSObject* box = [boxedObjects valueForKey:key];
+ id o = [(JSCocoaPrivateObject*)JSObjectGetPrivate([box jsObject]) object];
+ if ([o retainCount] == -1) {
+ if ([o class] == o)
+ NSLog(@"%p (class) %@", o, o);
+ else
+ NSLog(@"%p (%@) %@", o, [o class], o);
+ } else {
+ NSLog(@"%p (%@)", o, [o class]);
+ }
+
+/*
+ id boxedObject = [(JSCocoaPrivateObject*)JSObjectGetPrivate(jsObject) object];
+ id retainCount = [NSString stringWithFormat:@"%d", [boxedObject retainCount]];
+#if !TARGET_OS_IPHONE
+ retainCount = [NSGarbageCollector defaultCollector] ? @"Running GC" : [NSString stringWithFormat:@"%d", [boxedObject retainCount]];
+#endif
+ return [NSString stringWithFormat:@"<%@: %p holding %@ %@: %p (retainCount=%@)>",
+ [self class],
+ self,
+ ((id)self == (id)[self class]) ? @"Class" : @"",
+ [boxedObject class],
+ boxedObject,
+ retainCount];
+*/
+
+ }
+// NSLog(@"%@", boxedObjects);
}
#pragma mark Class inspection
@@ -3092,7 +3132,7 @@ JSValueRef boxedValueFromExternalContext(JSContextRef externalCtx, JSValueRef va
JSObjectRef o;
if (JSValueIsBoolean(externalCtx, result))
// o = [JSCocoaController jsCocoaPrivateFunctionInContext:ctx];
- o = [[JSCocoa controllerFromContext:ctx] newPrivateObject];
+ o = [[JSCocoa controllerFromContext:ctx] newPrivateFunction];
else
// o = [JSCocoaController jsCocoaPrivateObjectInContext:ctx];
o = [[JSCocoa controllerFromContext:ctx] newPrivateFunction];
@@ -3236,7 +3276,7 @@ static void jsCocoaObject_finalize(JSObjectRef object)
id boxedObject = [private object];
if (boxedObject)
{
-// id key = [NSString stringWithFormat:@"%llx", boxedObject];
+// id key = [NSString stringWithFormat:@"%p", boxedObject];
// Object may have been already deallocated
// id existingBoxedObject = [boxedObjects objectForKey:key];
// id existingBoxedObject = [jsc boxedObject];
@@ -3315,12 +3355,8 @@ static JSValueRef jsCocoaObject_getProperty(JSContextRef ctx, JSObjectRef object
[NSMakeCollectable(propertyName) autorelease];
JSCocoaPrivateObject* privateObject = JSObjectGetPrivate(object);
- NSLog(@"Asking for property %@ %@(%@)", propertyName, privateObject, privateObject.type);
+// NSLog(@"Asking for property %@ %@(%@)", propertyName, privateObject, privateObject.type);
- if ([propertyName hasPrefix:@"sharedA"]) {
- NSLog(@"there");
- }
-
// Get delegate
JSCocoaController* jsc = [JSCocoaController controllerFromContext:ctx];
id delegate = jsc.delegate;
@@ -3394,7 +3430,7 @@ static JSValueRef jsCocoaObject_getProperty(JSContextRef ctx, JSObjectRef object
{
// NSLog(@"*** array method : %@", propertyName);
// JSObjectRef o = [JSCocoaController jsCocoaPrivateFunctionInContext:ctx];
- JSObjectRef o = [jsc newPrivateObject];
+ JSObjectRef o = [jsc newPrivateFunction];
JSCocoaPrivateObject* private = JSObjectGetPrivate(o);
private.type = @"jsFunction";
[private setJSValueRef:result ctx:ctx];
@@ -3454,7 +3490,7 @@ static JSValueRef jsCocoaObject_getProperty(JSContextRef ctx, JSObjectRef object
JSStringRelease(scriptJS);
BOOL isNativeCode = result ? JSValueToBoolean(ctx, result) : NO;
returnHashValue = !isNativeCode;
-// NSLog(@"isNative(%@)=%d rawJSResult=%llx hashProperty=%llx returnHashValue=%d", propertyName, isNativeCode, result, hashProperty, returnHashValue);
+// NSLog(@"isNative(%@)=%d rawJSResult=%p hashProperty=%p returnHashValue=%d", propertyName, isNativeCode, result, hashProperty, returnHashValue);
}
if (returnHashValue) return hashProperty;
}
@@ -3484,7 +3520,6 @@ static JSValueRef jsCocoaObject_getProperty(JSContextRef ctx, JSObjectRef object
if ([jsc useAutoCall])
{
callee = [privateObject object];
- NSLog(@"%@.%@", [callee class], propertyName);
SEL sel = NSSelectorFromString(propertyName);
BOOL isInstanceCall = [propertyName isEqualToString:@"instance"];
@@ -3829,7 +3864,7 @@ static bool jsCocoaObject_setProperty(JSContextRef ctx, JSObjectRef object, JSSt
NSString* propertyName = (NSString*)JSStringCopyCFString(kCFAllocatorDefault, propertyNameJS);
[NSMakeCollectable(propertyName) autorelease];
-// NSLog(@"****SET %@ in ctx %llx on object %llx (type=%@) method=%@", propertyName, ctx, object, privateObject.type, privateObject.methodName);
+// NSLog(@"****SET %@ in ctx %p on object %p (type=%@) method=%@", propertyName, ctx, object, privateObject.type, privateObject.methodName);
// Get delegate
JSCocoaController* jsc = [JSCocoaController controllerFromContext:ctx];
@@ -4444,7 +4479,7 @@ static JSValueRef jsCocoaObject_callAsFunction_ffi(JSContextRef ctx, JSObjectRef
#endif
superPointer = &_super;
values[0] = &superPointer;
-// NSLog(@"superClass=%@ (old=%@) (%@) function=%llx", superSelectorClass, [callee superclass], [callee class], function);
+// NSLog(@"superClass=%@ (old=%@) (%@) function=%p", superSelectorClass, [callee superclass], [callee class], function);
}
}
@@ -5011,23 +5046,20 @@ @implementation JSCocoa
//
@implementation BoxedJSObject
-- (void)setJSObject:(JSObjectRef)o
-{
+- (void)setJSObject:(JSObjectRef)o {
jsObject = o;
}
-- (JSObjectRef)jsObject
-{
+- (JSObjectRef)jsObject {
return jsObject;
}
-- (id)description
-{
+- (id)description {
id boxedObject = [(JSCocoaPrivateObject*)JSObjectGetPrivate(jsObject) object];
id retainCount = [NSString stringWithFormat:@"%d", [boxedObject retainCount]];
#if !TARGET_OS_IPHONE
retainCount = [NSGarbageCollector defaultCollector] ? @"Running GC" : [NSString stringWithFormat:@"%d", [boxedObject retainCount]];
#endif
- return [NSString stringWithFormat:@"<%@: %llx holding %@ %@: %llx (retainCount=%@)>",
+ return [NSString stringWithFormat:@"<%@: %p holding %@ %@: %p (retainCount=%@)>",
[self class],
self,
((id)self == (id)[self class]) ? @"Class" : @"",
View
10 JSCocoa/JSCocoaFFIArgument.m
@@ -64,7 +64,7 @@ - (void)finalize
- (NSString*)description
{
- return [NSString stringWithFormat:@"JSCocoaFFIArgument %llx typeEncoding=%c %@ isReturnValue=%d storage=%llx", self,
+ return [NSString stringWithFormat:@"JSCocoaFFIArgument %p typeEncoding=%c %@ isReturnValue=%d storage=%p", self,
typeEncoding,
(structureTypeEncoding ? structureTypeEncoding : @""),
isReturnValue, ptr];
@@ -276,7 +276,7 @@ - (void*)allocateStorage
if (isReturnValue && size < minimalReturnSize) size = minimalReturnSize;
ptr = malloc(size);
}
-// NSLog(@"Allocated size=%d (%llx) for object %@", size, ptr, self);
+// NSLog(@"Allocated size=%d (%p) for object %@", size, ptr, self);
return ptr;
}
@@ -366,7 +366,7 @@ + (BOOL)fromJSValueRef:(JSValueRef)value inContext:(JSContextRef)ctx typeEncodin
if (!typeEncoding) return NO;
// JSType type = JSValueGetType(ctx, value);
-// NSLog(@"JSType=%d encoding=%c self=%llx", type, typeEncoding, self);
+// NSLog(@"JSType=%d encoding=%c self=%p", type, typeEncoding, self);
switch (typeEncoding)
{
@@ -526,7 +526,7 @@ + (BOOL)toJSValueRef:(JSValueRef*)value inContext:(JSContextRef)ctx typeEncoding
{
if (!typeEncoding) return NO;
-// NSLog(@"toJSValueRef: %c ptr=%llx", typeEncoding, ptr);
+// NSLog(@"toJSValueRef: %c ptr=%p", typeEncoding, ptr);
switch (typeEncoding)
{
case _C_ID:
@@ -764,7 +764,7 @@ + (NSInteger)structureFromJSObjectRef:(JSObjectRef)object inContext:(JSContextRe
JSStringRelease(propertyNameJS);
// JSObjectRef objectProperty2 = JSValueToObject(ctx, valueJS, NULL);
-// NSLog(@"%c %@ %llx %llx", encoding, propertyName, valueJS, objectProperty2);
+// NSLog(@"%c %@ %p %p", encoding, propertyName, valueJS, objectProperty2);
if (encoding == '{')
{
if (JSValueIsObject(ctx, valueJS))
View
2 JSCocoa/JSCocoaFFIClosure.m
@@ -54,7 +54,7 @@ - (void)cleanUp
}
- (void)dealloc
{
-// NSLog(@"deallocing closure %llx IMP=%llx", self, closure);
+// NSLog(@"deallocing closure %p IMP=%p", self, closure);
[self cleanUp];
[super dealloc];
}
View
5 JSCocoa/JSCocoaLib.m
@@ -146,6 +146,11 @@ - (id)initWithTypes:(id)_types
if (size == -1) return NSLog(@"JSCocoaMemoryBuffer initWithTypes : unknown type %c", types[i]), self;
bufferSize += size;
}
+
+ if (bufferSize == 0) {
+ NSLog(@"initWithTypes has no types");
+ return NULL;
+ }
// Malloc
// NSLog(@"mallocing %d bytes for %@", bufferSize, typeString);
View
8 JSCocoa/JSCocoaPrivateObject.m
@@ -37,7 +37,7 @@ - (void)cleanUp
[JSCocoaController downJSCocoaPrivateObjectCount];
if (object && retainObject)
{
- NSLog(@"commented downBoxedJSObjectCount");
+// NSLog(@"commented downBoxedJSObjectCount");
// [JSCocoaController downBoxedJSObjectCount:object];
// NSLog(@"releasing %@(%d)", [object class], [object retainCount]);
// if ([object isKindOfClass:[JSCocoaController class]])
@@ -68,7 +68,7 @@ - (void)cleanUp
/*
if (retainContext)
{
- NSLog(@"releasing %llx", ctx);
+ NSLog(@"releasing %p", ctx);
JSContextGroupRelease(contextGroup);
// JSGlobalContextRelease((JSGlobalContextRef)ctx);
}
@@ -204,8 +204,8 @@ - (id)rawPointerEncoding
- (id)description
{
id extra = @"";
- if ([type isEqualToString:@"rawPointer"]) extra = [NSString stringWithFormat:@" (%llx) %@", rawPointer, declaredType];
- return [NSString stringWithFormat:@"<%@: %llx holding %@%@>",
+ if ([type isEqualToString:@"rawPointer"]) extra = [NSString stringWithFormat:@" (%p) %@", rawPointer, declaredType];
+ return [NSString stringWithFormat:@"<%@: %p holding %@%@>",
[self class],
self,
type,
View
3 JSCocoa/class.js
@@ -33,7 +33,8 @@
for (var i=0; i<l; i++)
{
var t = types[i]
- encodings[t] = JSCocoaFFIArgument.typeEncodingForType_(t)
+ // use new String to convert from a boxed NSString to a Javascript string
+ encodings[t] = new String(JSCocoaFFIArgument.typeEncodingForType_(t))
}
encodings['charpointer'] = encodings['char*']
encodings['IBAction'] = encodings['void']
View
0 Tests/37 init from webview.js → Tests/! stock/37 init from webview.js
File renamed without changes.
View
0 Tests/! stock/40 ObjJ syntax.js → Tests/40 ObjJ syntax.js
File renamed without changes.
View
0 Tests/! stock/41 class inner js functions.js → Tests/41 class inner js functions.js
File renamed without changes.
View
0 Tests/! stock/42 return if.js → Tests/42 return if.js
File renamed without changes.
View
0 Tests/! stock/43 @ string and selector.js → Tests/43 @ string and selector.js
File renamed without changes.
View
0 Tests/! stock/44 instanceWith.js → Tests/44 instanceWith.js
File renamed without changes.
View
0 Tests/! stock/45 ƒ function shortcut.js → Tests/45 ƒ function shortcut.js
File renamed without changes.
View
0 Tests/! stock/46 exceptions.js → Tests/46 exceptions.js
File renamed without changes.
View
0 Tests/! stock/47 ObjJ syntax super.js → Tests/47 ObjJ syntax super.js
File renamed without changes.
View
0 ...s/! stock/48 ObjJ syntax compatibility.js → Tests/48 ObjJ syntax compatibility.js
File renamed without changes.
View
0 Tests/! stock/49 out pointer.js → Tests/49 out pointer.js
File renamed without changes.
View
0 Tests/! stock/50 setValueForKey op.js → Tests/50 setValueForKey op.js
File renamed without changes.
View
0 Tests/! stock/51 ObjC blocks.js → Tests/51 ObjC blocks.js
File renamed without changes.
View
0 Tests/! stock/52 line and sourceURL.js → Tests/52 line and sourceURL.js
File renamed without changes.
View
0 Tests/! stock/53 Unicode ObjC classes.js → Tests/53 Unicode ObjC classes.js
File renamed without changes.
View
0 Tests/! stock/54 custom indexed access.js → Tests/54 custom indexed access.js
File renamed without changes.
View
0 .../! stock/55 javascript method override.js → Tests/55 javascript method override.js
File renamed without changes.
View
0 Tests/! stock/56 whitespace.js → Tests/56 whitespace.js
File renamed without changes.
View
5 Tests/Resources/37 inited from webview.html
@@ -31,7 +31,6 @@
if ('OSX' in this) log('JSCocoa is running')
else log('FAILED : JSCocoa is not running')
-
log('jsc=' + ('__jsc__' in this) + ' (' + __jsc__ + ')')
var objCDate = OSX.NSDate.alloc.init
@@ -41,6 +40,8 @@
objCDate = null
var delegate = OSX.NSApplication.sharedApplication.delegate
+
+
log('delegate=' + delegate)
log('NSDate.date=' + OSX.NSDate)
log('NSDate.date=' + OSX.NSDate.date)
@@ -87,8 +88,8 @@
log('NSDate(now)=' + OSX.NSDate.date)
log('NSDate=' + OSX.NSDate.valueOf())
log('OSX=' + OSX)
- delegate.finishTest37(true)
+ delegate.finishTest37(true)
document.getElementById('dump').innerHTML += '<br><h2 style="color: lime">OK</h2>'
}
catch(e)
View
45 TestsRunner/ApplicationController.m
@@ -36,6 +36,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
[[NSApplication sharedApplication] setDelegate:self];
NSLog(@"*** Running %@ ***", [JSCocoa runningArchitecture]);
+
/*
[self cycleContext];
NSLog(@"%d", [jsc retainCount]);
@@ -46,7 +47,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
[jsc garbageCollect];
*/
// Run tests
-// [self performSelector:@selector(runJSTests:) withObject:nil afterDelay:0];
+ [self performSelector:@selector(runJSTests:) withObject:nil afterDelay:0];
}
- (void)applicationWillTerminate:(NSNotification *)notification
@@ -180,7 +181,7 @@ - (IBAction)runJSTests:(id)sender
// Init JSCocoa from WebView's globalContext
JSGlobalContextRef ctx = [[webViewUsedAsContextSource mainFrame] globalContext];
-// NSLog(@"WebView contextGroup=%llx context=%llx", JSContextGetGroup(ctx), ctx);
+// NSLog(@"WebView contextGroup=%p context=%p", JSContextGetGroup(ctx), ctx);
jsc2 = [[JSCocoa alloc] initWithGlobalContext:ctx];
}
@@ -290,7 +291,10 @@ - (IBAction)logInstanceStats:(id)sender
- (IBAction)logBoxedObjects:(id)sender
{
+ NSLog(@"(jsc)");
[jsc logBoxedObjects];
+ NSLog(@"(jsc2, webView)");
+ [jsc2 logBoxedObjects];
}
- (void)log:(NSString*)message
@@ -517,7 +521,7 @@ - (id)testDelegate
canSet = YES;
canGetGlobal= NO;
ret = [jsc evalJSString:@"NSWorkspace"];
-// NSLog(@"ret=%llx %llx", ret, JSValueIsNull([jsc ctx], ret));
+// NSLog(@"ret=%p %p", ret, JSValueIsNull([jsc ctx], ret));
if (ret) return @"delegate canGetGlobalProperty failed (1)";
//
@@ -703,7 +707,7 @@ - (BOOL) JSCocoa:(JSCocoaController*)controller canGetProperty:(NSString*)_prope
}
- (JSValueRef) JSCocoa:(JSCocoaController*)controller getProperty:(NSString*)_propertyName ofObject:(id)_object inContext:(JSContextRef)ctx exception:(JSValueRef*)exception
{
-// NSLog(@"delegate get %@(%@).%@ customValueGet=%llx", _object, [_object class], _propertyName, customValueGet);
+// NSLog(@"delegate get %@(%@).%@ customValueGet=%p", _object, [_object class], _propertyName, customValueGet);
object = _object;
propertyName = _propertyName;
return customValueGet;
@@ -781,7 +785,7 @@ - (BOOL) JSCocoa:(JSCocoaController*)controller canGetGlobalProperty:(NSString*)
}
- (JSValueRef) JSCocoa:(JSCocoaController*)controller getGlobalProperty:(NSString*)_propertyName inContext:(JSContextRef)ctx exception:(JSValueRef*)exception
{
-// NSLog(@"getGlobalProperty %@ %llx", _propertyName, customValueGetGlobal);
+// NSLog(@"getGlobalProperty %@ %p", _propertyName, customValueGetGlobal);
propertyName = _propertyName;
return customValueGetGlobal;
}
@@ -881,9 +885,9 @@ - (IBAction)runSimpleTestFile:(id)sender
{
if (!jsc)
return;
- id js = @"2+2";
- js = @"NSWorkspace.sharedWorkspace.activeApplication";
-
+ id js;
+// js = @"2+2";
+// js = @"NSWorkspace.sharedWorkspace.activeApplication";
js = @"var a = NSMakePoint(2, 3)";
[jsc garbageCollect];
JSValueRef ret2 = [jsc evalJSString:js];
@@ -947,17 +951,32 @@ - (void)finishTest37:(BOOL)b
if (!b) return;
[jsc callJSFunctionNamed:@"completeDelayedTest" withArguments:@"37 init from webview", [NSNumber numberWithInt:1], nil];
+
+ NSLog(@"JSC2 not deallocated");
+
+ [jsc2 unlinkAllReferences];
+ [jsc2 garbageCollect];
+ [jsc2 release];
+ jsc2 = nil;
+
+ NSLog(@"JSC2 DEALLOCATED");
+
+/*
NSLog(@"COMMENTED test 37 !");
- return;
- NSLog(@"jsc2 rc=%lu (%llx)", [jsc2 retainCount], self);
+// return;
+ NSLog(@"jsc2 rc=%lu (%p)", [jsc2 retainCount], self);
NSLog(@"get1 %@", [jsc2 eval:@"__jsc__"]);
// b = [jsc2 removeObjectWithName:@"__jsc__"];
[jsc2 garbageCollect];
NSLog(@"jsc2 rc=%lu (POST REMOVE %d)", [jsc2 retainCount], b);
NSLog(@"get2 %@", [jsc2 eval:@"__jsc__"]);
[jsc2 release];
+*/
+ NSLog(@"jsc2 rc=%lu (%p)", [jsc2 retainCount], self);
[topObjects release];
+ NSLog(@"jsc2 rc=%lu (%p)", [jsc2 retainCount], self);
+
topObjects = nil;
jsc2 = nil;
@@ -1004,7 +1023,7 @@ - (BOOL)callbackNSErrorWithClass:(NSErrorTest*)o
testNSError = nil;
}
NSError* error = nil;
-// NSLog(@"calling with pointer %llx", &error);
+// NSLog(@"calling with pointer %p", &error);
BOOL r = [o someMethodReturningAnError:&error];
if (error)
@@ -1045,7 +1064,7 @@ - (void)disposeShadowBindingsClasses
// Use JSValueRefAndContextRef
- (void)incorrectlySetJSValue:(JSValueRef)value
{
- NSLog(@"[%@ %@] got %llx", [self class], NSStringFromSelector(_cmd), value);
+ NSLog(@"[%@ %@] got %p", [self class], NSStringFromSelector(_cmd), value);
}
// Correctly set, testing holding on to it
@@ -1062,7 +1081,7 @@ - (void)setJSValue:(JSValueRefAndContextRef)vc
JSContextGroupRetain(JSContextGetGroup(vc.ctx));
JSGlobalContextRetain([jsc ctx]);
*/
- NSLog(@"ctx=%llx value=%llx globalctx=%llx", vc.ctx, vc.value, [jsc ctx]);
+ NSLog(@"ctx=%p value=%p globalctx=%p", vc.ctx, vc.value, [jsc ctx]);
}
- (JSValueRefAndContextRef)jsValue
{
View
10 TestsRunner/English.lproj/MainMenu.xib
@@ -1360,15 +1360,15 @@
<object class="NSTextField" id="835093140">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">290</int>
- <string key="NSFrame">{{31, 19}, {372, 12}}</string>
+ <string key="NSFrame">{{17, 20}, {386, 11}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView"/>
<bool key="NSEnabled">YES</bool>
<object class="NSTextFieldCell" key="NSCell" id="291550997">
<int key="NSCellFlags">68288064</int>
<int key="NSCellFlags2">272892928</int>
- <string key="NSContents"/>
+ <string key="NSContents">Text field</string>
<object class="NSFont" key="NSSupport">
<string key="NSName">LucidaGrande</string>
<double key="NSSize">9</double>
@@ -1408,6 +1408,7 @@
<int key="NSCellFlags2">272630784</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="943665204"/>
+ <string key="NSPlaceholderString">Type to eval, eg NSDate.date</string>
<reference key="NSControlView" ref="49564704"/>
<bool key="NSDrawsBackground">YES</bool>
<object class="NSColor" key="NSBackgroundColor" id="336928000">
@@ -1430,7 +1431,7 @@
<object class="NSTextField" id="118854190">
<reference key="NSNextResponder" ref="439893737"/>
<int key="NSvFlags">274</int>
- <string key="NSFrame">{{20, 20}, {380, 95}}</string>
+ <string key="NSFrame">{{20, 39}, {380, 76}}</string>
<reference key="NSSuperview" ref="439893737"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="835093140"/>
@@ -1440,6 +1441,7 @@
<int key="NSCellFlags2">272629760</int>
<string key="NSContents"/>
<reference key="NSSupport" ref="943665204"/>
+ <string key="NSPlaceholderString">Eval results</string>
<reference key="NSControlView" ref="118854190"/>
<bool key="NSDrawsBackground">YES</bool>
<reference key="NSBackgroundColor" ref="336928000"/>
@@ -2943,13 +2945,13 @@
<reference ref="1051573598"/>
<reference ref="872062680"/>
<reference ref="49564704"/>
- <reference ref="835093140"/>
<reference ref="118854190"/>
<reference ref="934852353"/>
<reference ref="362537091"/>
<reference ref="778899845"/>
<reference ref="481926543"/>
<reference ref="835348829"/>
+ <reference ref="835093140"/>
</object>
<reference key="parent" ref="972006081"/>
</object>
View
40,835 ....xcodeproj/project.xcworkspace/xcuserdata/mini.xcuserdatad/UserInterfaceState.xcuserstate
28,482 additions, 12,353 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 TestsRunner/TestsRunner.xcodeproj/xcuserdata/mini.xcuserdatad/xcschemes/TestsRunner.xcscheme
@@ -68,7 +68,7 @@
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
- buildConfiguration = "Release">
+ buildConfiguration = "Debug">
<BuildableProductRunnable>
<BuildableReference
BuildableIdentifier = "primary"
View
4 TestsRunner/main.m
@@ -11,9 +11,5 @@
int main(int argc, char *argv[])
{
-// [[NSAutoreleasePool alloc] init];
-// [JSCocoaController allocAutoreleasePool];
-// [JSCocoaController sharedController];
-
return NSApplicationMain(argc, (const char **) argv);
}

0 comments on commit 965cc43

Please sign in to comment.