/work/obj-fuzz/dom/bindings/MozStorageStatementRowBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM MozStorageStatementRow.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "MozStorageStatementRowBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/DOMJSClass.h" |
8 | | #include "mozilla/dom/DOMJSProxyHandler.h" |
9 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
10 | | #include "mozilla/dom/XrayExpandoClass.h" |
11 | | #include "mozilla/storage/mozStorageStatementRow.h" |
12 | | #include "nsContentUtils.h" |
13 | | |
14 | | namespace mozilla { |
15 | | namespace dom { |
16 | | |
17 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
18 | | using namespace mozilla::dom::binding_detail; |
19 | | |
20 | | |
21 | | namespace MozStorageStatementRow_Binding { |
22 | | |
23 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
24 | | { |
25 | | "Function", |
26 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
27 | | &sBoringInterfaceObjectClassClassOps, |
28 | | JS_NULL_CLASS_SPEC, |
29 | | JS_NULL_CLASS_EXT, |
30 | | &sInterfaceObjectClassObjectOps |
31 | | }, |
32 | | eInterface, |
33 | | true, |
34 | | prototypes::id::MozStorageStatementRow, |
35 | | PrototypeTraits<prototypes::id::MozStorageStatementRow>::Depth, |
36 | | sNativePropertyHooks, |
37 | | "function MozStorageStatementRow() {\n [native code]\n}", |
38 | | JS::GetRealmFunctionPrototype |
39 | | }; |
40 | | |
41 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
42 | | { |
43 | | "MozStorageStatementRowPrototype", |
44 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
45 | | JS_NULL_CLASS_OPS, |
46 | | JS_NULL_CLASS_SPEC, |
47 | | JS_NULL_CLASS_EXT, |
48 | | JS_NULL_OBJECT_OPS |
49 | | }, |
50 | | eInterfacePrototype, |
51 | | false, |
52 | | prototypes::id::MozStorageStatementRow, |
53 | | PrototypeTraits<prototypes::id::MozStorageStatementRow>::Depth, |
54 | | sNativePropertyHooks, |
55 | | "[object MozStorageStatementRowPrototype]", |
56 | | JS::GetRealmObjectPrototype |
57 | | }; |
58 | | |
59 | | bool |
60 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
61 | 0 | { |
62 | 0 | return nsContentUtils::ThreadsafeIsSystemCaller(aCx); |
63 | 0 | } |
64 | | |
65 | | static_assert(IsBaseOf<nsISupports, mozilla::storage::StatementRow >::value, |
66 | | "We don't support non-nsISupports native classes for " |
67 | | "proxy-based bindings yet"); |
68 | | |
69 | | |
70 | | class DOMProxyHandler : public mozilla::dom::DOMProxyHandler |
71 | | { |
72 | | public: |
73 | | explicit constexpr DOMProxyHandler() |
74 | 0 | { |
75 | 0 | } |
76 | | |
77 | | virtual bool |
78 | | getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override; |
79 | | |
80 | | virtual bool |
81 | | defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override; |
82 | | |
83 | | using mozilla::dom::DOMProxyHandler::defineProperty; |
84 | | |
85 | | virtual bool |
86 | | ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override; |
87 | | |
88 | | virtual bool |
89 | | hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override; |
90 | | |
91 | | virtual bool |
92 | | get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override; |
93 | | |
94 | | virtual const char* |
95 | | className(JSContext* cx, JS::Handle<JSObject*> proxy) const override; |
96 | | |
97 | | virtual bool |
98 | | finalizeInBackground(const JS::Value& priv) const override; |
99 | | |
100 | | virtual void |
101 | | finalize(JSFreeOp* fop, JSObject* proxy) const override; |
102 | | |
103 | | static const DOMProxyHandler* |
104 | | getInstance(); |
105 | | |
106 | | virtual bool |
107 | | delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override; |
108 | | |
109 | | virtual size_t |
110 | | objectMoved(JSObject* obj, JSObject* old) const override; |
111 | | }; |
112 | | |
113 | | MOZ_ALWAYS_INLINE bool |
114 | | IsProxy(JSObject* obj) |
115 | 0 | { |
116 | 0 | return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance(); |
117 | 0 | } |
118 | | |
119 | | MOZ_ALWAYS_INLINE mozilla::storage::StatementRow* |
120 | | UnwrapProxy(JSObject* obj) |
121 | 0 | { |
122 | 0 | MOZ_ASSERT(js::IsProxy(obj)); |
123 | 0 | if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) { |
124 | 0 | MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj)); |
125 | 0 | obj = js::UncheckedUnwrap(obj); |
126 | 0 | } |
127 | 0 | MOZ_ASSERT(IsProxy(obj)); |
128 | 0 | return static_cast<mozilla::storage::StatementRow*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate()); |
129 | 0 | } |
130 | | |
131 | | bool |
132 | | DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const |
133 | 0 | { |
134 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
135 | 0 | JS::Rooted<JSObject*> expando(cx); |
136 | 0 | if (!isXray && (expando = GetExpandoObject(proxy))) { |
137 | 0 | if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) { |
138 | 0 | return false; |
139 | 0 | } |
140 | 0 | if (desc.object()) { |
141 | 0 | // Pretend the property lives on the wrapper. |
142 | 0 | desc.object().set(proxy); |
143 | 0 | return true; |
144 | 0 | } |
145 | 0 | } |
146 | 0 | |
147 | 0 | bool callNamedGetter = false; |
148 | 0 | if (!ignoreNamedProps) { |
149 | 0 | bool hasOnProto; |
150 | 0 | if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { |
151 | 0 | return false; |
152 | 0 | } |
153 | 0 | callNamedGetter = !hasOnProto; |
154 | 0 | } |
155 | 0 | if (callNamedGetter) { |
156 | 0 | FakeString name; |
157 | 0 | bool isSymbol; |
158 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
159 | 0 | return false; |
160 | 0 | } |
161 | 0 | if (!isSymbol) { |
162 | 0 | mozilla::storage::StatementRow* self = UnwrapProxy(proxy); |
163 | 0 | bool found = false; |
164 | 0 | FastErrorResult rv; |
165 | 0 | JS::Rooted<JS::Value> result(cx); |
166 | 0 | self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); |
167 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
168 | 0 | return false; |
169 | 0 | } |
170 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
171 | 0 |
|
172 | 0 | if (found) { |
173 | 0 | JS::ExposeValueToActiveJS(result); |
174 | 0 | desc.value().set(result); |
175 | 0 | if (!MaybeWrapValue(cx, desc.value())) { |
176 | 0 | return false; |
177 | 0 | } |
178 | 0 | FillPropertyDescriptor(desc, proxy, true, true); |
179 | 0 | return true; |
180 | 0 | } |
181 | 0 | } |
182 | 0 | } |
183 | 0 |
|
184 | 0 | desc.object().set(nullptr); |
185 | 0 | return true; |
186 | 0 | } |
187 | | |
188 | | bool |
189 | | DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const |
190 | 0 | { |
191 | 0 | bool found = false; |
192 | 0 | FakeString name; |
193 | 0 | bool isSymbol; |
194 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
195 | 0 | return false; |
196 | 0 | } |
197 | 0 | if (!isSymbol) { |
198 | 0 | mozilla::storage::StatementRow* self = UnwrapProxy(proxy); |
199 | 0 | FastErrorResult rv; |
200 | 0 | JS::Rooted<JS::Value> result(cx); |
201 | 0 | self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); |
202 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
203 | 0 | return false; |
204 | 0 | } |
205 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
206 | 0 | (void)result; |
207 | 0 | } |
208 | 0 |
|
209 | 0 | if (found) { |
210 | 0 | *defined = true; |
211 | 0 | return opresult.failNoNamedSetter(); |
212 | 0 | } |
213 | 0 | return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined); |
214 | 0 | } |
215 | | |
216 | | |
217 | | bool |
218 | | DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const |
219 | 0 | { |
220 | 0 | bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy); |
221 | 0 |
|
222 | 0 | nsTArray<nsString> names; |
223 | 0 | UnwrapProxy(proxy)->GetSupportedNames(names); |
224 | 0 | if (!AppendNamedPropertyIds(cx, proxy, names, false, props)) { |
225 | 0 | return false; |
226 | 0 | } |
227 | 0 | |
228 | 0 | JS::Rooted<JSObject*> expando(cx); |
229 | 0 | if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) && |
230 | 0 | !js::GetPropertyKeys(cx, expando, flags, &props)) { |
231 | 0 | return false; |
232 | 0 | } |
233 | 0 | |
234 | 0 | return true; |
235 | 0 | } |
236 | | |
237 | | bool |
238 | | DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const |
239 | 0 | { |
240 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
241 | 0 | "Should not have a XrayWrapper here"); |
242 | 0 |
|
243 | 0 |
|
244 | 0 | JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy)); |
245 | 0 | if (expando) { |
246 | 0 | bool b = true; |
247 | 0 | bool ok = JS_HasPropertyById(cx, expando, id, &b); |
248 | 0 | *bp = !!b; |
249 | 0 | if (!ok || *bp) { |
250 | 0 | return ok; |
251 | 0 | } |
252 | 0 | } |
253 | 0 | |
254 | 0 | bool hasOnProto; |
255 | 0 | if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { |
256 | 0 | return false; |
257 | 0 | } |
258 | 0 | if (!hasOnProto) { |
259 | 0 | bool found = false; |
260 | 0 | FakeString name; |
261 | 0 | bool isSymbol; |
262 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
263 | 0 | return false; |
264 | 0 | } |
265 | 0 | if (!isSymbol) { |
266 | 0 | mozilla::storage::StatementRow* self = UnwrapProxy(proxy); |
267 | 0 | FastErrorResult rv; |
268 | 0 | JS::Rooted<JS::Value> result(cx); |
269 | 0 | self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); |
270 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
271 | 0 | return false; |
272 | 0 | } |
273 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
274 | 0 | (void)result; |
275 | 0 | } |
276 | 0 |
|
277 | 0 | *bp = found; |
278 | 0 | return true; |
279 | 0 | } |
280 | 0 | *bp = false; |
281 | 0 | return true; |
282 | 0 | } |
283 | | |
284 | | bool |
285 | | DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const |
286 | 0 | { |
287 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
288 | 0 | "Should not have a XrayWrapper here"); |
289 | 0 |
|
290 | 0 | { // Scope for expando |
291 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
292 | 0 | if (expando) { |
293 | 0 | bool hasProp; |
294 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
295 | 0 | return false; |
296 | 0 | } |
297 | 0 | |
298 | 0 | if (hasProp) { |
299 | 0 | // Forward the get to the expando object, but our receiver is whatever our |
300 | 0 | // receiver is. |
301 | 0 | return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp); |
302 | 0 | } |
303 | 0 | } |
304 | 0 | } |
305 | 0 | |
306 | 0 | bool foundOnPrototype; |
307 | 0 | if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) { |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | |
311 | 0 | if (foundOnPrototype) { |
312 | 0 | return true; |
313 | 0 | } |
314 | 0 | |
315 | 0 | FakeString name; |
316 | 0 | bool isSymbol; |
317 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
318 | 0 | return false; |
319 | 0 | } |
320 | 0 | if (!isSymbol) { |
321 | 0 | mozilla::storage::StatementRow* self = UnwrapProxy(proxy); |
322 | 0 | bool found = false; |
323 | 0 | FastErrorResult rv; |
324 | 0 | JS::Rooted<JS::Value> result(cx); |
325 | 0 | self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); |
326 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
327 | 0 | return false; |
328 | 0 | } |
329 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
330 | 0 |
|
331 | 0 | if (found) { |
332 | 0 | JS::ExposeValueToActiveJS(result); |
333 | 0 | vp.set(result); |
334 | 0 | if (!MaybeWrapValue(cx, vp)) { |
335 | 0 | return false; |
336 | 0 | } |
337 | 0 | return true; |
338 | 0 | } |
339 | 0 | } |
340 | 0 |
|
341 | 0 | vp.setUndefined(); |
342 | 0 | return true; |
343 | 0 | } |
344 | | |
345 | | const char* |
346 | | DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const |
347 | 0 | { |
348 | 0 | return "MozStorageStatementRow"; |
349 | 0 | } |
350 | | |
351 | | bool |
352 | | DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const |
353 | 0 | { |
354 | 0 | return false; |
355 | 0 | } |
356 | | |
357 | | void |
358 | | DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const |
359 | 0 | { |
360 | 0 | mozilla::storage::StatementRow* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::storage::StatementRow>(proxy); |
361 | 0 | if (self) { |
362 | 0 | ClearWrapper(self, self, proxy); |
363 | 0 | AddForDeferredFinalization<mozilla::storage::StatementRow>(self); |
364 | 0 | } |
365 | 0 | } |
366 | | |
367 | | const DOMProxyHandler* |
368 | | DOMProxyHandler::getInstance() |
369 | 0 | { |
370 | 0 | static const DOMProxyHandler instance; |
371 | 0 | return &instance; |
372 | 0 | } |
373 | | |
374 | | bool |
375 | | DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const |
376 | 0 | { |
377 | 0 | MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy), |
378 | 0 | "Should not have a XrayWrapper here"); |
379 | 0 |
|
380 | 0 | // Try named delete only if the named property visibility |
381 | 0 | // algorithm says the property is visible. |
382 | 0 | bool tryNamedDelete = true; |
383 | 0 | { // Scope for expando |
384 | 0 | JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy)); |
385 | 0 | if (expando) { |
386 | 0 | bool hasProp; |
387 | 0 | if (!JS_HasPropertyById(cx, expando, id, &hasProp)) { |
388 | 0 | return false; |
389 | 0 | } |
390 | 0 | tryNamedDelete = !hasProp; |
391 | 0 | } |
392 | 0 | } |
393 | 0 | if (tryNamedDelete) { |
394 | 0 | bool hasOnProto; |
395 | 0 | if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) { |
396 | 0 | return false; |
397 | 0 | } |
398 | 0 | tryNamedDelete = !hasOnProto; |
399 | 0 | } |
400 | 0 | if (tryNamedDelete) { |
401 | 0 | bool found = false; |
402 | 0 | bool deleteSucceeded; |
403 | 0 | FakeString name; |
404 | 0 | bool isSymbol; |
405 | 0 | if (!ConvertIdToString(cx, id, name, isSymbol)) { |
406 | 0 | return false; |
407 | 0 | } |
408 | 0 | if (!isSymbol) { |
409 | 0 | mozilla::storage::StatementRow* self = UnwrapProxy(proxy); |
410 | 0 | FastErrorResult rv; |
411 | 0 | JS::Rooted<JS::Value> result(cx); |
412 | 0 | self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv); |
413 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
414 | 0 | return false; |
415 | 0 | } |
416 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
417 | 0 | (void)result; |
418 | 0 | } |
419 | 0 | deleteSucceeded = !found; |
420 | 0 | if (found) { |
421 | 0 | return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete(); |
422 | 0 | } |
423 | 0 | } |
424 | 0 |
|
425 | 0 | return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult); |
426 | 0 | } |
427 | | |
428 | | size_t |
429 | | DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const |
430 | 0 | { |
431 | 0 | mozilla::storage::StatementRow* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::storage::StatementRow>(obj); |
432 | 0 | if (self) { |
433 | 0 | UpdateWrapper(self, self, obj, old); |
434 | 0 | } |
435 | 0 |
|
436 | 0 | return 0; |
437 | 0 | } |
438 | | |
439 | | static const DOMJSClass sClass = { |
440 | | PROXY_CLASS_DEF("MozStorageStatementRow", |
441 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)), |
442 | | { prototypes::id::MozStorageStatementRow, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
443 | | IsBaseOf<nsISupports, mozilla::storage::StatementRow >::value, |
444 | | sNativePropertyHooks, |
445 | | FindAssociatedGlobalForNative<mozilla::storage::StatementRow>::Get, |
446 | | GetProtoObjectHandle, |
447 | | GetCCParticipant<mozilla::storage::StatementRow>::Get() |
448 | | }; |
449 | | |
450 | | bool |
451 | | Wrap(JSContext* aCx, mozilla::storage::StatementRow* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
452 | 0 | { |
453 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::storage::StatementRow>::value, |
454 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
455 | 0 | MOZ_ASSERT(static_cast<mozilla::storage::StatementRow*>(aObject) == |
456 | 0 | reinterpret_cast<mozilla::storage::StatementRow*>(aObject), |
457 | 0 | "Multiple inheritance for mozilla::storage::StatementRow is broken."); |
458 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
459 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
460 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
461 | 0 | "You should probably not be using Wrap() directly; use " |
462 | 0 | "GetOrCreateDOMReflector instead"); |
463 | 0 |
|
464 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
465 | 0 | "nsISupports must be on our primary inheritance chain"); |
466 | 0 |
|
467 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
468 | 0 | if (!global) { |
469 | 0 | return false; |
470 | 0 | } |
471 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
472 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
473 | 0 |
|
474 | 0 | // That might have ended up wrapping us already, due to the wonders |
475 | 0 | // of XBL. Check for that, and bail out as needed. |
476 | 0 | aReflector.set(aCache->GetWrapper()); |
477 | 0 | if (aReflector) { |
478 | | #ifdef DEBUG |
479 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
480 | | #endif // DEBUG |
481 | | return true; |
482 | 0 | } |
483 | 0 |
|
484 | 0 | JSAutoRealm ar(aCx, global); |
485 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
486 | 0 | if (!canonicalProto) { |
487 | 0 | return false; |
488 | 0 | } |
489 | 0 | JS::Rooted<JSObject*> proto(aCx); |
490 | 0 | if (aGivenProto) { |
491 | 0 | proto = aGivenProto; |
492 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
493 | 0 | // coming in, we changed compartments to that of "parent" so may need |
494 | 0 | // to wrap the proto here. |
495 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
496 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
497 | 0 | return false; |
498 | 0 | } |
499 | 0 | } |
500 | 0 | } else { |
501 | 0 | proto = canonicalProto; |
502 | 0 | } |
503 | 0 |
|
504 | 0 | BindingJSObjectCreator<mozilla::storage::StatementRow> creator(aCx); |
505 | 0 | creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(), |
506 | 0 | proto, aObject, JS::UndefinedHandleValue, aReflector); |
507 | 0 | if (!aReflector) { |
508 | 0 | return false; |
509 | 0 | } |
510 | 0 | |
511 | 0 | aCache->SetWrapper(aReflector); |
512 | 0 | creator.InitializationSucceeded(); |
513 | 0 |
|
514 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
515 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
516 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
517 | 0 | // otherwise we won't be able to properly recreate it later, since |
518 | 0 | // we won't know what proto to use. Note that we don't check |
519 | 0 | // aGivenProto here, since it's entirely possible (and even |
520 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
521 | 0 | // same as canonicalProto. |
522 | 0 | if (proto != canonicalProto) { |
523 | 0 | PreserveWrapper(aObject); |
524 | 0 | } |
525 | 0 |
|
526 | 0 | return true; |
527 | 0 | } |
528 | | |
529 | | static bool |
530 | | ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc) |
531 | 0 | { |
532 | 0 | return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc); |
533 | 0 | } |
534 | | |
535 | | static bool |
536 | | EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props) |
537 | 0 | { |
538 | 0 | return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props); |
539 | 0 | } |
540 | | |
541 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
542 | | ResolveOwnProperty, |
543 | | EnumerateOwnProperties, |
544 | | nullptr, |
545 | | { nullptr, nullptr }, |
546 | | prototypes::id::MozStorageStatementRow, |
547 | | constructors::id::MozStorageStatementRow, |
548 | | nullptr, |
549 | | &DefaultXrayExpandoObjectClass |
550 | | } }; |
551 | | |
552 | | void |
553 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
554 | 0 | { |
555 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
556 | 0 | if (!parentProto) { |
557 | 0 | return; |
558 | 0 | } |
559 | 0 | |
560 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
561 | 0 | if (!constructorProto) { |
562 | 0 | return; |
563 | 0 | } |
564 | 0 | |
565 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MozStorageStatementRow); |
566 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MozStorageStatementRow); |
567 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
568 | 0 | &sPrototypeClass.mBase, protoCache, |
569 | 0 | nullptr, |
570 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
571 | 0 | interfaceCache, |
572 | 0 | nullptr, |
573 | 0 | nullptr, |
574 | 0 | "MozStorageStatementRow", aDefineOnGlobal, |
575 | 0 | nullptr, |
576 | 0 | false); |
577 | 0 | } |
578 | | |
579 | | JSObject* |
580 | | GetConstructorObject(JSContext* aCx) |
581 | 0 | { |
582 | 0 | return GetConstructorObjectHandle(aCx); |
583 | 0 | } |
584 | | |
585 | | } // namespace MozStorageStatementRow_Binding |
586 | | |
587 | | |
588 | | |
589 | | } // namespace dom |
590 | | } // namespace mozilla |