WaiveXrayWrapper.cpp (3486B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #include "WaiveXrayWrapper.h" 8 #include "WrapperFactory.h" 9 #include "jsapi.h" 10 #include "js/CallAndConstruct.h" // JS::IsCallable 11 12 using namespace JS; 13 14 namespace xpc { 15 16 bool WaiveXrayWrapper::getOwnPropertyDescriptor( 17 JSContext* cx, HandleObject wrapper, HandleId id, 18 MutableHandle<mozilla::Maybe<PropertyDescriptor>> desc) const { 19 if (!CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, 20 desc)) { 21 return false; 22 } 23 24 if (desc.isNothing()) { 25 return true; 26 } 27 28 Rooted<PropertyDescriptor> desc_(cx, *desc); 29 if (desc_.hasValue()) { 30 if (!WrapperFactory::WaiveXrayAndWrap(cx, desc_.value())) { 31 return false; 32 } 33 } 34 if (desc_.hasGetter() && desc_.getter()) { 35 RootedValue v(cx, JS::ObjectValue(*desc_.getter())); 36 if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) { 37 return false; 38 } 39 desc_.setGetter(&v.toObject()); 40 } 41 if (desc_.hasSetter() && desc_.setter()) { 42 RootedValue v(cx, JS::ObjectValue(*desc_.setter())); 43 if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) { 44 return false; 45 } 46 desc_.setSetter(&v.toObject()); 47 } 48 49 desc.set(mozilla::Some(desc_.get())); 50 return true; 51 } 52 53 bool WaiveXrayWrapper::get(JSContext* cx, HandleObject wrapper, 54 HandleValue receiver, HandleId id, 55 MutableHandleValue vp) const { 56 return CrossCompartmentWrapper::get(cx, wrapper, receiver, id, vp) && 57 WrapperFactory::WaiveXrayAndWrap(cx, vp); 58 } 59 60 bool WaiveXrayWrapper::call(JSContext* cx, HandleObject wrapper, 61 const JS::CallArgs& args) const { 62 return CrossCompartmentWrapper::call(cx, wrapper, args) && 63 WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); 64 } 65 66 bool WaiveXrayWrapper::construct(JSContext* cx, HandleObject wrapper, 67 const JS::CallArgs& args) const { 68 return CrossCompartmentWrapper::construct(cx, wrapper, args) && 69 WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); 70 } 71 72 // NB: This is important as the other side of a handshake with FieldGetter. See 73 // nsXBLProtoImplField.cpp. 74 bool WaiveXrayWrapper::nativeCall(JSContext* cx, JS::IsAcceptableThis test, 75 JS::NativeImpl impl, 76 const JS::CallArgs& args) const { 77 return CrossCompartmentWrapper::nativeCall(cx, test, impl, args) && 78 WrapperFactory::WaiveXrayAndWrap(cx, args.rval()); 79 } 80 81 bool WaiveXrayWrapper::getPrototype(JSContext* cx, HandleObject wrapper, 82 MutableHandleObject protop) const { 83 return CrossCompartmentWrapper::getPrototype(cx, wrapper, protop) && 84 (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop)); 85 } 86 87 bool WaiveXrayWrapper::getPrototypeIfOrdinary( 88 JSContext* cx, HandleObject wrapper, bool* isOrdinary, 89 MutableHandleObject protop) const { 90 return CrossCompartmentWrapper::getPrototypeIfOrdinary(cx, wrapper, 91 isOrdinary, protop) && 92 (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop)); 93 } 94 95 } // namespace xpc