diff --git a/dom/base/nsContentList.h b/dom/base/nsContentList.h index a399b1a8d9..14ace9cd9e 100644 --- a/dom/base/nsContentList.h +++ b/dom/base/nsContentList.h @@ -260,6 +260,7 @@ public: // nsWrapperCache using nsWrapperCache::GetWrapperPreserveColor; + using nsWrapperCache::PreserveWrapper; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: virtual ~nsContentList(); @@ -268,6 +269,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 3094a98c41..9c81f12483 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3708,17 +3708,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); @@ -3773,7 +3762,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; @@ -3785,8 +3774,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 76e34ab4f3..4ce6ccf87b 100644 --- a/dom/html/HTMLFormControlsCollection.h +++ b/dom/html/HTMLFormControlsCollection.h @@ -78,6 +78,7 @@ public: // nsWrapperCache using nsWrapperCache::GetWrapperPreserveColor; + using nsWrapperCache::PreserveWrapper; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: virtual ~HTMLFormControlsCollection(); @@ -85,6 +86,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 dc13eba9d5..f339efc04f 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() = default; @@ -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 a2a6937432..ceeb815c8c 100644 --- a/dom/html/HTMLTableElement.cpp +++ b/dom/html/HTMLTableElement.cpp @@ -48,6 +48,7 @@ public: // nsWrapperCache using nsWrapperCache::GetWrapperPreserveColor; + using nsWrapperCache::PreserveWrapper; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle aGivenProto) override; protected: virtual ~TableRowsCollection(); @@ -56,6 +57,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 d27f82d1fa..dde2f2b154 100644 --- a/dom/html/nsIHTMLCollection.h +++ b/dom/html/nsIHTMLCollection.h @@ -85,9 +85,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)