Issue #2678 - Stop using EnsureExpandoObject in codegen code when we just want to preserver the wrapper for a DOM proxy.

This commit is contained in:
Moonchild 2025-01-16 22:54:23 +01:00 committed by roytam1
commit c9c941f321
6 changed files with 29 additions and 14 deletions

View file

@ -260,6 +260,7 @@ public:
// nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor;
using nsWrapperCache::PreserveWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
protected:
virtual ~nsContentList();
@ -268,6 +269,10 @@ protected:
{
return nsWrapperCache::GetWrapperPreserveColor();
}
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override
{
nsWrapperCache::PreserveWrapper(aScriptObjectHolder);
}
public:
// nsIDOMHTMLCollection

View file

@ -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<JSObject*> 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):

View file

@ -78,6 +78,7 @@ public:
// nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor;
using nsWrapperCache::PreserveWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> 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);

View file

@ -44,6 +44,7 @@ public:
// nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor;
using nsWrapperCache::GetWrapper;
using nsWrapperCache::PreserveWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> 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

View file

@ -48,6 +48,7 @@ public:
// nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor;
using nsWrapperCache::PreserveWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> 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;

View file

@ -85,9 +85,16 @@ public:
}
return obj;
}
void PreserveWrapper(nsISupports* aScriptObjectHolder)
{
PreserveWrapperInternal(aScriptObjectHolder);
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> 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)