Bug 107839 - Objective-C API: JSObjCClassInfo creates reference cycle with JSContext
Summary: Objective-C API: JSObjCClassInfo creates reference cycle with JSContext
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Hahnenberg
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2013-01-24 09:27 PST by Mark Hahnenberg
Modified: 2013-01-29 18:20 PST (History)
4 users (show)

See Also:


Attachments
Patch (8.50 KB, patch)
2013-01-29 15:02 PST, Mark Hahnenberg
no flags Details | Formatted Diff | Diff
Patch (5.33 KB, patch)
2013-01-29 16:34 PST, Mark Hahnenberg
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Hahnenberg 2013-01-24 09:27:40 PST
JSContext has a JSWrapperMap, which has an NSMutableDictionary m_classMap, which has values that are JSObjCClassInfo objects, which have strong references to two JSValue *'s, m_prototype and m_constructor, which in turn have strong references to the JSContext, creating a reference cycle. We should make m_prototype and m_constructor Weak<JSObject>. This gets rid of the strong reference to the JSContext and also prevents clients from accidentally creating reference cycles by assigning to the prototype of the constructor. If Weak<JSObject> fields are ever garbage collected, we will reallocate them.
Comment 1 Radar WebKit Bug Importer 2013-01-24 11:47:51 PST
<rdar://problem/13079710>
Comment 2 Mark Hahnenberg 2013-01-29 15:02:30 PST
Created attachment 185314 [details]
Patch
Comment 3 WebKit Review Bot 2013-01-29 15:05:07 PST
Attachment 185314 [details] did not pass style-queue:

Failed to run "['Tools/Scripts/check-webkit-style', '--diff-files', u'Source/JavaScriptCore/API/JSContext.mm', u'Source/JavaScriptCore/API/JSContextInternal.h', u'Source/JavaScriptCore/API/JSWrapperMap.mm', u'Source/JavaScriptCore/ChangeLog']" exit_code: 1
Source/JavaScriptCore/API/JSContextInternal.h:70:  Extra space before ( in function call  [whitespace/parens] [4]
Total errors found: 1 in 4 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 4 Geoffrey Garen 2013-01-29 15:52:46 PST
Comment on attachment 185314 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=185314&action=review

> Source/JavaScriptCore/API/JSWrapperMap.mm:382
> +    ASSERT(!m_constructor.get());
> +    ASSERT(!m_prototype.get());

Since the prototype's .constructor property is user-modifiable, it's possible for m_prototype to be NULL when m_constructor is not.
Comment 5 Mark Hahnenberg 2013-01-29 16:03:56 PST
> Since the prototype's .constructor property is user-modifiable, it's possible for m_prototype to be NULL when m_constructor is not.

With the way it's written here, isn't that also true of the constructor's .prototype property?

I guess the fix is to do the check for each and only re-generate the one(s) that have been collected.
Comment 6 WebKit Review Bot 2013-01-29 16:09:09 PST
Comment on attachment 185314 [details]
Patch

Clearing flags on attachment: 185314

Committed r141176: <http://trac.webkit.org/changeset/141176>
Comment 7 WebKit Review Bot 2013-01-29 16:09:13 PST
All reviewed patches have been landed.  Closing bug.
Comment 8 Geoffrey Garen 2013-01-29 16:24:55 PST
> With the way it's written here, isn't that also true of the constructor's .prototype property?

Yes, I think so.

> I guess the fix is to do the check for each and only re-generate the one(s) that have been collected.

Sounds right.
Comment 9 Mark Hahnenberg 2013-01-29 16:29:43 PST
I'm reopening since those ASSERTs are wrong, along with some of the reallocation logic they're based on.
Comment 10 Mark Hahnenberg 2013-01-29 16:34:15 PST
Created attachment 185338 [details]
Patch
Comment 11 Geoffrey Garen 2013-01-29 17:05:34 PST
Comment on attachment 185338 [details]
Patch

r=me
Comment 12 WebKit Review Bot 2013-01-29 18:20:34 PST
Comment on attachment 185338 [details]
Patch

Clearing flags on attachment: 185338

Committed r141199: <http://trac.webkit.org/changeset/141199>
Comment 13 WebKit Review Bot 2013-01-29 18:20:38 PST
All reviewed patches have been landed.  Closing bug.