Closed Bug 909953 Opened 11 years ago Closed 11 years ago

Introduce a HTMLAllCollection class

Categories

(Core :: DOM: Core & HTML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla26

People

(Reporter: Ms2ger, Assigned: Ms2ger)

References

Details

Attachments

(1 file, 1 obsolete file)

Attached patch Patch v1 (obsolete) — Splinter Review
I want to move more stuff into it, but that's for another bug.
Attachment #796293 - Flags: review?(bugs)
Blocks: 874212
Comment on attachment 796293 [details] [diff] [review]
Patch v1

>From: Ms2ger <ms2ger@gmail.com>
>
>diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h
>--- a/content/base/public/nsINode.h
>+++ b/content/base/public/nsINode.h
>@@ -1743,16 +1743,28 @@ inline nsINode* NODE_FROM(C& aContent, D
> {
>   if (aContent)
>     return static_cast<nsINode*>(aContent);
>   return static_cast<nsINode*>(aDocument);
> }
> 
> NS_DEFINE_STATIC_IID_ACCESSOR(nsINode, NS_INODE_IID)
> 
>+inline nsISupports*
>+ToSupports(nsINode* aPointer)
>+{
>+  return aPointer;
>+}
>+
>+inline nsISupports*
>+ToCanonicalSupports(nsINode* aPointer)
>+{
>+  return aPointer;
>+}
Not sure how this is related, but ok change anyway.


>+HTMLAllCollection::GetObject(JSContext* aCx, JS::Handle<JSObject*> aObject,
>+                             ErrorResult& aRv)
>+{
>+  MOZ_ASSERT(aCx);
>+  MOZ_ASSERT(aObject);
>+
>+  if (!mObject) {
>+    JSAutoCompartment ac(aCx, aObject);
>+    mObject = JS_NewObject(aCx, &sHTMLDocumentAllClass, nullptr,
>+                           JS_GetGlobalForObject(aCx, aObject));
>+    if (!mObject) {
>+      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
>+      return nullptr;
>+    }
>+
>+    // Make the JSObject hold a reference to the document.
>+    JS_SetPrivate(mObject, ToSupports(mDocument));
>+    NS_ADDREF(mDocument);
>+
>+    mDocument->PreserveWrapper(ToSupports(mDocument));
I sure hope we have wrapper here. We should have, as far as I see.


>+  }
>+
>+  return mObject;
Could you call xpc_UnmarkGrayObject here before returning.
I know it is missing from the current code.

> NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
>-  tmp->mAll = nullptr;
>+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mAll)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mImages)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mApplets)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mEmbeds)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mLinks)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnchors)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mScripts)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mForms)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mFormControls)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mWyciwygChannel)
>   NS_IMPL_CYCLE_COLLECTION_UNLINK(mMidasCommandManager)
> NS_IMPL_CYCLE_COLLECTION_UNLINK_END
Couldn't you now use some macro to traverse/unlink all these?
Attachment #796293 - Flags: review?(bugs) → review+
I think the JS pointer in there makes it hard to use a macro.
(In reply to Olli Pettay [:smaug] from comment #1)
> Comment on attachment 796293 [details] [diff] [review]
> Patch v1
> 
> >From: Ms2ger <ms2ger@gmail.com>
> >
> >diff --git a/content/base/public/nsINode.h b/content/base/public/nsINode.h
> >--- a/content/base/public/nsINode.h
> >+++ b/content/base/public/nsINode.h
> >@@ -1743,16 +1743,28 @@ inline nsINode* NODE_FROM(C& aContent, D
> > {
> >   if (aContent)
> >     return static_cast<nsINode*>(aContent);
> >   return static_cast<nsINode*>(aDocument);
> > }
> > 
> > NS_DEFINE_STATIC_IID_ACCESSOR(nsINode, NS_INODE_IID)
> > 
> >+inline nsISupports*
> >+ToSupports(nsINode* aPointer)
> >+{
> >+  return aPointer;
> >+}
> >+
> >+inline nsISupports*
> >+ToCanonicalSupports(nsINode* aPointer)
> >+{
> >+  return aPointer;
> >+}
> Not sure how this is related, but ok change anyway.

I wanted to call ToSupports from HTMLAllCollection::GetObject, but I also didn't want to include nsDOMQS.h :)

> 
> >+HTMLAllCollection::GetObject(JSContext* aCx, JS::Handle<JSObject*> aObject,
> >+                             ErrorResult& aRv)
> >+{
> >+  MOZ_ASSERT(aCx);
> >+  MOZ_ASSERT(aObject);
> >+
> >+  if (!mObject) {
> >+    JSAutoCompartment ac(aCx, aObject);
> >+    mObject = JS_NewObject(aCx, &sHTMLDocumentAllClass, nullptr,
> >+                           JS_GetGlobalForObject(aCx, aObject));
> >+    if (!mObject) {
> >+      aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
> >+      return nullptr;
> >+    }
> >+
> >+    // Make the JSObject hold a reference to the document.
> >+    JS_SetPrivate(mObject, ToSupports(mDocument));
> >+    NS_ADDREF(mDocument);
> >+
> >+    mDocument->PreserveWrapper(ToSupports(mDocument));
> I sure hope we have wrapper here. We should have, as far as I see.

So assert mDocument->PreservingWrapper()?

> >+  }
> >+
> >+  return mObject;
> Could you call xpc_UnmarkGrayObject here before returning.
> I know it is missing from the current code.

Will do.

> > NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(nsHTMLDocument, nsDocument)
> >-  tmp->mAll = nullptr;
> >+  NS_IMPL_CYCLE_COLLECTION_UNLINK(mAll)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mImages)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mApplets)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mEmbeds)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mLinks)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mAnchors)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mScripts)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mForms)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mFormControls)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mWyciwygChannel)
> >   NS_IMPL_CYCLE_COLLECTION_UNLINK(mMidasCommandManager)
> > NS_IMPL_CYCLE_COLLECTION_UNLINK_END
> Couldn't you now use some macro to traverse/unlink all these?

That would lose

NS_ASSERTION(!nsCCUncollectableMarker::InGeneration(cb, tmp->GetMarkedCCGeneration()),
             "Shouldn't traverse nsHTMLDocument!");

Is that ok?
Attached patch Patch v2Splinter Review
We discussed this on IRC: http://logbot.glob.com.au/?c=mozilla%23content#c122511
Attachment #796293 - Attachment is obsolete: true
Attachment #796837 - Flags: review+
https://hg.mozilla.org/mozilla-central/rev/4a89871f5c4b
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Flags: in-testsuite-
Resolution: --- → FIXED
Target Milestone: --- → mozilla26
Component: DOM → DOM: Core & HTML
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: