From 4f5d92624b44cb705d1ee361143416f83fb951cc Mon Sep 17 00:00:00 2001 From: Peter Van der Beken Date: Tue, 16 Feb 2016 19:30:49 +0100 Subject: [PATCH] Bug 1248478 - Remove some obsolete code in XrayWrapper.cpp. r=bholley. --- js/xpconnect/wrappers/XrayWrapper.cpp | 100 +------------------------- js/xpconnect/wrappers/XrayWrapper.h | 10 +-- 2 files changed, 6 insertions(+), 104 deletions(-) diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 4ab4192af12..7be477ead5b 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -8,8 +8,6 @@ #include "AccessCheck.h" #include "WrapperFactory.h" -#include "nsContentUtils.h" -#include "nsIControllers.h" #include "nsDependentString.h" #include "nsIScriptError.h" #include "mozilla/dom/Element.h" @@ -1256,17 +1254,10 @@ IsXPCWNHolderClass(const JSClass* clasp) static nsGlobalWindow* AsWindow(JSContext* cx, JSObject* wrapper) { - nsGlobalWindow* win; // We want to use our target object here, since we don't want to be // doing a security check while unwrapping. JSObject* target = XrayTraits::getTargetObject(wrapper); - nsresult rv = UNWRAP_OBJECT(Window, target, win); - if (NS_SUCCEEDED(rv)) - return win; - - nsCOMPtr piWin = do_QueryInterface( - nsContentUtils::XPConnect()->GetNativeOfWrapper(cx, target)); - return nsGlobalWindow::Cast(piWin); + return WindowOrNull(target); } static bool @@ -1306,53 +1297,6 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext* cx, HandleObject wr if (!JSID_IS_STRING(id)) return true; - // The |controllers| property is accessible as a [ChromeOnly] property on - // Window.WebIDL, and [noscript] in XPIDL. Chrome needs to see this over - // Xray, so we need to special-case it until we move |Window| to WebIDL. - nsGlobalWindow* win = nullptr; - if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_CONTROLLERS) && - AccessCheck::isChrome(wrapper) && - (win = AsWindow(cx, wrapper))) - { - nsCOMPtr c; - nsresult rv = win->GetControllers(getter_AddRefs(c)); - if (NS_SUCCEEDED(rv) && c) { - rv = nsXPConnect::XPConnect()->WrapNativeToJSVal(cx, CurrentGlobalOrNull(cx), - c, nullptr, nullptr, true, - desc.value()); - } - - if (NS_FAILED(rv) || !c) { - JS_ReportError(cx, "Failed to invoke GetControllers via Xrays"); - return false; - } - - desc.object().set(wrapper); - return true; - } - - // The |realFrameElement| property is accessible as a [ChromeOnly] property - // on Window.WebIDL, and [noscript] in XPIDL. Chrome needs to see this over - // Xray, so we need to special-case it until we move |Window| to WebIDL. - if (id == GetRTIdByIndex(cx, XPCJSRuntime::IDX_REALFRAMEELEMENT) && - AccessCheck::isChrome(wrapper) && - (win = AsWindow(cx, wrapper))) - { - ErrorResult rv; - Element* f = win->GetRealFrameElement(rv); - if (!f) { - desc.object().set(nullptr); - return true; - } - - if (!GetOrCreateDOMReflector(cx, f, desc.value())) { - return false; - } - - desc.object().set(wrapper); - return true; - } - XPCNativeInterface* iface; XPCNativeMember* member; XPCWrappedNative* wn = getWN(wrapper); @@ -1533,28 +1477,6 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsW if (!ok || desc.object()) return ok; - // Check for indexed access on a window. - int32_t index = GetArrayIndexFromId(cx, id); - if (IsArrayIndex(index)) { - nsGlobalWindow* win = AsWindow(cx, wrapper); - // Note: As() unwraps outer windows to get to the inner window. - if (win) { - nsCOMPtr subframe = win->IndexedGetter(index); - if (subframe) { - subframe->EnsureInnerWindow(); - nsGlobalWindow* global = nsGlobalWindow::Cast(subframe); - JSObject* obj = global->FastGetGlobalJSObject(); - if (MOZ_UNLIKELY(!obj)) { - // It's gone? - return xpc::Throw(cx, NS_ERROR_FAILURE); - } - desc.value().setObject(*obj); - FillPropertyDescriptor(desc, wrapper, true); - return JS_WrapPropertyDescriptor(cx, desc); - } - } - } - // Xray wrappers don't use the regular wrapper hierarchy, so we should be // in the wrapper's compartment here, not the wrappee. MOZ_ASSERT(js::IsObjectInContextCompartment(wrapper, cx)); @@ -1562,26 +1484,6 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext* cx, const Wrapper& jsW return JS_GetOwnPropertyDescriptorById(cx, holder, id, desc); } -bool -XPCWrappedNativeXrayTraits::defineProperty(JSContext* cx, HandleObject wrapper, HandleId id, - Handle desc, - Handle existingDesc, - JS::ObjectOpResult& result, bool* defined) -{ - *defined = false; - RootedObject holder(cx, singleton.ensureHolder(cx, wrapper)); - - // Check for an indexed property on a Window. If that's happening, do - // nothing but claim we defined it so it won't get added as an expando. - int32_t index = GetArrayIndexFromId(cx, id); - if (IsArrayIndex(index) && IsWindow(cx, wrapper)) { - *defined = true; - return result.succeed(); - } - - return true; -} - bool XPCWrappedNativeXrayTraits::enumerateNames(JSContext* cx, HandleObject wrapper, unsigned flags, AutoIdVector& props) diff --git a/js/xpconnect/wrappers/XrayWrapper.h b/js/xpconnect/wrappers/XrayWrapper.h index 2e10711f18b..ceabc8704d7 100644 --- a/js/xpconnect/wrappers/XrayWrapper.h +++ b/js/xpconnect/wrappers/XrayWrapper.h @@ -135,7 +135,11 @@ public: bool defineProperty(JSContext* cx, JS::HandleObject wrapper, JS::HandleId id, JS::Handle desc, JS::Handle existingDesc, - JS::ObjectOpResult& result, bool* defined); + JS::ObjectOpResult& result, bool* defined) + { + *defined = false; + return true; + } virtual bool enumerateNames(JSContext* cx, JS::HandleObject wrapper, unsigned flags, JS::AutoIdVector& props); static bool call(JSContext* cx, JS::HandleObject wrapper, @@ -143,10 +147,6 @@ public: static bool construct(JSContext* cx, JS::HandleObject wrapper, const JS::CallArgs& args, const js::Wrapper& baseInstance); - static bool resolveDOMCollectionProperty(JSContext* cx, JS::HandleObject wrapper, - JS::HandleObject holder, JS::HandleId id, - JS::MutableHandle desc); - static XPCWrappedNative* getWN(JSObject* wrapper); virtual void preserveWrapper(JSObject* target) override;