Title: [141490] trunk/Source/_javascript_Core
Revision
141490
Author
[email protected]
Date
2013-01-31 14:33:55 -0800 (Thu, 31 Jan 2013)

Log Message

Objective-C API: JSContext exception property causes reference cycle
https://bugs.webkit.org/show_bug.cgi?id=107778

Reviewed by Darin Adler.

JSContext has a (retain) JSValue * exception property which, when non-null, creates a 
reference cycle (since the JSValue * holds a strong reference back to the JSContext *).

* API/JSContext.mm: Instead of JSValue *, we now use a plain JSValueRef, which eliminates the reference cycle.
(-[JSContext initWithVirtualMachine:]):
(-[JSContext setException:]):
(-[JSContext exception]):

Modified Paths

Diff

Modified: trunk/Source/_javascript_Core/API/JSContext.mm (141489 => 141490)


--- trunk/Source/_javascript_Core/API/JSContext.mm	2013-01-31 22:31:45 UTC (rev 141489)
+++ trunk/Source/_javascript_Core/API/JSContext.mm	2013-01-31 22:33:55 UTC (rev 141490)
@@ -34,6 +34,7 @@
 #import "_javascript_Core.h"
 #import "ObjcRuntimeExtras.h"
 #import "Operations.h"
+#import "StrongInlines.h"
 #import <wtf/HashSet.h>
 
 #if JS_OBJC_API_ENABLED
@@ -42,9 +43,9 @@
     JSVirtualMachine *m_virtualMachine;
     JSGlobalContextRef m_context;
     JSWrapperMap *m_wrapperMap;
+    JSC::Strong<JSC::JSObject> m_exception;
 }
 
-@synthesize exception;
 @synthesize exceptionHandler;
 
 - (id)init
@@ -62,7 +63,6 @@
     m_context = JSGlobalContextCreateInGroup(getGroupFromVirtualMachine(virtualMachine), 0);
     m_wrapperMap = [[JSWrapperMap alloc] initWithContext:self];
 
-    self.exception = nil;
     self.exceptionHandler = ^(JSContext *context, JSValue *exceptionValue) {
         context.exception = exceptionValue;
     };
@@ -84,6 +84,21 @@
     return [JSValue valueWithValue:result inContext:self];
 }
 
+- (void)setException:(JSValue *)value
+{
+    if (value)
+        m_exception.set(toJS(m_context)->globalData(), toJS(JSValueToObject(m_context, valueInternalValue(value), 0)));
+    else
+        m_exception.clear();
+}
+
+- (JSValue *)exception
+{
+    if (!m_exception)
+        return nil;
+    return [JSValue valueWithValue:toRef(m_exception.get()) inContext:self];
+}
+
 - (JSWrapperMap *)wrapperMap
 {
     return m_wrapperMap;

Modified: trunk/Source/_javascript_Core/ChangeLog (141489 => 141490)


--- trunk/Source/_javascript_Core/ChangeLog	2013-01-31 22:31:45 UTC (rev 141489)
+++ trunk/Source/_javascript_Core/ChangeLog	2013-01-31 22:33:55 UTC (rev 141490)
@@ -1,3 +1,18 @@
+2013-01-31  Mark Hahnenberg  <[email protected]>
+
+        Objective-C API: JSContext exception property causes reference cycle
+        https://bugs.webkit.org/show_bug.cgi?id=107778
+
+        Reviewed by Darin Adler.
+
+        JSContext has a (retain) JSValue * exception property which, when non-null, creates a 
+        reference cycle (since the JSValue * holds a strong reference back to the JSContext *).
+
+        * API/JSContext.mm: Instead of JSValue *, we now use a plain JSValueRef, which eliminates the reference cycle.
+        (-[JSContext initWithVirtualMachine:]):
+        (-[JSContext setException:]):
+        (-[JSContext exception]):
+
 2013-01-31  Roger Fong  <[email protected]>
 
         Unreviewed build fix. Win7 port.
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to