From 9f3244d6058a4b85469764a83a25a72011fec646 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 17 May 2017 00:52:53 -0400 Subject: [PATCH] Bug 1189822 part 3. Stop using EnsureExpandoObject in codegen code when we just want to preserver the wrapper for a DOM proxy. r=peterv --- dom/base/nsContentList.h | 5 +++++ dom/bindings/Codegen.py | 16 ++-------------- dom/html/HTMLFormControlsCollection.h | 5 +++++ dom/html/HTMLOptionsCollection.h | 5 +++++ dom/html/HTMLTableElement.cpp | 5 +++++ dom/html/nsIHTMLCollection.h | 7 +++++++ 6 files changed, 29 insertions(+), 14 deletions(-) diff --git a/dom/base/nsContentList.h b/dom/base/nsContentList.h index 3878074b2124..d27561786491 100644 --- a/dom/base/nsContentList.h +++ b/dom/base/nsContentList.h @@ -261,6 +261,7 @@ public: // nsWrapperCache using nsWrapperCache::GetWrapperPreserveColor; + using nsWrapperCache::PreserveWrapper; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: virtual ~nsContentList(); @@ -269,6 +270,10 @@ protected: { return nsWrapperCache::GetWrapperPreserveColor(); } + virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override + { + nsWrapperCache::PreserveWrapper(aScriptObjectHolder); + } public: // nsIDOMHTMLCollection diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 4c96312a26ec..feb260b432c8 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3738,17 +3738,6 @@ class CGWrapWithCacheMethod(CGAbstractMethod): self.properties = properties def definition_body(self): - if self.descriptor.proxy: - preserveWrapper = dedent( - """ - // For DOM proxies, the only reliable way to preserve the wrapper - // is to force creation of the expando object. - JS::Rooted unused(aCx, - DOMProxyHandler::EnsureExpandoObject(aCx, aReflector)); - """) - else: - preserveWrapper = "PreserveWrapper(aObject);\n" - failureCode = dedent( """ aCache->ReleaseWrapper(aObject); @@ -3804,7 +3793,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod): // somewhat common) to have a non-null aGivenProto which is the // same as canonicalProto. if (proto != canonicalProto) { - $*{preserveWrapper} + PreserveWrapper(aObject); } return true; @@ -3816,8 +3805,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod): failureCode), slots=InitMemberSlots(self.descriptor, failureCode), setImmutablePrototype=SetImmutablePrototype(self.descriptor, - failureCode), - preserveWrapper=preserveWrapper) + failureCode)) class CGWrapMethod(CGAbstractMethod): diff --git a/dom/html/HTMLFormControlsCollection.h b/dom/html/HTMLFormControlsCollection.h index 1b8e1e62b3ee..014aa2695ecd 100644 --- a/dom/html/HTMLFormControlsCollection.h +++ b/dom/html/HTMLFormControlsCollection.h @@ -79,6 +79,7 @@ public: // nsWrapperCache using nsWrapperCache::GetWrapperPreserveColor; + using nsWrapperCache::PreserveWrapper; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: virtual ~HTMLFormControlsCollection(); @@ -86,6 +87,10 @@ protected: { return nsWrapperCache::GetWrapperPreserveColor(); } + virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override + { + nsWrapperCache::PreserveWrapper(aScriptObjectHolder); + } public: static bool ShouldBeInElements(nsIFormControl* aFormControl); diff --git a/dom/html/HTMLOptionsCollection.h b/dom/html/HTMLOptionsCollection.h index 7889cfa5b230..00cedb225353 100644 --- a/dom/html/HTMLOptionsCollection.h +++ b/dom/html/HTMLOptionsCollection.h @@ -44,6 +44,7 @@ public: // nsWrapperCache using nsWrapperCache::GetWrapperPreserveColor; using nsWrapperCache::GetWrapper; + using nsWrapperCache::PreserveWrapper; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: virtual ~HTMLOptionsCollection(); @@ -52,6 +53,10 @@ protected: { return nsWrapperCache::GetWrapperPreserveColor(); } + virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override + { + nsWrapperCache::PreserveWrapper(aScriptObjectHolder); + } public: // nsIDOMHTMLOptionsCollection interface diff --git a/dom/html/HTMLTableElement.cpp b/dom/html/HTMLTableElement.cpp index 1c29e850f29b..ebbdf7e24675 100644 --- a/dom/html/HTMLTableElement.cpp +++ b/dom/html/HTMLTableElement.cpp @@ -49,6 +49,7 @@ public: // nsWrapperCache using nsWrapperCache::GetWrapperPreserveColor; + using nsWrapperCache::PreserveWrapper; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: virtual ~TableRowsCollection(); @@ -57,6 +58,10 @@ protected: { return nsWrapperCache::GetWrapperPreserveColor(); } + virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override + { + nsWrapperCache::PreserveWrapper(aScriptObjectHolder); + } // Those rows that are not in table sections HTMLTableElement* mParent; diff --git a/dom/html/nsIHTMLCollection.h b/dom/html/nsIHTMLCollection.h index 7dbfe87665db..51b226cae904 100644 --- a/dom/html/nsIHTMLCollection.h +++ b/dom/html/nsIHTMLCollection.h @@ -86,9 +86,16 @@ public: } return obj; } + void PreserveWrapper(nsISupports* aScriptObjectHolder) + { + PreserveWrapperInternal(aScriptObjectHolder); + } virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) = 0; protected: + // Hook for calling nsWrapperCache::GetWrapperPreserveColor. virtual JSObject* GetWrapperPreserveColorInternal() = 0; + // Hook for calling nsWrapperCache::PreserveWrapper. + virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) = 0; }; NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLCollection, NS_IHTMLCOLLECTION_IID)