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/. */
7 #include "WaiveXrayWrapper.h"
8 #include "WrapperFactory.h"
10 #include "js/CallAndConstruct.h" // JS::IsCallable
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
,
24 if (desc
.isNothing()) {
28 Rooted
<PropertyDescriptor
> desc_(cx
, *desc
);
29 if (desc_
.hasValue()) {
30 if (!WrapperFactory::WaiveXrayAndWrap(cx
, desc_
.value())) {
34 if (desc_
.hasGetter() && desc_
.getter()) {
35 RootedValue
v(cx
, JS::ObjectValue(*desc_
.getter()));
36 if (!WrapperFactory::WaiveXrayAndWrap(cx
, &v
)) {
39 desc_
.setGetter(&v
.toObject());
41 if (desc_
.hasSetter() && desc_
.setter()) {
42 RootedValue
v(cx
, JS::ObjectValue(*desc_
.setter()));
43 if (!WrapperFactory::WaiveXrayAndWrap(cx
, &v
)) {
46 desc_
.setSetter(&v
.toObject());
49 desc
.set(mozilla::Some(desc_
.get()));
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
);
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());
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());
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
,
76 const JS::CallArgs
& args
) const {
77 return CrossCompartmentWrapper::nativeCall(cx
, test
, impl
, args
) &&
78 WrapperFactory::WaiveXrayAndWrap(cx
, args
.rval());
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
));
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
));