Bug 1941128 - Turn off network.dns.native_https_query on Mac again
[gecko.git] / js / xpconnect / wrappers / WaiveXrayWrapper.cpp
blob17c273a5e0aa3160da0d2516d6b8dfd914924d50
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"
9 #include "jsapi.h"
10 #include "js/CallAndConstruct.h" // JS::IsCallable
12 using namespace JS;
14 namespace xpc {
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;
24 if (desc.isNothing()) {
25 return true;
28 Rooted<PropertyDescriptor> desc_(cx, *desc);
29 if (desc_.hasValue()) {
30 if (!WrapperFactory::WaiveXrayAndWrap(cx, desc_.value())) {
31 return false;
34 if (desc_.hasGetter() && desc_.getter()) {
35 RootedValue v(cx, JS::ObjectValue(*desc_.getter()));
36 if (!WrapperFactory::WaiveXrayAndWrap(cx, &v)) {
37 return false;
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)) {
44 return false;
46 desc_.setSetter(&v.toObject());
49 desc.set(mozilla::Some(desc_.get()));
50 return true;
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,
75 JS::NativeImpl impl,
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));
95 } // namespace xpc