Title: [141199] trunk/Source/_javascript_Core
Revision
141199
Author
[email protected]
Date
2013-01-29 18:17:59 -0800 (Tue, 29 Jan 2013)

Log Message

Objective-C API: JSObjCClassInfo creates reference cycle with JSContext
https://bugs.webkit.org/show_bug.cgi?id=107839

Reviewed by Geoffrey Garen.

Fixing several ASSERTs that were incorrect along with some of the reallocation of m_prototype and
m_constructor that they were based on.

* API/JSWrapperMap.mm:
(-[JSObjCClassInfo allocateConstructorAndPrototypeWithSuperClassInfo:]): We now only allocate those
fields that are null (i.e. have been collected or have never been allocated to begin with).
(-[JSObjCClassInfo reallocateConstructorAndOrPrototype]): Renamed to better indicate that we're
reallocating one or both of the prototype/constructor combo.
(-[JSObjCClassInfo wrapperForObject:]): Call new reallocate function.
(-[JSObjCClassInfo constructor]): Ditto.

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSWrapperMap.mm (141198 => 141199)


--- trunk/Source/_javascript_Core/API/JSWrapperMap.mm	2013-01-30 02:17:15 UTC (rev 141198)
+++ trunk/Source/_javascript_Core/API/JSWrapperMap.mm	2013-01-30 02:17:59 UTC (rev 141199)
@@ -340,21 +340,34 @@
 
 - (void)allocateConstructorAndPrototypeWithSuperClassInfo:(JSObjCClassInfo*)superClassInfo
 {
+    ASSERT(!m_constructor || !m_prototype);
     ASSERT((m_class == [NSObject class]) == !superClassInfo);
     if (!superClassInfo) {
         JSContextRef cContext = contextInternalContext(m_context);
         JSValue *constructor = m_context[@"Object"];
-        m_constructor = toJS(JSValueToObject(cContext, valueInternalValue(constructor), 0));
+        if (!m_constructor)
+            m_constructor = toJS(JSValueToObject(cContext, valueInternalValue(constructor), 0));
 
-        JSValue *prototype = constructor[@"prototype"];
-        m_prototype = toJS(JSValueToObject(cContext, valueInternalValue(prototype), 0));
+        if (!m_prototype) {
+            JSValue *prototype = constructor[@"prototype"];
+            m_prototype = toJS(JSValueToObject(cContext, valueInternalValue(prototype), 0));
+        }
     } else {
         const char* className = class_getName(m_class);
 
-        // Create the prototype/constructor pair.
-        JSValue *prototype = createObjectWithCustomBrand(m_context, [NSString stringWithFormat:@"%sPrototype", className]);
-        JSValue *constructor = createObjectWithCustomBrand(m_context, [NSString stringWithFormat:@"%sConstructor", className], wrapperClass(), [m_class retain]);
+        // Create or grab the prototype/constructor pair.
+        JSValue *prototype;
+        JSValue *constructor;
+        if (m_prototype)
+            prototype = [JSValue valueWithValue:toRef(m_prototype.get()) inContext:m_context];
+        else
+            prototype = createObjectWithCustomBrand(m_context, [NSString stringWithFormat:@"%sPrototype", className]);
 
+        if (m_constructor)
+            constructor = [JSValue valueWithValue:toRef(m_constructor.get()) inContext:m_context];
+        else
+            constructor = createObjectWithCustomBrand(m_context, [NSString stringWithFormat:@"%sConstructor", className], wrapperClass(), [m_class retain]);
+
         JSContextRef cContext = contextInternalContext(m_context);
         m_prototype = toJS(JSValueToObject(cContext, valueInternalValue(prototype), 0));
         m_constructor = toJS(JSValueToObject(cContext, valueInternalValue(constructor), 0));
@@ -376,10 +389,8 @@
     }
 }
 
-- (void)allocateConstructorAndPrototype
+- (void)reallocateConstructorAndOrPrototype
 {
-    ASSERT(!m_constructor.get());
-    ASSERT(!m_prototype.get());
     [self allocateConstructorAndPrototypeWithSuperClassInfo:[m_context.wrapperMap classInfoForClass:class_getSuperclass(m_class)]];
 }
 
@@ -392,27 +403,21 @@
             return [JSValue valueWithValue:method inContext:m_context];
     }
 
-    JSC::JSObject* prototype = m_prototype.get();
-    if (!prototype) {
-        [self allocateConstructorAndPrototype];
-        prototype = m_prototype.get();
-        ASSERT(prototype);
-    }
+    if (!m_prototype)
+        [self reallocateConstructorAndOrPrototype];
+    ASSERT(!!m_prototype);
 
     JSObjectRef wrapper = JSObjectMake(contextInternalContext(m_context), m_classRef, [object retain]);
-    JSObjectSetPrototype(contextInternalContext(m_context), wrapper, toRef(prototype));
+    JSObjectSetPrototype(contextInternalContext(m_context), wrapper, toRef(m_prototype.get()));
     return [JSValue valueWithValue:wrapper inContext:m_context];
 }
 
 - (JSValue *)constructor
 {
-    JSC::JSObject* constructor = m_constructor.get();
-    if (!constructor) {
-        [self allocateConstructorAndPrototype];
-        constructor = m_constructor.get();
-        ASSERT(constructor);
-    }
-    return [JSValue valueWithValue:toRef(constructor) inContext:m_context];
+    if (!m_constructor)
+        [self reallocateConstructorAndOrPrototype];
+    ASSERT(!!m_constructor);
+    return [JSValue valueWithValue:toRef(m_constructor.get()) inContext:m_context];
 }
 
 @end

Modified: trunk/Source/_javascript_Core/ChangeLog (141198 => 141199)


--- trunk/Source/_javascript_Core/ChangeLog	2013-01-30 02:17:15 UTC (rev 141198)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-01-30 02:17:59 UTC (rev 141199)
@@ -1,3 +1,21 @@
+2013-01-29  Mark Hahnenberg  <[email protected]>
+
+        Objective-C API: JSObjCClassInfo creates reference cycle with JSContext
+        https://bugs.webkit.org/show_bug.cgi?id=107839
+
+        Reviewed by Geoffrey Garen.
+
+        Fixing several ASSERTs that were incorrect along with some of the reallocation of m_prototype and 
+        m_constructor that they were based on.
+
+        * API/JSWrapperMap.mm:
+        (-[JSObjCClassInfo allocateConstructorAndPrototypeWithSuperClassInfo:]): We now only allocate those
+        fields that are null (i.e. have been collected or have never been allocated to begin with).
+        (-[JSObjCClassInfo reallocateConstructorAndOrPrototype]): Renamed to better indicate that we're 
+        reallocating one or both of the prototype/constructor combo.
+        (-[JSObjCClassInfo wrapperForObject:]): Call new reallocate function.
+        (-[JSObjCClassInfo constructor]): Ditto.
+
 2013-01-29  Geoffrey Garen  <[email protected]>
 
         Make precise size classes more precise
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to