michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* vim: set ts=8 sts=4 et sw=4 tw=99: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "WaiveXrayWrapper.h" michael@0: #include "WrapperFactory.h" michael@0: #include "jsapi.h" michael@0: michael@0: using namespace JS; michael@0: michael@0: namespace xpc { michael@0: michael@0: static bool michael@0: WaiveAccessors(JSContext *cx, JS::MutableHandle desc) michael@0: { michael@0: if (desc.hasGetterObject() && desc.getterObject()) { michael@0: RootedValue v(cx, JS::ObjectValue(*desc.getterObject())); michael@0: if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) michael@0: return false; michael@0: desc.setGetterObject(&v.toObject()); michael@0: } michael@0: michael@0: if (desc.hasSetterObject() && desc.setterObject()) { michael@0: RootedValue v(cx, JS::ObjectValue(*desc.setterObject())); michael@0: if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) michael@0: return false; michael@0: desc.setSetterObject(&v.toObject()); michael@0: } michael@0: return true; michael@0: } michael@0: michael@0: WaiveXrayWrapper::WaiveXrayWrapper(unsigned flags) : js::CrossCompartmentWrapper(flags) michael@0: { michael@0: } michael@0: michael@0: WaiveXrayWrapper::~WaiveXrayWrapper() michael@0: { michael@0: } michael@0: michael@0: bool michael@0: WaiveXrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wrapper, michael@0: HandleId id, JS::MutableHandle desc) michael@0: { michael@0: return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, desc) && michael@0: WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc); michael@0: } michael@0: michael@0: bool michael@0: WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, michael@0: HandleId id, JS::MutableHandle desc) michael@0: { michael@0: return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc) && michael@0: WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc); michael@0: } michael@0: michael@0: bool michael@0: WaiveXrayWrapper::get(JSContext *cx, HandleObject wrapper, michael@0: HandleObject receiver, HandleId id, michael@0: MutableHandleValue vp) michael@0: { michael@0: return CrossCompartmentWrapper::get(cx, wrapper, receiver, id, vp) && michael@0: WrapperFactory::WaiveXrayAndWrap(cx, vp); michael@0: } michael@0: michael@0: bool michael@0: WaiveXrayWrapper::call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args) michael@0: { michael@0: return CrossCompartmentWrapper::call(cx, wrapper, args) && michael@0: WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); michael@0: } michael@0: michael@0: bool michael@0: WaiveXrayWrapper::construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args) michael@0: { michael@0: return CrossCompartmentWrapper::construct(cx, wrapper, args) && michael@0: WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); michael@0: } michael@0: michael@0: // NB: This is important as the other side of a handshake with FieldGetter. See michael@0: // nsXBLProtoImplField.cpp. michael@0: bool michael@0: WaiveXrayWrapper::nativeCall(JSContext *cx, JS::IsAcceptableThis test, michael@0: JS::NativeImpl impl, JS::CallArgs args) michael@0: { michael@0: return CrossCompartmentWrapper::nativeCall(cx, test, impl, args) && michael@0: WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); michael@0: } michael@0: michael@0: bool michael@0: WaiveXrayWrapper::getPrototypeOf(JSContext *cx, HandleObject wrapper, MutableHandleObject protop) michael@0: { michael@0: return CrossCompartmentWrapper::getPrototypeOf(cx, wrapper, protop) && michael@0: (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop)); michael@0: } michael@0: michael@0: }