Title: [141914] trunk/Source/_javascript_Core
Revision
141914
Author
[email protected]
Date
2013-02-05 12:38:47 -0800 (Tue, 05 Feb 2013)

Log Message

Objective-C API: testapi.mm should use ARC
https://bugs.webkit.org/show_bug.cgi?id=107838

Reviewed by Oliver Hunt.

In ToT testapi.mm uses the Obj-C garbage collector, which hides a lot of our object lifetime bugs.
We should enable ARC, since that is what most of our clients will be using. We use Xcode project
settings to make sure we don't try to compile ARC on 32-bit.

* API/tests/testapi.mm:
(+[TestObject testObject]):
(testObjectiveCAPI):
* _javascript_Core.xcodeproj/project.pbxproj:

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/tests/testapi.mm (141913 => 141914)


--- trunk/Source/_javascript_Core/API/tests/testapi.mm	2013-02-05 20:34:21 UTC (rev 141913)
+++ trunk/Source/_javascript_Core/API/tests/testapi.mm	2013-02-05 20:38:47 UTC (rev 141914)
@@ -25,8 +25,8 @@
 
 #import "_javascript_Core.h"
 
-extern "C" bool _Block_has_signature(void *);
-extern "C" const char * _Block_signature(void *);
+extern "C" bool _Block_has_signature(id);
+extern "C" const char * _Block_signature(id);
 
 extern int failed;
 extern "C" void testObjectiveCAPI(void);
@@ -71,7 +71,7 @@
 @synthesize point;
 + (id)testObject
 {
-    return [[[TestObject alloc] init] autorelease];
+    return [[TestObject alloc] init];
 }
 + (NSString *)classTest
 {
@@ -136,26 +136,26 @@
     NSLog(@"Testing Objective-C API");
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         JSValue *result = [context evaluateScript:@"2 + 2"];
         checkResult(@"2 + 2", [result isNumber] && [result toInt32] == 4);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         NSString *result = [NSString stringWithFormat:@"Two plus two is %@", [context evaluateScript:@"2 + 2"]];
         checkResult(@"stringWithFormat", [result isEqual:@"Two plus two is 4"]);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"message"] = @"Hello";
         JSValue *result = [context evaluateScript:@"message + ', World!'"];
         checkResult(@"Hello, World!", [result isString] && [result isEqualToObject:@"Hello, World!"]);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         JSValue *result = [context evaluateScript:@"({ x:42 })"];
         checkResult(@"({ x:42 })", [result isObject] && [result[@"x"] isEqualToObject:@42]);
         id obj = [result toObject];
