1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/xpconnect/wrappers/WaiveXrayWrapper.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,98 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* vim: set ts=8 sts=4 et sw=4 tw=99: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#include "WaiveXrayWrapper.h" 1.11 +#include "WrapperFactory.h" 1.12 +#include "jsapi.h" 1.13 + 1.14 +using namespace JS; 1.15 + 1.16 +namespace xpc { 1.17 + 1.18 +static bool 1.19 +WaiveAccessors(JSContext *cx, JS::MutableHandle<JSPropertyDescriptor> desc) 1.20 +{ 1.21 + if (desc.hasGetterObject() && desc.getterObject()) { 1.22 + RootedValue v(cx, JS::ObjectValue(*desc.getterObject())); 1.23 + if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) 1.24 + return false; 1.25 + desc.setGetterObject(&v.toObject()); 1.26 + } 1.27 + 1.28 + if (desc.hasSetterObject() && desc.setterObject()) { 1.29 + RootedValue v(cx, JS::ObjectValue(*desc.setterObject())); 1.30 + if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) 1.31 + return false; 1.32 + desc.setSetterObject(&v.toObject()); 1.33 + } 1.34 + return true; 1.35 +} 1.36 + 1.37 +WaiveXrayWrapper::WaiveXrayWrapper(unsigned flags) : js::CrossCompartmentWrapper(flags) 1.38 +{ 1.39 +} 1.40 + 1.41 +WaiveXrayWrapper::~WaiveXrayWrapper() 1.42 +{ 1.43 +} 1.44 + 1.45 +bool 1.46 +WaiveXrayWrapper::getPropertyDescriptor(JSContext *cx, HandleObject wrapper, 1.47 + HandleId id, JS::MutableHandle<JSPropertyDescriptor> desc) 1.48 +{ 1.49 + return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, desc) && 1.50 + WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc); 1.51 +} 1.52 + 1.53 +bool 1.54 +WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext *cx, HandleObject wrapper, 1.55 + HandleId id, JS::MutableHandle<JSPropertyDescriptor> desc) 1.56 +{ 1.57 + return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc) && 1.58 + WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc); 1.59 +} 1.60 + 1.61 +bool 1.62 +WaiveXrayWrapper::get(JSContext *cx, HandleObject wrapper, 1.63 + HandleObject receiver, HandleId id, 1.64 + MutableHandleValue vp) 1.65 +{ 1.66 + return CrossCompartmentWrapper::get(cx, wrapper, receiver, id, vp) && 1.67 + WrapperFactory::WaiveXrayAndWrap(cx, vp); 1.68 +} 1.69 + 1.70 +bool 1.71 +WaiveXrayWrapper::call(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args) 1.72 +{ 1.73 + return CrossCompartmentWrapper::call(cx, wrapper, args) && 1.74 + WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); 1.75 +} 1.76 + 1.77 +bool 1.78 +WaiveXrayWrapper::construct(JSContext *cx, HandleObject wrapper, const JS::CallArgs &args) 1.79 +{ 1.80 + return CrossCompartmentWrapper::construct(cx, wrapper, args) && 1.81 + WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); 1.82 +} 1.83 + 1.84 +// NB: This is important as the other side of a handshake with FieldGetter. See 1.85 +// nsXBLProtoImplField.cpp. 1.86 +bool 1.87 +WaiveXrayWrapper::nativeCall(JSContext *cx, JS::IsAcceptableThis test, 1.88 + JS::NativeImpl impl, JS::CallArgs args) 1.89 +{ 1.90 + return CrossCompartmentWrapper::nativeCall(cx, test, impl, args) && 1.91 + WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); 1.92 +} 1.93 + 1.94 +bool 1.95 +WaiveXrayWrapper::getPrototypeOf(JSContext *cx, HandleObject wrapper, MutableHandleObject protop) 1.96 +{ 1.97 + return CrossCompartmentWrapper::getPrototypeOf(cx, wrapper, protop) && 1.98 + (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop)); 1.99 +} 1.100 + 1.101 +}