Bug 1088228 part 6. Simplify the DOM GetParentObject setup, now that we no longer rely on it for scope chains. r=peterv

This commit is contained in:
Boris Zbarsky 2014-10-30 17:43:42 -04:00
parent 7a654f6bd1
commit 937b0d8c48
8 changed files with 21 additions and 78 deletions

View File

@ -2877,7 +2877,11 @@ nsINode::OwnerDocAsNode() const
inline mozilla::dom::ParentObject
nsINode::GetParentObject() const
{
return GetParentObjectInternal(OwnerDoc());
mozilla::dom::ParentObject p(OwnerDoc());
// Note that mUseXBLScope is a no-op for chrome, and other places where we
// don't use XBL scopes.
p.mUseXBLScope = IsInAnonymousSubtree() && !IsAnonymousContentInSVGUseSubtree();
return p;
}
#endif /* nsIDocument_h___ */

View File

@ -382,17 +382,6 @@ protected:
*/
virtual JSObject* WrapNode(JSContext *aCx) = 0;
// Subclasses that wish to override the parent behavior should return the
// result of GetParentObjectIntenral, which handles the XBL scope stuff.
//
mozilla::dom::ParentObject GetParentObjectInternal(nsINode* aNativeParent) const {
mozilla::dom::ParentObject p(aNativeParent);
// Note that mUseXBLScope is a no-op for chrome, and other places where we
// don't use XBL scopes.
p.mUseXBLScope = IsInAnonymousSubtree() && !IsAnonymousContentInSVGUseSubtree();
return p;
}
public:
mozilla::dom::ParentObject GetParentObject() const; // Implemented in nsIDocument.h

View File

@ -1504,22 +1504,6 @@ WrapNativeParent(JSContext* cx, const T& p)
return WrapNativeParent(cx, GetParentPointer(p), GetWrapperCache(p), GetUseXBLScope(p));
}
// A way to differentiate between nodes, which use the parent object
// returned by native->GetParentObject(), and all other objects, which
// just use the parent's global.
static inline JSObject*
GetRealParentObject(void* aParent, JSObject* aParentObject)
{
return aParentObject ?
js::GetGlobalForObjectCrossCompartment(aParentObject) : nullptr;
}
static inline JSObject*
GetRealParentObject(Element* aParent, JSObject* aParentObject)
{
return aParentObject;
}
HAS_MEMBER(GetParentObject)
template<typename T, bool WrapperCached=HasGetParentObjectMember<T>::Value>
@ -1529,9 +1513,8 @@ struct GetParentObject
{
MOZ_ASSERT(js::IsObjectInContextCompartment(obj, cx));
T* native = UnwrapDOMObject<T>(obj);
return
GetRealParentObject(native,
WrapNativeParent(cx, native->GetParentObject()));
JSObject* wrappedParent = WrapNativeParent(cx, native->GetParentObject());
return wrappedParent ? js::GetGlobalForObjectCrossCompartment(wrappedParent) : nullptr;
}
};

View File

