Reviewed by Maciej.
authordarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Jun 2004 07:38:52 +0000 (07:38 +0000)
committerdarin <darin@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 15 Jun 2004 07:38:52 +0000 (07:38 +0000)
        - fixed some things for GC that Patrick missed, or that happened after the branch

        * bindings/objc/WebScriptObject.mm:
        (-[WebScriptObject dealloc]): Moved removeNativeReference call here from private object.
        (-[WebScriptObject finalize]): Added.

        - added some missing nil checks

        * bindings/objc/objc_instance.mm:
        (ObjcInstance::ObjcInstance): Check for nil.
        (ObjcInstance::~ObjcInstance): Check for nil.
        (ObjcInstance::operator=): Check for nil.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@6846 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/bindings/objc/WebScriptObject.mm
JavaScriptCore/bindings/objc/objc_instance.mm

index bdf392d3f198c9d9a699623ec31f0c064e4943a5..fa34aa3772671f95af767ff475d21f6e6bfb873f 100644 (file)
@@ -1,3 +1,20 @@
+2004-06-14  Darin Adler  <darin@apple.com>
+
+        Reviewed by Maciej.
+
+        - fixed some things for GC that Patrick missed, or that happened after the branch
+
+        * bindings/objc/WebScriptObject.mm:
+        (-[WebScriptObject dealloc]): Moved removeNativeReference call here from private object.
+        (-[WebScriptObject finalize]): Added.
+
+        - added some missing nil checks
+
+        * bindings/objc/objc_instance.mm:
+        (ObjcInstance::ObjcInstance): Check for nil.
+        (ObjcInstance::~ObjcInstance): Check for nil.
+        (ObjcInstance::operator=): Check for nil.
+
 2004-06-14  Darin Adler  <darin@apple.com>
 
         Reviewed by me, code changes by Patrick Beard.
index 854da8c17d5a4d9c3c237a64e5b041277a828692..6a38d6d784e6d33e6896edf125f32f44e494f246 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2003 Apple Computer, Inc.  All rights reserved.
+ * Copyright (C) 2004 Apple Computer, Inc.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -22,6 +22,7 @@
  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
  */
+
 #import <JavaScriptCore/WebScriptObjectPrivate.h>
 
 #include <JavaScriptCore/internal.h>
 #include <runtime_object.h>
 #include <runtime_root.h>
 
+#if MAC_OS_X_VERSION_MAX_ALLOWED <= MAC_OS_X_VERSION_10_3
+
+@interface NSObject (WebExtras)
+- (void)finalize;
+@end
+
+#endif
+
 using namespace KJS;
 using namespace KJS::Bindings;
 
@@ -43,12 +52,7 @@ using namespace KJS::Bindings;
         NSLog (@"%s:%d:  JavaScript exception:  %s\n", __FILE__, __LINE__, exec->exception().toObject(exec).get(exec, messagePropertyName).toString(exec).ascii());
 
 @implementation WebScriptObjectPrivate
-- (void)dealloc
-{
-    removeNativeReference (imp);
-    
-    [super dealloc];
-}
+
 @end
 
 @implementation WebScriptObject
@@ -95,11 +99,19 @@ static void _didExecute(WebScriptObject *obj)
 
 - (void)dealloc
 {
+    removeNativeReference(_private->imp);
     [_private release];
         
     [super dealloc];
 }
 
+- (void)finalize
+{
+    removeNativeReference(_private->imp);
+        
+    [super finalize];
+}
+
 + (BOOL)throwException:(NSString *)exceptionMessage
 {
     NSLog (@"%s:%d:  not yet implemented", __PRETTY_FUNCTION__, __LINE__);
index c3c9f6e2b906a340108e641f8433e12008f96e4b..78a879a7b1968b36ff16756bfda40b28addc3bb6 100644 (file)
@@ -41,7 +41,10 @@ using namespace KJS;
 
 ObjcInstance::ObjcInstance (ObjectStructPtr instance) 
 {
-    _instance = (id)CFRetain(instance);
+    _instance = (id)instance;
+    if (_instance) {
+        CFRetain(_instance);
+    }
     _class = 0;
     _pool = 0;
     _beginCount = 0;
@@ -51,12 +54,17 @@ ObjcInstance::~ObjcInstance ()
 {
     if ([_instance respondsToSelector:@selector(finalizeForWebScript)])
         [_instance finalizeForWebScript];
-    CFRelease(_instance);
+    if (_instance) {
+        CFRelease(_instance);
+    }
 }
 
 ObjcInstance::ObjcInstance (const ObjcInstance &other) : Instance() 
 {
-    _instance = (id) CFRetain(other._instance);
+    _instance = (id)other._instance;
+    if (_instance) {
+        CFRetain(_instance);
+    }
     _class = other._class;
     _pool = 0;
     _beginCount = 0;
@@ -65,8 +73,13 @@ ObjcInstance::ObjcInstance (const ObjcInstance &other) : Instance()
 ObjcInstance &ObjcInstance::operator=(const ObjcInstance &other)
 {
     ObjectStructPtr _oldInstance = _instance;
-    _instance = (id) CFRetain(other._instance);
-    CFRelease(_oldInstance);
+    _instance = other._instance;
+    if (_instance) {
+        CFRetain(_instance);
+    }
+    if (_oldInstance) {
+        CFRelease(_oldInstance);
+    }
     
     // Classes are kept around forever.
     _class = other._class;