diff --git a/dom/base/nsContentList.h b/dom/base/nsContentList.h index 83d27da95..68238cacf 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 ab6f7d774..6589b950e 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -3712,17 +3712,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); @@ -3778,7 +3767,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; @@ -3790,8 +3779,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 1b8e1e62b..014aa2695 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 1dc7df150..32642a52e 100644 --- a/dom/html/HTMLOptionsCollection.h +++ b/dom/html/HTMLOptionsCollection.h @@ -45,6 +45,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; @@ -53,6 +54,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 4ac1515c0..81d8e51ef 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 7dbfe8766..51b226cae 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)