@@ -165,7 +165,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         __block int result;
         context[@"blockCallback"] = ^(int value){
             result = value;
@@ -176,7 +176,7 @@
 
     if (blockSignatureContainsClass()) {
         @autoreleasepool {
-            JSContext *context = [[[JSContext alloc] init] autorelease];
+            JSContext *context = [[JSContext alloc] init];
             __block bool result = false;
             context[@"blockCallback"] = ^(NSString *value){
                 result = [@"42" isEqualToString:value] == YES;
@@ -188,14 +188,14 @@
         NSLog(@"Skipping 'blockCallback(NSString *)' test case");
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         checkResult(@"!context.exception", !context.exception);
         [context evaluateScript:@"!@#$%^&*() THIS IS NOT VALID _javascript_ SYNTAX !@#$%^&*()"];
         checkResult(@"context.exception", context.exception);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         __block bool caught = false;
         context.exceptionHandler = ^(JSContext *context, JSValue *exception) {
             (void)context;
@@ -207,7 +207,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"callback"] = ^{
             JSContext *context = [JSContext currentContext];
             context.exception = [JSValue valueWithNewErrorFromMessage:@"Something went wrong." inContext:context];
@@ -218,7 +218,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"callback"] = ^{
             JSContext *context = [JSContext currentContext];
             [context evaluateScript:@"!@#$%^&*() THIS IS NOT VALID _javascript_ SYNTAX !@#$%^&*()"];
@@ -229,7 +229,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         [context evaluateScript:
             @"function sum(array) { \
                 var result = 0; \
@@ -244,7 +244,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         JSValue *mulAddFunction = [context evaluateScript:
             @"(function(array, object) { \
                 var result = []; \
@@ -257,7 +257,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];        
+        JSContext *context = [[JSContext alloc] init];        
         JSValue *array = [JSValue valueWithNewArrayInContext:context];
         checkResult(@"arrayLengthEmpty", [[array[@"length"] toNumber] unsignedIntegerValue] == 0);
         JSValue *value1 = [JSValue valueWithInt32:42 inContext:context];
@@ -285,7 +285,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         JSValue *object = [JSValue valueWithNewObjectInContext:context];
 
         object[@"point"] = @{ @"x":@1, @"y":@2 };
@@ -301,7 +301,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TextXYZ *testXYZ = [[TextXYZ alloc] init];
         context[@"testXYZ"] = testXYZ;
         testXYZ.x = 3;
@@ -315,7 +315,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         [context[@"Object"][@"prototype"] defineProperty:@"getterProperty" descriptor:@{
             JSPropertyDescriptorGetKey:^{
                 return [JSContext currentThis][@"x"];
@@ -327,7 +327,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"concatenate"] = ^{
             NSArray *arguments = [JSContext currentArguments];
             if (![arguments count])
@@ -342,7 +342,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"foo"] = @YES;
         checkResult(@"@YES is boolean", [context[@"foo"] isBoolean]);
         JSValue *result = [context evaluateScript:@"typeof foo"];
@@ -350,7 +350,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         JSValue *result = [context evaluateScript:@"String(testObject)"];
@@ -358,7 +358,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         JSValue *result = [context evaluateScript:@"String(testObject.__proto__)"];
@@ -366,27 +366,27 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"TestObject"] = [TestObject class];
         JSValue *result = [context evaluateScript:@"String(TestObject)"];
         checkResult(@"String(TestObject)", [result isEqualToObject:@"[object TestObjectConstructor]"]);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         JSValue* value = [JSValue valueWithObject:[TestObject class] inContext:context];
         checkResult(@"[value toObject] == [TestObject class]", [value toObject] == [TestObject class]);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"TestObject"] = [TestObject class];
         JSValue *result = [context evaluateScript:@"TestObject.parentTest()"];
         checkResult(@"TestObject.parentTest()", [result isEqualToObject:@"TestObject"]);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObjectA"] = testObject;
         context[@"testObjectB"] = testObject;
@@ -395,7 +395,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         testObject.point = (CGPoint){3,4};
@@ -405,7 +405,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         testObject.six = 6;
         context[@"testObject"] = testObject;
@@ -415,7 +415,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         context[@"testObject"][@"variable"] = @4;
@@ -424,21 +424,21 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"point"] = @{ @"x":@6, @"y":@7 };
         JSValue *result = [context evaluateScript:@"point.x + ',' + point.y"];
         checkResult(@"point.x + ',' + point.y", [result isEqualToObject:@"6,7"]);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         context[@"point"] = @{ @"x":@6, @"y":@7 };
         JSValue *result = [context evaluateScript:@"point.x + ',' + point.y"];
         checkResult(@"point.x + ',' + point.y", [result isEqualToObject:@"6,7"]);
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         JSValue *result = [context evaluateScript:@"testObject.getString()"];
@@ -446,7 +446,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         JSValue *result = [context evaluateScript:@"testObject.testArgumentTypes(101,0.5,true,'foo',666,[false,'bar',false],{x:'baz'})"];
@@ -454,7 +454,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         JSValue *result = [context evaluateScript:@"testObject.getString.call(testObject)"];
@@ -462,7 +462,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         checkResult(@"testObject.getString.call({}) pre", !context.exception);
@@ -471,7 +471,7 @@
     }
 
     @autoreleasepool {
-        JSContext *context = [[[JSContext alloc] init] autorelease];
+        JSContext *context = [[JSContext alloc] init];
         TestObject* testObject = [TestObject testObject];
         context[@"testObject"] = testObject;
         JSValue *result = [context evaluateScript:@"var result = 0; testObject.callback(function(x){ result = x; }); result"];
@@ -487,8 +487,6 @@
         JSValue *result = [context1 evaluateScript:@"passValueBetweenContexts"];
         checkResult(@"result.context == context1", result.context == context1);
         checkResult(@"[value isEqualToObject:result]", [value isEqualToObject:result]);
-        [context1 release];
-        [context2 release];
     }
 }
 

Modified: trunk/Source/_javascript_Core/ChangeLog (141913 => 141914)


--- trunk/Source/_javascript_Core/ChangeLog	2013-02-05 20:34:21 UTC (rev 141913)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-02-05 20:38:47 UTC (rev 141914)
@@ -1,3 +1,19 @@
+2013-02-05  Mark Hahnenberg  <[email protected]>
+
+        Objective-C API: testapi.mm should use ARC
+        https://bugs.webkit.org/show_bug.cgi?id=107838
+
+        Reviewed by Oliver Hunt.
+
+        In ToT testapi.mm uses the Obj-C garbage collector, which hides a lot of our object lifetime bugs.
+        We should enable ARC, since that is what most of our clients will be using. We use Xcode project 
+        settings to make sure we don't try to compile ARC on 32-bit.
+
+        * API/tests/testapi.mm:
+        (+[TestObject testObject]):
+        (testObjectiveCAPI):
+        * _javascript_Core.xcodeproj/project.pbxproj:
+
 2013-02-05  Brent Fulgham  <[email protected]>
 
         [Windows] Unreviewed VS2010 Build Correction after r141651

Modified: trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj (141913 => 141914)


--- trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2013-02-05 20:34:21 UTC (rev 141913)
+++ trunk/Source/_javascript_Core/_javascript_Core.xcodeproj/project.pbxproj	2013-02-05 20:38:47 UTC (rev 141914)
@@ -4192,6 +4192,12 @@
 			isa = XCBuildConfiguration;
 			baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
 			buildSettings = {
+				CLANG_ENABLE_OBJC_ARC = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=*]" = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=i386]" = NO;
+				GCC_ENABLE_OBJC_GC_macosx = "";
+				"GCC_ENABLE_OBJC_GC_macosx[arch=*]" = NO;
+				"GCC_ENABLE_OBJC_GC_macosx[arch=i386]" = YES;
 			};
 			name = Debug;
 		};
@@ -4199,6 +4205,12 @@
 			isa = XCBuildConfiguration;
 			baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
 			buildSettings = {
+				CLANG_ENABLE_OBJC_ARC = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=*]" = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=i386]" = NO;
+				GCC_ENABLE_OBJC_GC_macosx = "";
+				"GCC_ENABLE_OBJC_GC_macosx[arch=*]" = NO;
+				"GCC_ENABLE_OBJC_GC_macosx[arch=i386]" = YES;
 			};
 			name = Release;
 		};
@@ -4206,6 +4218,12 @@
 			isa = XCBuildConfiguration;
 			baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
 			buildSettings = {
+				CLANG_ENABLE_OBJC_ARC = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=*]" = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=i386]" = NO;
+				GCC_ENABLE_OBJC_GC_macosx = "";
+				"GCC_ENABLE_OBJC_GC_macosx[arch=*]" = NO;
+				"GCC_ENABLE_OBJC_GC_macosx[arch=i386]" = YES;
 			};
 			name = Production;
 		};
@@ -4327,6 +4345,12 @@
 			isa = XCBuildConfiguration;
 			baseConfigurationReference = BC021BF2136900C300FC5467 /* ToolExecutable.xcconfig */;
 			buildSettings = {
+				CLANG_ENABLE_OBJC_ARC = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=*]" = YES;
+				"CLANG_ENABLE_OBJC_ARC[arch=i386]" = NO;
+				GCC_ENABLE_OBJC_GC_macosx = "";
+				"GCC_ENABLE_OBJC_GC_macosx[arch=*]" = NO;
+				"GCC_ENABLE_OBJC_GC_macosx[arch=i386]" = YES;
 			};
 			name = Profiling;
 		};
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to