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 "jswrapper.h"
8 
9 #include "jsobjinlines.h"
10 
11 using namespace js;
12 
13 bool
getOwnPropertyDescriptor(JSContext * cx,HandleObject wrapper,HandleId id,MutableHandle<PropertyDescriptor> desc) const14 OpaqueCrossCompartmentWrapper::getOwnPropertyDescriptor(JSContext* cx,
15                                                         HandleObject wrapper,
16                                                         HandleId id,
17                                                         MutableHandle<PropertyDescriptor> desc) const
18 {
19     desc.object().set(nullptr);
20     return true;
21 }
22 
23 bool
defineProperty(JSContext * cx,HandleObject wrapper,HandleId id,Handle<JSPropertyDescriptor> desc,ObjectOpResult & result) const24 OpaqueCrossCompartmentWrapper::defineProperty(JSContext* cx, HandleObject wrapper, HandleId id,
25                                               Handle<JSPropertyDescriptor> desc,
26                                               ObjectOpResult& result) const
27 {
28     return result.succeed();
29 }
30 
31 bool
ownPropertyKeys(JSContext * cx,HandleObject wrapper,AutoIdVector & props) const32 OpaqueCrossCompartmentWrapper::ownPropertyKeys(JSContext* cx, HandleObject wrapper,
33                                                AutoIdVector& props) const
34 {
35     return true;
36 }
37 
38 bool
delete_(JSContext * cx,HandleObject wrapper,HandleId id,ObjectOpResult & result) const39 OpaqueCrossCompartmentWrapper::delete_(JSContext* cx, HandleObject wrapper, HandleId id,
40                                        ObjectOpResult& result) const
41 {
42     return result.succeed();
43 }
44 
45 bool
enumerate(JSContext * cx,HandleObject wrapper,MutableHandleObject objp) const46 OpaqueCrossCompartmentWrapper::enumerate(JSContext* cx, HandleObject wrapper,
47                                          MutableHandleObject objp) const
48 {
49     return BaseProxyHandler::enumerate(cx, wrapper, objp);
50 }
51 
52 bool
getPrototype(JSContext * cx,HandleObject proxy,MutableHandleObject protop) const53 OpaqueCrossCompartmentWrapper::getPrototype(JSContext* cx, HandleObject proxy,
54                                             MutableHandleObject protop) const
55 {
56     protop.set(nullptr);
57     return true;
58 }
59 
60 bool
setPrototype(JSContext * cx,HandleObject proxy,HandleObject proto,ObjectOpResult & result) const61 OpaqueCrossCompartmentWrapper::setPrototype(JSContext* cx, HandleObject proxy, HandleObject proto,
62                                             ObjectOpResult& result) const
63 {
64     return result.succeed();
65 }
66 
67 bool
setImmutablePrototype(JSContext * cx,HandleObject proxy,bool * succeeded) const68 OpaqueCrossCompartmentWrapper::setImmutablePrototype(JSContext* cx, HandleObject proxy,
69                                                      bool* succeeded) const
70 {
71     *succeeded = false;
72     return true;
73 }
74 
75 bool
preventExtensions(JSContext * cx,HandleObject wrapper,ObjectOpResult & result) const76 OpaqueCrossCompartmentWrapper::preventExtensions(JSContext* cx, HandleObject wrapper,
77                                                  ObjectOpResult& result) const
78 {
79     return result.failCantPreventExtensions();
80 }
81 
82 bool
isExtensible(JSContext * cx,HandleObject wrapper,bool * extensible) const83 OpaqueCrossCompartmentWrapper::isExtensible(JSContext* cx, HandleObject wrapper,
84                                             bool* extensible) const
85 {
86     *extensible = true;
87     return true;
88 }
89 
90 bool
has(JSContext * cx,HandleObject wrapper,HandleId id,bool * bp) const91 OpaqueCrossCompartmentWrapper::has(JSContext* cx, HandleObject wrapper, HandleId id,
92                                    bool* bp) const
93 {
94     return BaseProxyHandler::has(cx, wrapper, id, bp);
95 }
96 
97 bool
get(JSContext * cx,HandleObject wrapper,HandleValue receiver,HandleId id,MutableHandleValue vp) const98 OpaqueCrossCompartmentWrapper::get(JSContext* cx, HandleObject wrapper, HandleValue receiver,
99                                    HandleId id, MutableHandleValue vp) const
100 {
101     return BaseProxyHandler::get(cx, wrapper, receiver, id, vp);
102 }
103 
104 bool
set(JSContext * cx,HandleObject wrapper,HandleId id,HandleValue v,HandleValue receiver,ObjectOpResult & result) const105 OpaqueCrossCompartmentWrapper::set(JSContext* cx, HandleObject wrapper, HandleId id,
106                                    HandleValue v, HandleValue receiver,
107                                    ObjectOpResult& result) const
108 {
109     return BaseProxyHandler::set(cx, wrapper, id, v, receiver, result);
110 }
111 
112 bool
call(JSContext * cx,HandleObject wrapper,const CallArgs & args) const113 OpaqueCrossCompartmentWrapper::call(JSContext* cx, HandleObject wrapper,
114                                     const CallArgs& args) const
115 {
116     RootedValue v(cx, ObjectValue(*wrapper));
117     ReportIsNotFunction(cx, v);
118     return false;
119 }
120 
121 bool
construct(JSContext * cx,HandleObject wrapper,const CallArgs & args) const122 OpaqueCrossCompartmentWrapper::construct(JSContext* cx, HandleObject wrapper,
123                                          const CallArgs& args) const
124 {
125     RootedValue v(cx, ObjectValue(*wrapper));
126     ReportIsNotFunction(cx, v);
127     return false;
128 }
129 
130 bool
getPropertyDescriptor(JSContext * cx,HandleObject wrapper,HandleId id,MutableHandle<JSPropertyDescriptor> desc) const131 OpaqueCrossCompartmentWrapper::getPropertyDescriptor(JSContext* cx,
132                                                      HandleObject wrapper,
133                                                      HandleId id,
134                                                      MutableHandle<JSPropertyDescriptor> desc) const
135 {
136     return BaseProxyHandler::getPropertyDescriptor(cx, wrapper, id, desc);
137 }
138 
139 bool
hasOwn(JSContext * cx,HandleObject wrapper,HandleId id,bool * bp) const140 OpaqueCrossCompartmentWrapper::hasOwn(JSContext* cx, HandleObject wrapper, HandleId id,
141                                       bool* bp) const
142 {
143     return BaseProxyHandler::hasOwn(cx, wrapper, id, bp);
144 }
145 
146 bool
getOwnEnumerablePropertyKeys(JSContext * cx,HandleObject wrapper,AutoIdVector & props) const147 OpaqueCrossCompartmentWrapper::getOwnEnumerablePropertyKeys(JSContext* cx, HandleObject wrapper,
148                                                             AutoIdVector& props) const
149 {
150     return BaseProxyHandler::getOwnEnumerablePropertyKeys(cx, wrapper, props);
151 }
152 
153 bool
getBuiltinClass(JSContext * cx,HandleObject wrapper,ESClassValue * classValue) const154 OpaqueCrossCompartmentWrapper::getBuiltinClass(JSContext* cx, HandleObject wrapper,
155                                                ESClassValue* classValue) const
156 {
157     *classValue = ESClass_Other;
158     return true;
159 }
160 
161 bool
isArray(JSContext * cx,HandleObject obj,JS::IsArrayAnswer * answer) const162 OpaqueCrossCompartmentWrapper::isArray(JSContext* cx, HandleObject obj,
163                                        JS::IsArrayAnswer* answer) const
164 {
165     *answer = JS::IsArrayAnswer::NotArray;
166     return true;
167 }
168 
169 const char*
className(JSContext * cx,HandleObject proxy) const170 OpaqueCrossCompartmentWrapper::className(JSContext* cx,
171                                          HandleObject proxy) const
172 {
173     return "Opaque";
174 }
175 
176 JSString*
fun_toString(JSContext * cx,HandleObject proxy,unsigned indent) const177 OpaqueCrossCompartmentWrapper::fun_toString(JSContext* cx, HandleObject proxy,
178                                             unsigned indent) const
179 {
180     JS_ReportErrorNumber(cx, GetErrorMessage, nullptr, JSMSG_INCOMPATIBLE_PROTO, js_Function_str,
181                          js_toString_str, "object");
182     return nullptr;
183 }
184 
185 const OpaqueCrossCompartmentWrapper OpaqueCrossCompartmentWrapper::singleton;
186