mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1440949 - Allow plain JS objects to request addon interposition;r=kmag
This is needed to allow interposition for gBrowser, which will change from a DOM node into a plain JS object in Bug 1392352. An object can set the `requiresAddonInterpositions` property to enable this feature. MozReview-Commit-ID: 4Uw5xzgZtXO --HG-- extra : rebase_source : 203fe656da3ecd514d4e27ad0eeb4885cf4e9b0b
This commit is contained in:
parent
0c3ddfb661
commit
e13938f94f
@ -38,20 +38,36 @@ ReportASCIIErrorWithId(JSContext* cx, const char* msg, HandleId id)
|
||||
JS_ReportErrorUTF8(cx, msg, bytes.ptr());
|
||||
}
|
||||
|
||||
bool
|
||||
RequiresInterpositions(JSContext* cx, HandleObject unwrapped)
|
||||
{
|
||||
Rooted<PropertyDescriptor> desc(cx);
|
||||
JSAutoCompartment ac(cx, unwrapped);
|
||||
|
||||
if (!JS_GetOwnPropertyDescriptor(cx, unwrapped, "requiresAddonInterpositions", &desc)) {
|
||||
JS_ClearPendingException(cx);
|
||||
return false;
|
||||
}
|
||||
|
||||
return desc.hasValue() && desc.value().isTrue();
|
||||
}
|
||||
|
||||
bool
|
||||
InterposeProperty(JSContext* cx, HandleObject target, const nsIID* iid, HandleId id,
|
||||
MutableHandle<PropertyDescriptor> descriptor)
|
||||
{
|
||||
// We only want to do interpostion on DOM instances and
|
||||
// wrapped natives.
|
||||
// We only want to do interpostion on DOM instances,
|
||||
// wrapped natives, or if the object explicitly requests it.
|
||||
RootedObject unwrapped(cx, UncheckedUnwrap(target));
|
||||
const js::Class* clasp = js::GetObjectClass(unwrapped);
|
||||
bool isCPOW = jsipc::IsWrappedCPOW(unwrapped);
|
||||
|
||||
if (!mozilla::dom::IsDOMClass(clasp) &&
|
||||
!IS_WN_CLASS(clasp) &&
|
||||
!IS_PROTO_CLASS(clasp) &&
|
||||
clasp != &OuterWindowProxyClass &&
|
||||
!isCPOW) {
|
||||
!isCPOW &&
|
||||
!RequiresInterpositions(cx, unwrapped)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user