Line data Source code
1 : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /* vim: set ts=8 sts=4 et sw=4 tw=99: */
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 :
11 : using namespace JS;
12 :
13 : namespace xpc {
14 :
15 : static bool
16 0 : WaiveAccessors(JSContext* cx, MutableHandle<PropertyDescriptor> desc)
17 : {
18 0 : if (desc.hasGetterObject() && desc.getterObject()) {
19 0 : RootedValue v(cx, JS::ObjectValue(*desc.getterObject()));
20 0 : if (!WrapperFactory::WaiveXrayAndWrap(cx, &v))
21 0 : return false;
22 0 : desc.setGetterObject(&v.toObject());
23 : }
24 :
25 0 : if (desc.hasSetterObject() && desc.setterObject()) {
26 0 : RootedValue v(cx, JS::ObjectValue(*desc.setterObject()));
27 0 : if (!WrapperFactory::WaiveXrayAndWrap(cx, &v))
28 0 : return false;
29 0 : desc.setSetterObject(&v.toObject());
30 : }
31 0 : return true;
32 : }
33 :
34 : bool
35 0 : WaiveXrayWrapper::getPropertyDescriptor(JSContext* cx, HandleObject wrapper, HandleId id,
36 : MutableHandle<PropertyDescriptor> desc) const
37 : {
38 0 : return CrossCompartmentWrapper::getPropertyDescriptor(cx, wrapper, id, desc) &&
39 0 : WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc);
40 : }
41 :
42 : bool
43 0 : WaiveXrayWrapper::getOwnPropertyDescriptor(JSContext* cx, HandleObject wrapper, HandleId id,
44 : MutableHandle<PropertyDescriptor> desc) const
45 : {
46 0 : return CrossCompartmentWrapper::getOwnPropertyDescriptor(cx, wrapper, id, desc) &&
47 0 : WrapperFactory::WaiveXrayAndWrap(cx, desc.value()) && WaiveAccessors(cx, desc);
48 : }
49 :
50 : bool
51 0 : WaiveXrayWrapper::get(JSContext* cx, HandleObject wrapper, HandleValue receiver, HandleId id,
52 : MutableHandleValue vp) const
53 : {
54 0 : return CrossCompartmentWrapper::get(cx, wrapper, receiver, id, vp) &&
55 0 : WrapperFactory::WaiveXrayAndWrap(cx, vp);
56 : }
57 :
58 : JSObject*
59 0 : WaiveXrayWrapper::enumerate(JSContext* cx, HandleObject proxy) const
60 : {
61 0 : RootedObject obj(cx, CrossCompartmentWrapper::enumerate(cx, proxy));
62 0 : if (!obj)
63 0 : return nullptr;
64 0 : if (!WrapperFactory::WaiveXrayAndWrap(cx, &obj))
65 0 : return nullptr;
66 0 : return obj;
67 : }
68 :
69 : bool
70 0 : WaiveXrayWrapper::call(JSContext* cx, HandleObject wrapper, const JS::CallArgs& args) const
71 : {
72 0 : return CrossCompartmentWrapper::call(cx, wrapper, args) &&
73 0 : WrapperFactory::WaiveXrayAndWrap(cx, args.rval());
74 : }
75 :
76 : bool
77 0 : WaiveXrayWrapper::construct(JSContext* cx, HandleObject wrapper, const JS::CallArgs& args) const
78 : {
79 0 : return CrossCompartmentWrapper::construct(cx, wrapper, args) &&
80 0 : WrapperFactory::WaiveXrayAndWrap(cx, args.rval());
81 : }
82 :
83 : // NB: This is important as the other side of a handshake with FieldGetter. See
84 : // nsXBLProtoImplField.cpp.
85 : bool
86 0 : WaiveXrayWrapper::nativeCall(JSContext* cx, JS::IsAcceptableThis test,
87 : JS::NativeImpl impl, const JS::CallArgs& args) const
88 : {
89 0 : return CrossCompartmentWrapper::nativeCall(cx, test, impl, args) &&
90 0 : WrapperFactory::WaiveXrayAndWrap(cx, args.rval());
91 : }
92 :
93 : bool
94 0 : WaiveXrayWrapper::getPrototype(JSContext* cx, HandleObject wrapper, MutableHandleObject protop) const
95 : {
96 0 : return CrossCompartmentWrapper::getPrototype(cx, wrapper, protop) &&
97 0 : (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop));
98 : }
99 :
100 : bool
101 0 : WaiveXrayWrapper::getPrototypeIfOrdinary(JSContext* cx, HandleObject wrapper, bool* isOrdinary,
102 : MutableHandleObject protop) const
103 : {
104 0 : return CrossCompartmentWrapper::getPrototypeIfOrdinary(cx, wrapper, isOrdinary, protop) &&
105 0 : (!protop || WrapperFactory::WaiveXrayAndWrap(cx, protop));
106 : }
107 :
108 : } // namespace xpc
|