@ -3069,24 +3069,23 @@ class CGConstructorEnabled(CGAbstractMethod):
return body.define()
def CreateBindingJSObject(descriptor, properties, parent):
def CreateBindingJSObject(descriptor, properties):
# We don't always need to root obj, but there are a variety
# of cases where we do, so for simplicity, just always root it.
objDecl = "JS::Rooted<JSObject*> obj(aCx);\n"
if descriptor.proxy:
create = fill(
create = dedent(
"""
JS::Rooted<JS::Value> proxyPrivateVal(aCx, JS::PrivateValue(aObject));
js::ProxyOptions options;
options.setClass(&Class.mBase);
obj = NewProxyObject(aCx, DOMProxyHandler::getInstance(),
proxyPrivateVal, proto, ${parent}, options);
proxyPrivateVal, proto, global, options);
if (!obj) {
return nullptr;
}
""",
parent=parent)
""")
if descriptor.interface.getExtendedAttribute('OverrideBuiltins'):
create += dedent("""
js::SetProxyExtra(obj, JSPROXYSLOT_EXPANDO,
@ -3094,16 +3093,15 @@ def CreateBindingJSObject(descriptor, properties, parent):
""")
else:
create = fill(
create = dedent(
"""
obj = JS_NewObject(aCx, Class.ToJSClass(), proto, ${parent});
obj = JS_NewObject(aCx, Class.ToJSClass(), proto, global);
if (!obj) {
return nullptr;
}
js::SetReservedSlot(obj, DOM_OBJECT_SLOT, PRIVATE_TO_JSVAL(aObject));
""",
parent=parent)
""")
create = objDecl + create
if descriptor.nativeOwnership == 'refcounted':
@ -3254,9 +3252,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
"nsISupports must be on our primary inheritance chain");
JS::Rooted<JSObject*> parent(aCx,
GetRealParentObject(aObject,
WrapNativeParent(aCx, aObject->GetParentObject())));
JS::Rooted<JSObject*> parent(aCx, WrapNativeParent(aCx, aObject->GetParentObject()));
if (!parent) {
return nullptr;
}
@ -3272,13 +3268,13 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
}
JSAutoCompartment ac(aCx, parent);
JS::Rooted<JSObject*> global(aCx, JS_GetGlobalForObject(aCx, parent));
JS::Rooted<JSObject*> global(aCx, js::GetGlobalForObjectCrossCompartment(parent));
JS::Handle<JSObject*> proto = GetProtoObjectHandle(aCx, global);
if (!proto) {
return nullptr;
}
$*{parent}
$*{createObject}
$*{unforgeable}
@ -3287,8 +3283,7 @@ class CGWrapWithCacheMethod(CGAbstractMethod):
return obj;
""",
assertion=AssertInheritanceChain(self.descriptor),
parent=CreateBindingJSObject(self.descriptor, self.properties,
"parent"),
createObject=CreateBindingJSObject(self.descriptor, self.properties),
unforgeable=InitUnforgeableProperties(self.descriptor, self.properties),
slots=InitMemberSlots(self.descriptor, True))
@ -3334,7 +3329,7 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
return nullptr;
}
$*{global_}
$*{createObject}
$*{unforgeable}
@ -3342,8 +3337,7 @@ class CGWrapNonWrapperCacheMethod(CGAbstractMethod):
return obj;
""",
assertions=AssertInheritanceChain(self.descriptor),
global_=CreateBindingJSObject(self.descriptor, self.properties,
"global"),
createObject=CreateBindingJSObject(self.descriptor, self.properties),
unforgeable=InitUnforgeableProperties(self.descriptor, self.properties),
slots=InitMemberSlots(self.descriptor, False))

View File

@ -77,12 +77,6 @@ public:
SetHTMLAttr(nsGkAtoms::align, aAlign, aError);
}
ParentObject GetParentObject() {
Element* form = GetFormElement();
return form ? GetParentObjectInternal(form)
: nsGenericHTMLElement::GetParentObject();
}
nsINode* GetScopeChainParent() const MOZ_OVERRIDE
{
Element* form = GetFormElement();

View File

@ -1896,16 +1896,6 @@ NS_IMPL_ISUPPORTS_INHERITED(nsGenericHTMLFormElement,
nsGenericHTMLElement,
nsIFormControl)
mozilla::dom::ParentObject
nsGenericHTMLFormElement::GetParentObject() const
{
// We use the parent chain to implement the scope for event handlers.
if (mForm) {
return GetParentObjectInternal(mForm);
}
return nsGenericHTMLElement::GetParentObject();
}
nsINode*
nsGenericHTMLFormElement::GetScopeChainParent() const
{

View File

@ -1245,8 +1245,6 @@ public:
NS_DECL_ISUPPORTS_INHERITED
mozilla::dom::ParentObject GetParentObject() const;
nsINode* GetScopeChainParent() const MOZ_OVERRIDE;
virtual bool IsNodeOfType(uint32_t aFlags) const MOZ_OVERRIDE;

View File

@ -606,18 +606,9 @@ public:
already_AddRefed<nsFrameLoader> GetFrameLoader();
void SwapFrameLoaders(nsXULElement& aOtherOwner, mozilla::ErrorResult& rv);
// For XUL, the parent is the parent element, if any
mozilla::dom::ParentObject GetParentObject() const
{
Element* parent = GetParentElement();
if (parent) {
return GetParentObjectInternal(parent);
}
return nsStyledElement::GetParentObject();
}
nsINode* GetScopeChainParent() const MOZ_OVERRIDE
{
// For XUL, the parent is the parent element, if any
Element* parent = GetParentElement();
return parent ? parent : nsStyledElement::GetScopeChainParent();
}