From 29f5ad412011012bce8ac2c4842406a12e4a4f50 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Mon, 1 Jul 2013 09:14:36 +0200 Subject: [PATCH] Bug 888579 - Remove some code that handled WN Nodes; r=bholley --- dom/bindings/BindingUtils.cpp | 2 + js/xpconnect/src/XPCJSRuntime.cpp | 33 ++----- js/xpconnect/src/xpcprivate.h | 3 - js/xpconnect/wrappers/XrayWrapper.cpp | 135 +------------------------- 4 files changed, 10 insertions(+), 163 deletions(-) diff --git a/dom/bindings/BindingUtils.cpp b/dom/bindings/BindingUtils.cpp index 9c3310758cc..ff71e66d944 100644 --- a/dom/bindings/BindingUtils.cpp +++ b/dom/bindings/BindingUtils.cpp @@ -636,6 +636,8 @@ NativeInterface2JSObjectAndThrowIfFailed(JSContext* aCx, bool TryPreserveWrapper(JSObject* obj) { + MOZ_ASSERT(IsDOMObject(obj)); + if (nsISupports* native = UnwrapDOMObjectToISupports(obj)) { nsWrapperCache* cache = nullptr; CallQueryInterface(native, &cache); diff --git a/js/xpconnect/src/XPCJSRuntime.cpp b/js/xpconnect/src/XPCJSRuntime.cpp index 3892538f707..a56bcf55504 100644 --- a/js/xpconnect/src/XPCJSRuntime.cpp +++ b/js/xpconnect/src/XPCJSRuntime.cpp @@ -1,6 +1,6 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- - * - * This Source Code Form is subject to the terms of the Mozilla Public +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* vim: set ts=8 sts=4 et sw=4 tw=99: */ +/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ @@ -71,9 +71,6 @@ const char* XPCJSRuntime::mStrings[] = { "__proto__", // IDX_PROTO "__iterator__", // IDX_ITERATOR "__exposedProps__", // IDX_EXPOSEDPROPS - "baseURIObject", // IDX_BASEURIOBJECT - "nodePrincipal", // IDX_NODEPRINCIPAL - "mozMatchesSelector" // IDX_MOZMATCHESSELECTOR }; /***************************************************************************/ @@ -2514,29 +2511,13 @@ CompartmentNameCallback(JSRuntime *rt, JSCompartment *comp, } static bool -PreserveWrapper(JSContext *cx, JSObject *objArg) +PreserveWrapper(JSContext *cx, JSObject *obj) { MOZ_ASSERT(cx); - MOZ_ASSERT(objArg); - MOZ_ASSERT(js::GetObjectClass(objArg)->ext.isWrappedNative || - mozilla::dom::IsDOMObject(objArg)); + MOZ_ASSERT(obj); + MOZ_ASSERT(IS_WN_REFLECTOR(obj) || mozilla::dom::IsDOMObject(obj)); - RootedObject obj(cx, objArg); - XPCCallContext ccx(NATIVE_CALLER, cx); - if (!ccx.IsValid()) - return false; - - if (!IS_WN_REFLECTOR(obj)) - return mozilla::dom::TryPreserveWrapper(obj); - - nsISupports *supports = XPCWrappedNative::Get(obj)->Native(); - - // For pre-Paris DOM bindings objects, we only support Node. - if (nsCOMPtr node = do_QueryInterface(supports)) { - node->PreserveWrapper(supports); - return true; - } - return false; + return mozilla::dom::IsDOMObject(obj) && mozilla::dom::TryPreserveWrapper(obj); } static nsresult diff --git a/js/xpconnect/src/xpcprivate.h b/js/xpconnect/src/xpcprivate.h index cc6a82598d0..e74fb74f19c 100644 --- a/js/xpconnect/src/xpcprivate.h +++ b/js/xpconnect/src/xpcprivate.h @@ -717,9 +717,6 @@ public: IDX_PROTO , IDX_ITERATOR , IDX_EXPOSEDPROPS , - IDX_BASEURIOBJECT , - IDX_NODEPRINCIPAL , - IDX_MOZMATCHESSELECTOR , IDX_TOTAL_COUNT // just a count of the above }; diff --git a/js/xpconnect/wrappers/XrayWrapper.cpp b/js/xpconnect/wrappers/XrayWrapper.cpp index 1803f442413..22fcd21feb2 100644 --- a/js/xpconnect/wrappers/XrayWrapper.cpp +++ b/js/xpconnect/wrappers/XrayWrapper.cpp @@ -11,9 +11,7 @@ #include "WaiveXrayWrapper.h" #include "WrapperFactory.h" -#include "nsINode.h" #include "nsIContent.h" -#include "nsIDocument.h" #include "nsContentUtils.h" #include "XPCWrapper.h" @@ -681,44 +679,6 @@ Is(JSObject *wrapper) static nsQueryInterface do_QueryInterfaceNative(JSContext* cx, HandleObject wrapper); -// Helper function to work around some limitations of the current XPC -// calling mechanism. See: bug 763897. -// The idea is that we unwrap the 'this' object, and find the wrapped -// native that belongs to it. Then we simply make the call directly -// on it after a Query Interface. -static JSBool -mozMatchesSelectorStub(JSContext *cx, unsigned argc, jsval *vp) -{ - if (argc < 1) { - JS_ReportError(cx, "Not enough arguments"); - return false; - } - - RootedObject wrapper(cx, JS_THIS_OBJECT(cx, vp)); - RootedString selector(cx, JS_ValueToString(cx, JS_ARGV(cx, vp)[0])); - if (!selector) { - return false; - } - nsDependentJSString selectorStr; - NS_ENSURE_TRUE(selectorStr.init(cx, selector), false); - - nsCOMPtr element = do_QueryInterfaceNative(cx, wrapper); - if (!element) { - JS_ReportError(cx, "Unexpected object"); - return false; - } - - bool ret; - nsresult rv = element->MozMatchesSelector(selectorStr, &ret); - if (NS_FAILED(rv)) { - XPCThrower::Throw(rv, cx); - return false; - } - - JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); - return true; -} - void XPCWrappedNativeXrayTraits::preserveWrapper(JSObject *target) { @@ -735,28 +695,6 @@ XPCWrappedNativeXrayTraits::resolveNativeProperty(JSContext *cx, HandleObject wr JSPropertyDescriptor *desc, unsigned flags) { MOZ_ASSERT(js::GetObjectJSClass(holder) == &HolderClass); - XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - if (id == rt->GetStringID(XPCJSRuntime::IDX_MOZMATCHESSELECTOR) && - Is(wrapper)) - { - // XPC calling mechanism cannot handle call/bind properly in some cases - // especially through xray wrappers. This is a temporary work around for - // this problem for mozMatchesSelector. See: bug 763897. - desc->obj = wrapper; - desc->attrs = JSPROP_ENUMERATE; - RootedObject proto(cx); - if (!JS_GetPrototype(cx, wrapper, proto.address())) - return false; - JSFunction *fun = JS_NewFunction(cx, mozMatchesSelectorStub, - 1, 0, proto, - "mozMatchesSelector"); - NS_ENSURE_TRUE(fun, false); - desc->value = OBJECT_TO_JSVAL(JS_GetFunctionObject(fun)); - desc->getter = NULL; - desc->setter = NULL; - desc->shortid = 0; - return true; - } desc->obj = NULL; @@ -855,60 +793,6 @@ wrappedJSObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, Mutable return WrapperFactory::WaiveXrayAndWrap(cx, vp.address()); } -static JSBool -WrapURI(JSContext *cx, nsIURI *uri, MutableHandleValue vp) -{ - RootedObject scope(cx, JS_GetGlobalForScopeChain(cx)); - nsresult rv = - nsXPConnect::XPConnect()->WrapNativeToJSVal(cx, scope, uri, nullptr, - &NS_GET_IID(nsIURI), true, - vp.address(), nullptr); - if (NS_FAILED(rv)) { - XPCThrower::Throw(rv, cx); - return false; - } - return true; -} - -static JSBool -baseURIObject_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp) -{ - nsCOMPtr native = do_QueryInterfaceNative(cx, wrapper); - if (!native) { - JS_ReportError(cx, "Unexpected object"); - return false; - } - - nsCOMPtr uri = native->GetBaseURI(); - if (!uri) { - JS_ReportOutOfMemory(cx); - return false; - } - - return WrapURI(cx, uri, vp); -} - -static JSBool -nodePrincipal_getter(JSContext *cx, HandleObject wrapper, HandleId id, MutableHandleValue vp) -{ - nsCOMPtr node = do_QueryInterfaceNative(cx, wrapper); - if (!node) { - JS_ReportError(cx, "Unexpected object"); - return false; - } - - RootedObject scope(cx, JS_GetGlobalForScopeChain(cx)); - nsresult rv = - nsXPConnect::XPConnect()->WrapNativeToJSVal(cx, scope, node->NodePrincipal(), nullptr, - &NS_GET_IID(nsIPrincipal), true, - vp.address(), nullptr); - if (NS_FAILED(rv)) { - XPCThrower::Throw(rv, cx); - return false; - } - return true; -} - bool XrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper, HandleObject wrapper, HandleObject holder, HandleId id, @@ -973,23 +857,6 @@ XPCWrappedNativeXrayTraits::resolveOwnProperty(JSContext *cx, Wrapper &jsWrapper // 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)); - XPCJSRuntime* rt = nsXPConnect::GetRuntimeInstance(); - if (AccessCheck::isChrome(wrapper) && - ((id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT) || - id == rt->GetStringID(XPCJSRuntime::IDX_NODEPRINCIPAL)) && - Is(wrapper))) - { - desc->obj = wrapper; - desc->attrs = JSPROP_ENUMERATE|JSPROP_SHARED; - if (id == rt->GetStringID(XPCJSRuntime::IDX_BASEURIOBJECT)) - desc->getter = baseURIObject_getter; - else - desc->getter = nodePrincipal_getter; - desc->setter = NULL; - desc->shortid = 0; - desc->value = JSVAL_VOID; - return true; - } JSBool hasProp; if (!JS_HasPropertyById(cx, holder, id, &hasProp)) { @@ -1589,7 +1456,7 @@ XrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wra // If we still have nothing, we're done. if (!desc->obj) - return true; + return true; if (!JS_DefinePropertyById(cx, holder, id, desc->value, desc->getter, desc->setter, desc->attrs) ||