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

View file

@ -3708,17 +3708,6 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
self.properties = properties self.properties = properties
def definition_body(self): 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( failureCode = dedent(
""" """
aCache->ReleaseWrapper(aObject); aCache->ReleaseWrapper(aObject);
@ -3773,7 +3762,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
// somewhat common) to have a non-null aGivenProto which is the // somewhat common) to have a non-null aGivenProto which is the
// same as canonicalProto. // same as canonicalProto.
if (proto != canonicalProto) { if (proto != canonicalProto) {
$*{preserveWrapper} PreserveWrapper(aObject);
} }
return true; return true;
@ -3785,8 +3774,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
failureCode), failureCode),
slots=InitMemberSlots(self.descriptor, failureCode), slots=InitMemberSlots(self.descriptor, failureCode),
setImmutablePrototype=SetImmutablePrototype(self.descriptor, setImmutablePrototype=SetImmutablePrototype(self.descriptor,
failureCode), failureCode))
preserveWrapper=preserveWrapper)
class CGWrapMethod(CGAbstractMethod): class CGWrapMethod(CGAbstractMethod):

View file

@ -78,6 +78,7 @@ public:
// nsWrapperCache // nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor; using nsWrapperCache::GetWrapperPreserveColor;
using nsWrapperCache::PreserveWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
protected: protected:
virtual ~HTMLFormControlsCollection(); virtual ~HTMLFormControlsCollection();
@ -85,6 +86,10 @@ protected:
{ {
return nsWrapperCache::GetWrapperPreserveColor(); return nsWrapperCache::GetWrapperPreserveColor();
} }
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override
{
nsWrapperCache::PreserveWrapper(aScriptObjectHolder);
}
public: public:
static bool ShouldBeInElements(nsIFormControl* aFormControl); static bool ShouldBeInElements(nsIFormControl* aFormControl);

View file

@ -44,6 +44,7 @@ public:
// nsWrapperCache // nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor; using nsWrapperCache::GetWrapperPreserveColor;
using nsWrapperCache::GetWrapper; using nsWrapperCache::GetWrapper;
using nsWrapperCache::PreserveWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
protected: protected:
virtual ~HTMLOptionsCollection() = default; virtual ~HTMLOptionsCollection() = default;
@ -52,6 +53,10 @@ protected:
{ {
return nsWrapperCache::GetWrapperPreserveColor(); return nsWrapperCache::GetWrapperPreserveColor();
} }
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override
{
nsWrapperCache::PreserveWrapper(aScriptObjectHolder);
}
public: public:
// nsIDOMHTMLOptionsCollection interface // nsIDOMHTMLOptionsCollection interface

View file

@ -48,6 +48,7 @@ public:
// nsWrapperCache // nsWrapperCache
using nsWrapperCache::GetWrapperPreserveColor; using nsWrapperCache::GetWrapperPreserveColor;
using nsWrapperCache::PreserveWrapper;
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
protected: protected:
virtual ~TableRowsCollection(); virtual ~TableRowsCollection();
@ -56,6 +57,10 @@ protected:
{ {
return nsWrapperCache::GetWrapperPreserveColor(); return nsWrapperCache::GetWrapperPreserveColor();
} }
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override
{
nsWrapperCache::PreserveWrapper(aScriptObjectHolder);
}
// Those rows that are not in table sections // Those rows that are not in table sections
HTMLTableElement* mParent; HTMLTableElement* mParent;

View file

@ -85,9 +85,16 @@ public:
} }
return obj; return obj;
} }
void PreserveWrapper(nsISupports* aScriptObjectHolder)
{
PreserveWrapperInternal(aScriptObjectHolder);
}
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) = 0; virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) = 0;
protected: protected:
// Hook for calling nsWrapperCache::GetWrapperPreserveColor.
virtual JSObject* GetWrapperPreserveColorInternal() = 0; virtual JSObject* GetWrapperPreserveColorInternal() = 0;
// Hook for calling nsWrapperCache::PreserveWrapper.
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) = 0;
}; };
NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLCollection, NS_IHTMLCOLLECTION_IID) NS_DEFINE_STATIC_IID_ACCESSOR(nsIHTMLCollection, NS_IHTMLCOLLECTION_IID)