/work/obj-fuzz/dom/bindings/IDBRequestBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM IDBRequest.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "IDBRequestBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "jsapi.h" |
8 | | #include "mozilla/OwningNonNull.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMException.h" |
11 | | #include "mozilla/dom/DOMJSClass.h" |
12 | | #include "mozilla/dom/IDBCursor.h" |
13 | | #include "mozilla/dom/IDBIndex.h" |
14 | | #include "mozilla/dom/IDBObjectStore.h" |
15 | | #include "mozilla/dom/IDBRequest.h" |
16 | | #include "mozilla/dom/IDBTransaction.h" |
17 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
18 | | #include "mozilla/dom/Nullable.h" |
19 | | #include "mozilla/dom/UnionConversions.h" |
20 | | #include "mozilla/dom/XrayExpandoClass.h" |
21 | | |
22 | | namespace mozilla { |
23 | | namespace dom { |
24 | | |
25 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
26 | | using namespace mozilla::dom::binding_detail; |
27 | | |
28 | | |
29 | | namespace IDBRequestReadyStateValues { |
30 | | extern const EnumEntry strings[3] = { |
31 | | {"pending", 7}, |
32 | | {"done", 4}, |
33 | | { nullptr, 0 } |
34 | | }; |
35 | | } // namespace IDBRequestReadyStateValues |
36 | | |
37 | | bool |
38 | | ToJSValue(JSContext* aCx, IDBRequestReadyState aArgument, JS::MutableHandle<JS::Value> aValue) |
39 | 0 | { |
40 | 0 | MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(IDBRequestReadyStateValues::strings)); |
41 | 0 | JSString* resultStr = |
42 | 0 | JS_NewStringCopyN(aCx, IDBRequestReadyStateValues::strings[uint32_t(aArgument)].value, |
43 | 0 | IDBRequestReadyStateValues::strings[uint32_t(aArgument)].length); |
44 | 0 | if (!resultStr) { |
45 | 0 | return false; |
46 | 0 | } |
47 | 0 | aValue.setString(resultStr); |
48 | 0 | return true; |
49 | 0 | } |
50 | | |
51 | | |
52 | | void |
53 | | ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningIDBObjectStoreOrIDBIndexOrIDBCursor& aUnion, const char* aName, uint32_t aFlags) |
54 | 0 | { |
55 | 0 | if (aUnion.IsIDBObjectStore()) { |
56 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsIDBObjectStore(), "mIDBObjectStore", aFlags); |
57 | 0 | } else if (aUnion.IsIDBIndex()) { |
58 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsIDBIndex(), "mIDBIndex", aFlags); |
59 | 0 | } else if (aUnion.IsIDBCursor()) { |
60 | 0 | ImplCycleCollectionTraverse(aCallback, aUnion.GetAsIDBCursor(), "mIDBCursor", aFlags); |
61 | 0 | } |
62 | 0 | } |
63 | | |
64 | | |
65 | | void |
66 | | ImplCycleCollectionUnlink(OwningIDBObjectStoreOrIDBIndexOrIDBCursor& aUnion) |
67 | 0 | { |
68 | 0 | aUnion.Uninit(); |
69 | 0 | } |
70 | | |
71 | | |
72 | | bool |
73 | | IDBObjectStoreOrIDBIndexOrIDBCursor::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
74 | 0 | { |
75 | 0 | switch (mType) { |
76 | 0 | case eUninitialized: { |
77 | 0 | return false; |
78 | 0 | break; |
79 | 0 | } |
80 | 0 | case eIDBObjectStore: { |
81 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mIDBObjectStore.Value(), rval)) { |
82 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
83 | 0 | return false; |
84 | 0 | } |
85 | 0 | return true; |
86 | 0 | break; |
87 | 0 | } |
88 | 0 | case eIDBIndex: { |
89 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mIDBIndex.Value(), rval)) { |
90 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
91 | 0 | return false; |
92 | 0 | } |
93 | 0 | return true; |
94 | 0 | break; |
95 | 0 | } |
96 | 0 | case eIDBCursor: { |
97 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mIDBCursor.Value(), rval)) { |
98 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
99 | 0 | return false; |
100 | 0 | } |
101 | 0 | return true; |
102 | 0 | break; |
103 | 0 | } |
104 | 0 | default: { |
105 | 0 | return false; |
106 | 0 | break; |
107 | 0 | } |
108 | 0 | } |
109 | 0 | |
110 | 0 | return false; |
111 | 0 | } |
112 | | |
113 | | |
114 | | OwningNonNull<mozilla::dom::IDBObjectStore>& |
115 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::RawSetAsIDBObjectStore() |
116 | 0 | { |
117 | 0 | if (mType == eIDBObjectStore) { |
118 | 0 | return mValue.mIDBObjectStore.Value(); |
119 | 0 | } |
120 | 0 | MOZ_ASSERT(mType == eUninitialized); |
121 | 0 | mType = eIDBObjectStore; |
122 | 0 | return mValue.mIDBObjectStore.SetValue(); |
123 | 0 | } |
124 | | |
125 | | OwningNonNull<mozilla::dom::IDBObjectStore>& |
126 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::SetAsIDBObjectStore() |
127 | 0 | { |
128 | 0 | if (mType == eIDBObjectStore) { |
129 | 0 | return mValue.mIDBObjectStore.Value(); |
130 | 0 | } |
131 | 0 | Uninit(); |
132 | 0 | mType = eIDBObjectStore; |
133 | 0 | return mValue.mIDBObjectStore.SetValue(); |
134 | 0 | } |
135 | | |
136 | | bool |
137 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::TrySetToIDBObjectStore(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
138 | 0 | { |
139 | 0 | tryNext = false; |
140 | 0 | { // scope for memberSlot |
141 | 0 | OwningNonNull<mozilla::dom::IDBObjectStore>& memberSlot = RawSetAsIDBObjectStore(); |
142 | 0 | static_assert(IsRefcounted<mozilla::dom::IDBObjectStore>::value, "We can only store refcounted classes.");{ |
143 | 0 | nsresult rv = UnwrapObject<prototypes::id::IDBObjectStore, mozilla::dom::IDBObjectStore>(value, memberSlot); |
144 | 0 | if (NS_FAILED(rv)) { |
145 | 0 | DestroyIDBObjectStore(); |
146 | 0 | tryNext = true; |
147 | 0 | return true; |
148 | 0 | } |
149 | 0 | } |
150 | 0 | } |
151 | 0 | return true; |
152 | 0 | } |
153 | | |
154 | | void |
155 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::DestroyIDBObjectStore() |
156 | 0 | { |
157 | 0 | MOZ_ASSERT(IsIDBObjectStore(), "Wrong type!"); |
158 | 0 | mValue.mIDBObjectStore.Destroy(); |
159 | 0 | mType = eUninitialized; |
160 | 0 | } |
161 | | |
162 | | |
163 | | |
164 | | |
165 | | OwningNonNull<mozilla::dom::IDBIndex>& |
166 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::RawSetAsIDBIndex() |
167 | 0 | { |
168 | 0 | if (mType == eIDBIndex) { |
169 | 0 | return mValue.mIDBIndex.Value(); |
170 | 0 | } |
171 | 0 | MOZ_ASSERT(mType == eUninitialized); |
172 | 0 | mType = eIDBIndex; |
173 | 0 | return mValue.mIDBIndex.SetValue(); |
174 | 0 | } |
175 | | |
176 | | OwningNonNull<mozilla::dom::IDBIndex>& |
177 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::SetAsIDBIndex() |
178 | 0 | { |
179 | 0 | if (mType == eIDBIndex) { |
180 | 0 | return mValue.mIDBIndex.Value(); |
181 | 0 | } |
182 | 0 | Uninit(); |
183 | 0 | mType = eIDBIndex; |
184 | 0 | return mValue.mIDBIndex.SetValue(); |
185 | 0 | } |
186 | | |
187 | | bool |
188 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::TrySetToIDBIndex(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
189 | 0 | { |
190 | 0 | tryNext = false; |
191 | 0 | { // scope for memberSlot |
192 | 0 | OwningNonNull<mozilla::dom::IDBIndex>& memberSlot = RawSetAsIDBIndex(); |
193 | 0 | static_assert(IsRefcounted<mozilla::dom::IDBIndex>::value, "We can only store refcounted classes.");{ |
194 | 0 | nsresult rv = UnwrapObject<prototypes::id::IDBIndex, mozilla::dom::IDBIndex>(value, memberSlot); |
195 | 0 | if (NS_FAILED(rv)) { |
196 | 0 | DestroyIDBIndex(); |
197 | 0 | tryNext = true; |
198 | 0 | return true; |
199 | 0 | } |
200 | 0 | } |
201 | 0 | } |
202 | 0 | return true; |
203 | 0 | } |
204 | | |
205 | | void |
206 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::DestroyIDBIndex() |
207 | 0 | { |
208 | 0 | MOZ_ASSERT(IsIDBIndex(), "Wrong type!"); |
209 | 0 | mValue.mIDBIndex.Destroy(); |
210 | 0 | mType = eUninitialized; |
211 | 0 | } |
212 | | |
213 | | |
214 | | |
215 | | |
216 | | OwningNonNull<mozilla::dom::IDBCursor>& |
217 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::RawSetAsIDBCursor() |
218 | 0 | { |
219 | 0 | if (mType == eIDBCursor) { |
220 | 0 | return mValue.mIDBCursor.Value(); |
221 | 0 | } |
222 | 0 | MOZ_ASSERT(mType == eUninitialized); |
223 | 0 | mType = eIDBCursor; |
224 | 0 | return mValue.mIDBCursor.SetValue(); |
225 | 0 | } |
226 | | |
227 | | OwningNonNull<mozilla::dom::IDBCursor>& |
228 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::SetAsIDBCursor() |
229 | 0 | { |
230 | 0 | if (mType == eIDBCursor) { |
231 | 0 | return mValue.mIDBCursor.Value(); |
232 | 0 | } |
233 | 0 | Uninit(); |
234 | 0 | mType = eIDBCursor; |
235 | 0 | return mValue.mIDBCursor.SetValue(); |
236 | 0 | } |
237 | | |
238 | | bool |
239 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::TrySetToIDBCursor(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl) |
240 | 0 | { |
241 | 0 | tryNext = false; |
242 | 0 | { // scope for memberSlot |
243 | 0 | OwningNonNull<mozilla::dom::IDBCursor>& memberSlot = RawSetAsIDBCursor(); |
244 | 0 | static_assert(IsRefcounted<mozilla::dom::IDBCursor>::value, "We can only store refcounted classes.");{ |
245 | 0 | nsresult rv = UnwrapObject<prototypes::id::IDBCursor, mozilla::dom::IDBCursor>(value, memberSlot); |
246 | 0 | if (NS_FAILED(rv)) { |
247 | 0 | DestroyIDBCursor(); |
248 | 0 | tryNext = true; |
249 | 0 | return true; |
250 | 0 | } |
251 | 0 | } |
252 | 0 | } |
253 | 0 | return true; |
254 | 0 | } |
255 | | |
256 | | void |
257 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::DestroyIDBCursor() |
258 | 0 | { |
259 | 0 | MOZ_ASSERT(IsIDBCursor(), "Wrong type!"); |
260 | 0 | mValue.mIDBCursor.Destroy(); |
261 | 0 | mType = eUninitialized; |
262 | 0 | } |
263 | | |
264 | | |
265 | | |
266 | | |
267 | | void |
268 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::Uninit() |
269 | | { |
270 | | switch (mType) { |
271 | | case eUninitialized: { |
272 | | break; |
273 | | } |
274 | | case eIDBObjectStore: { |
275 | | DestroyIDBObjectStore(); |
276 | | break; |
277 | | } |
278 | | case eIDBIndex: { |
279 | | DestroyIDBIndex(); |
280 | | break; |
281 | | } |
282 | | case eIDBCursor: { |
283 | | DestroyIDBCursor(); |
284 | | break; |
285 | | } |
286 | | } |
287 | | } |
288 | | |
289 | | bool |
290 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const |
291 | 0 | { |
292 | 0 | switch (mType) { |
293 | 0 | case eUninitialized: { |
294 | 0 | return false; |
295 | 0 | break; |
296 | 0 | } |
297 | 0 | case eIDBObjectStore: { |
298 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mIDBObjectStore.Value(), rval)) { |
299 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
300 | 0 | return false; |
301 | 0 | } |
302 | 0 | return true; |
303 | 0 | break; |
304 | 0 | } |
305 | 0 | case eIDBIndex: { |
306 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mIDBIndex.Value(), rval)) { |
307 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
308 | 0 | return false; |
309 | 0 | } |
310 | 0 | return true; |
311 | 0 | break; |
312 | 0 | } |
313 | 0 | case eIDBCursor: { |
314 | 0 | if (!GetOrCreateDOMReflector(cx, mValue.mIDBCursor.Value(), rval)) { |
315 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
316 | 0 | return false; |
317 | 0 | } |
318 | 0 | return true; |
319 | 0 | break; |
320 | 0 | } |
321 | 0 | default: { |
322 | 0 | return false; |
323 | 0 | break; |
324 | 0 | } |
325 | 0 | } |
326 | 0 | |
327 | 0 | return false; |
328 | 0 | } |
329 | | |
330 | | void |
331 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::TraceUnion(JSTracer* trc) |
332 | 0 | { |
333 | 0 | } |
334 | | |
335 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor& |
336 | | OwningIDBObjectStoreOrIDBIndexOrIDBCursor::operator=(const OwningIDBObjectStoreOrIDBIndexOrIDBCursor& aOther) |
337 | 0 | { |
338 | 0 | switch (aOther.mType) { |
339 | 0 | case eUninitialized: { |
340 | 0 | MOZ_ASSERT(mType == eUninitialized, |
341 | 0 | "We need to destroy ourselves?"); |
342 | 0 | break; |
343 | 0 | } |
344 | 0 | case eIDBObjectStore: { |
345 | 0 | SetAsIDBObjectStore() = aOther.GetAsIDBObjectStore(); |
346 | 0 | break; |
347 | 0 | } |
348 | 0 | case eIDBIndex: { |
349 | 0 | SetAsIDBIndex() = aOther.GetAsIDBIndex(); |
350 | 0 | break; |
351 | 0 | } |
352 | 0 | case eIDBCursor: { |
353 | 0 | SetAsIDBCursor() = aOther.GetAsIDBCursor(); |
354 | 0 | break; |
355 | 0 | } |
356 | 0 | } |
357 | 0 | return *this; |
358 | 0 | } |
359 | | |
360 | | |
361 | | namespace IDBRequest_Binding { |
362 | | |
363 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
364 | | "Can't inherit from an interface with a different ownership model."); |
365 | | |
366 | | MOZ_CAN_RUN_SCRIPT static bool |
367 | | get_result(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitGetterCallArgs args) |
368 | 0 | { |
369 | 0 | AUTO_PROFILER_LABEL_FAST("get IDBRequest.result", DOM, cx); |
370 | 0 |
|
371 | 0 | FastErrorResult rv; |
372 | 0 | JS::Rooted<JS::Value> result(cx); |
373 | 0 | self->GetResult(cx, &result, rv); |
374 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
375 | 0 | return false; |
376 | 0 | } |
377 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
378 | 0 | JS::ExposeValueToActiveJS(result); |
379 | 0 | args.rval().set(result); |
380 | 0 | if (!MaybeWrapValue(cx, args.rval())) { |
381 | 0 | return false; |
382 | 0 | } |
383 | 0 | return true; |
384 | 0 | } |
385 | | |
386 | | static const JSJitInfo result_getterinfo = { |
387 | | { (JSJitGetterOp)get_result }, |
388 | | { prototypes::id::IDBRequest }, |
389 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
390 | | JSJitInfo::Getter, |
391 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
392 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
393 | | false, /* isInfallible. False in setters. */ |
394 | | false, /* isMovable. Not relevant for setters. */ |
395 | | false, /* isEliminatable. Not relevant for setters. */ |
396 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
397 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
398 | | false, /* isTypedMethod. Only relevant for methods. */ |
399 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
400 | | }; |
401 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
402 | | static_assert(0 < 1, "There is no slot for us"); |
403 | | |
404 | | MOZ_CAN_RUN_SCRIPT static bool |
405 | | get_error(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitGetterCallArgs args) |
406 | 0 | { |
407 | 0 | AUTO_PROFILER_LABEL_FAST("get IDBRequest.error", DOM, cx); |
408 | 0 |
|
409 | 0 | FastErrorResult rv; |
410 | 0 | auto result(StrongOrRawPtr<mozilla::dom::DOMException>(self->GetError(rv))); |
411 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
412 | 0 | return false; |
413 | 0 | } |
414 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
415 | 0 | if (!result) { |
416 | 0 | args.rval().setNull(); |
417 | 0 | return true; |
418 | 0 | } |
419 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
420 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
421 | 0 | return false; |
422 | 0 | } |
423 | 0 | return true; |
424 | 0 | } |
425 | | |
426 | | static const JSJitInfo error_getterinfo = { |
427 | | { (JSJitGetterOp)get_error }, |
428 | | { prototypes::id::IDBRequest }, |
429 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
430 | | JSJitInfo::Getter, |
431 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
432 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
433 | | false, /* isInfallible. False in setters. */ |
434 | | false, /* isMovable. Not relevant for setters. */ |
435 | | false, /* isEliminatable. Not relevant for setters. */ |
436 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
437 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
438 | | false, /* isTypedMethod. Only relevant for methods. */ |
439 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
440 | | }; |
441 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
442 | | static_assert(0 < 1, "There is no slot for us"); |
443 | | |
444 | | MOZ_CAN_RUN_SCRIPT static bool |
445 | | get_source(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitGetterCallArgs args) |
446 | 0 | { |
447 | 0 | AUTO_PROFILER_LABEL_FAST("get IDBRequest.source", DOM, cx); |
448 | 0 |
|
449 | 0 | Nullable<OwningIDBObjectStoreOrIDBIndexOrIDBCursor> result; |
450 | 0 | self->GetSource(result); |
451 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
452 | 0 | if (result.IsNull()) { |
453 | 0 | args.rval().setNull(); |
454 | 0 | return true; |
455 | 0 | } |
456 | 0 | if (!result.Value().ToJSVal(cx, obj, args.rval())) { |
457 | 0 | return false; |
458 | 0 | } |
459 | 0 | return true; |
460 | 0 | } |
461 | | |
462 | | static const JSJitInfo source_getterinfo = { |
463 | | { (JSJitGetterOp)get_source }, |
464 | | { prototypes::id::IDBRequest }, |
465 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
466 | | JSJitInfo::Getter, |
467 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
468 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
469 | | false, /* isInfallible. False in setters. */ |
470 | | false, /* isMovable. Not relevant for setters. */ |
471 | | false, /* isEliminatable. Not relevant for setters. */ |
472 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
473 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
474 | | false, /* isTypedMethod. Only relevant for methods. */ |
475 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
476 | | }; |
477 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
478 | | static_assert(0 < 1, "There is no slot for us"); |
479 | | |
480 | | MOZ_CAN_RUN_SCRIPT static bool |
481 | | get_transaction(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitGetterCallArgs args) |
482 | 0 | { |
483 | 0 | AUTO_PROFILER_LABEL_FAST("get IDBRequest.transaction", DOM, cx); |
484 | 0 |
|
485 | 0 | auto result(StrongOrRawPtr<mozilla::dom::IDBTransaction>(self->GetTransaction())); |
486 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
487 | 0 | if (!result) { |
488 | 0 | args.rval().setNull(); |
489 | 0 | return true; |
490 | 0 | } |
491 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
492 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
493 | 0 | return false; |
494 | 0 | } |
495 | 0 | return true; |
496 | 0 | } |
497 | | |
498 | | static const JSJitInfo transaction_getterinfo = { |
499 | | { (JSJitGetterOp)get_transaction }, |
500 | | { prototypes::id::IDBRequest }, |
501 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
502 | | JSJitInfo::Getter, |
503 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
504 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
505 | | false, /* isInfallible. False in setters. */ |
506 | | false, /* isMovable. Not relevant for setters. */ |
507 | | false, /* isEliminatable. Not relevant for setters. */ |
508 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
509 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
510 | | false, /* isTypedMethod. Only relevant for methods. */ |
511 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
512 | | }; |
513 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
514 | | static_assert(0 < 1, "There is no slot for us"); |
515 | | |
516 | | MOZ_CAN_RUN_SCRIPT static bool |
517 | | get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitGetterCallArgs args) |
518 | 0 | { |
519 | 0 | AUTO_PROFILER_LABEL_FAST("get IDBRequest.readyState", DOM, cx); |
520 | 0 |
|
521 | 0 | IDBRequestReadyState result(self->ReadyState()); |
522 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
523 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
524 | 0 | return false; |
525 | 0 | } |
526 | 0 | return true; |
527 | 0 | } |
528 | | |
529 | | static const JSJitInfo readyState_getterinfo = { |
530 | | { (JSJitGetterOp)get_readyState }, |
531 | | { prototypes::id::IDBRequest }, |
532 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
533 | | JSJitInfo::Getter, |
534 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
535 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
536 | | false, /* isInfallible. False in setters. */ |
537 | | false, /* isMovable. Not relevant for setters. */ |
538 | | false, /* isEliminatable. Not relevant for setters. */ |
539 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
540 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
541 | | false, /* isTypedMethod. Only relevant for methods. */ |
542 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
543 | | }; |
544 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
545 | | static_assert(0 < 1, "There is no slot for us"); |
546 | | |
547 | | MOZ_CAN_RUN_SCRIPT static bool |
548 | | get_onsuccess(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitGetterCallArgs args) |
549 | 0 | { |
550 | 0 | AUTO_PROFILER_LABEL_FAST("get IDBRequest.onsuccess", DOM, cx); |
551 | 0 |
|
552 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnsuccess()); |
553 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
554 | 0 | if (result) { |
555 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
556 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
557 | 0 | return false; |
558 | 0 | } |
559 | 0 | return true; |
560 | 0 | } else { |
561 | 0 | args.rval().setNull(); |
562 | 0 | return true; |
563 | 0 | } |
564 | 0 | } |
565 | | |
566 | | MOZ_CAN_RUN_SCRIPT static bool |
567 | | set_onsuccess(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitSetterCallArgs args) |
568 | 0 | { |
569 | 0 | AUTO_PROFILER_LABEL_FAST("set IDBRequest.onsuccess", DOM, cx); |
570 | 0 |
|
571 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
572 | 0 | if (args[0].isObject()) { |
573 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
574 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
575 | 0 | } |
576 | 0 | } else { |
577 | 0 | arg0 = nullptr; |
578 | 0 | } |
579 | 0 | self->SetOnsuccess(Constify(arg0)); |
580 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
581 | 0 |
|
582 | 0 | return true; |
583 | 0 | } |
584 | | |
585 | | static const JSJitInfo onsuccess_getterinfo = { |
586 | | { (JSJitGetterOp)get_onsuccess }, |
587 | | { prototypes::id::IDBRequest }, |
588 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
589 | | JSJitInfo::Getter, |
590 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
591 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
592 | | false, /* isInfallible. False in setters. */ |
593 | | false, /* isMovable. Not relevant for setters. */ |
594 | | false, /* isEliminatable. Not relevant for setters. */ |
595 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
596 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
597 | | false, /* isTypedMethod. Only relevant for methods. */ |
598 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
599 | | }; |
600 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
601 | | static_assert(0 < 1, "There is no slot for us"); |
602 | | static const JSJitInfo onsuccess_setterinfo = { |
603 | | { (JSJitGetterOp)set_onsuccess }, |
604 | | { prototypes::id::IDBRequest }, |
605 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
606 | | JSJitInfo::Setter, |
607 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
608 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
609 | | false, /* isInfallible. False in setters. */ |
610 | | false, /* isMovable. Not relevant for setters. */ |
611 | | false, /* isEliminatable. Not relevant for setters. */ |
612 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
613 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
614 | | false, /* isTypedMethod. Only relevant for methods. */ |
615 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
616 | | }; |
617 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
618 | | static_assert(0 < 1, "There is no slot for us"); |
619 | | |
620 | | MOZ_CAN_RUN_SCRIPT static bool |
621 | | get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitGetterCallArgs args) |
622 | 0 | { |
623 | 0 | AUTO_PROFILER_LABEL_FAST("get IDBRequest.onerror", DOM, cx); |
624 | 0 |
|
625 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnerror()); |
626 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
627 | 0 | if (result) { |
628 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
629 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
630 | 0 | return false; |
631 | 0 | } |
632 | 0 | return true; |
633 | 0 | } else { |
634 | 0 | args.rval().setNull(); |
635 | 0 | return true; |
636 | 0 | } |
637 | 0 | } |
638 | | |
639 | | MOZ_CAN_RUN_SCRIPT static bool |
640 | | set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBRequest* self, JSJitSetterCallArgs args) |
641 | 0 | { |
642 | 0 | AUTO_PROFILER_LABEL_FAST("set IDBRequest.onerror", DOM, cx); |
643 | 0 |
|
644 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
645 | 0 | if (args[0].isObject()) { |
646 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
647 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
648 | 0 | } |
649 | 0 | } else { |
650 | 0 | arg0 = nullptr; |
651 | 0 | } |
652 | 0 | self->SetOnerror(Constify(arg0)); |
653 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
654 | 0 |
|
655 | 0 | return true; |
656 | 0 | } |
657 | | |
658 | | static const JSJitInfo onerror_getterinfo = { |
659 | | { (JSJitGetterOp)get_onerror }, |
660 | | { prototypes::id::IDBRequest }, |
661 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
662 | | JSJitInfo::Getter, |
663 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
664 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
665 | | false, /* isInfallible. False in setters. */ |
666 | | false, /* isMovable. Not relevant for setters. */ |
667 | | false, /* isEliminatable. Not relevant for setters. */ |
668 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
669 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
670 | | false, /* isTypedMethod. Only relevant for methods. */ |
671 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
672 | | }; |
673 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
674 | | static_assert(0 < 1, "There is no slot for us"); |
675 | | static const JSJitInfo onerror_setterinfo = { |
676 | | { (JSJitGetterOp)set_onerror }, |
677 | | { prototypes::id::IDBRequest }, |
678 | | { PrototypeTraits<prototypes::id::IDBRequest>::Depth }, |
679 | | JSJitInfo::Setter, |
680 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
681 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
682 | | false, /* isInfallible. False in setters. */ |
683 | | false, /* isMovable. Not relevant for setters. */ |
684 | | false, /* isEliminatable. Not relevant for setters. */ |
685 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
686 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
687 | | false, /* isTypedMethod. Only relevant for methods. */ |
688 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
689 | | }; |
690 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
691 | | static_assert(0 < 1, "There is no slot for us"); |
692 | | |
693 | | static bool |
694 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
695 | 0 | { |
696 | 0 | mozilla::dom::IDBRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBRequest>(obj); |
697 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
698 | 0 | // obviously can't preserve if we're not initialized. |
699 | 0 | if (self && self->GetWrapperPreserveColor()) { |
700 | 0 | PreserveWrapper(self); |
701 | 0 | } |
702 | 0 | return true; |
703 | 0 | } |
704 | | |
705 | | static void |
706 | | _finalize(js::FreeOp* fop, JSObject* obj) |
707 | 0 | { |
708 | 0 | mozilla::dom::IDBRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBRequest>(obj); |
709 | 0 | if (self) { |
710 | 0 | ClearWrapper(self, self, obj); |
711 | 0 | AddForDeferredFinalization<mozilla::dom::IDBRequest>(self); |
712 | 0 | } |
713 | 0 | } |
714 | | |
715 | | static size_t |
716 | | _objectMoved(JSObject* obj, JSObject* old) |
717 | 0 | { |
718 | 0 | mozilla::dom::IDBRequest* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBRequest>(obj); |
719 | 0 | if (self) { |
720 | 0 | UpdateWrapper(self, self, obj, old); |
721 | 0 | } |
722 | 0 |
|
723 | 0 | return 0; |
724 | 0 | } |
725 | | |
726 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
727 | | #if defined(__clang__) |
728 | | #pragma clang diagnostic push |
729 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
730 | | #endif |
731 | | static const JSPropertySpec sAttributes_specs[] = { |
732 | | { "result", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &result_getterinfo, nullptr, nullptr }, |
733 | | { "error", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &error_getterinfo, nullptr, nullptr }, |
734 | | { "source", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &source_getterinfo, nullptr, nullptr }, |
735 | | { "transaction", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &transaction_getterinfo, nullptr, nullptr }, |
736 | | { "readyState", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &readyState_getterinfo, nullptr, nullptr }, |
737 | | { "onsuccess", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onsuccess_getterinfo, GenericSetter<NormalThisPolicy>, &onsuccess_setterinfo }, |
738 | | { "onerror", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onerror_getterinfo, GenericSetter<NormalThisPolicy>, &onerror_setterinfo }, |
739 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
740 | | }; |
741 | | #if defined(__clang__) |
742 | | #pragma clang diagnostic pop |
743 | | #endif |
744 | | |
745 | | |
746 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
747 | | { nullptr, &sAttributes_specs[0] }, |
748 | | { nullptr, nullptr } |
749 | | }; |
750 | | |
751 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
752 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
753 | | static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
754 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
755 | | |
756 | | |
757 | | static uint16_t sNativeProperties_sortedPropertyIndices[7]; |
758 | | static PropertyInfo sNativeProperties_propertyInfos[7]; |
759 | | |
760 | | static const NativePropertiesN<1> sNativeProperties = { |
761 | | false, 0, |
762 | | false, 0, |
763 | | false, 0, |
764 | | true, 0 /* sAttributes */, |
765 | | false, 0, |
766 | | false, 0, |
767 | | false, 0, |
768 | | -1, |
769 | | 7, |
770 | | sNativeProperties_sortedPropertyIndices, |
771 | | { |
772 | | { sAttributes, &sNativeProperties_propertyInfos[0] } |
773 | | } |
774 | | }; |
775 | | static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
776 | | "We have a property info count that is oversized"); |
777 | | |
778 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
779 | | { |
780 | | "Function", |
781 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
782 | | &sBoringInterfaceObjectClassClassOps, |
783 | | JS_NULL_CLASS_SPEC, |
784 | | JS_NULL_CLASS_EXT, |
785 | | &sInterfaceObjectClassObjectOps |
786 | | }, |
787 | | eInterface, |
788 | | true, |
789 | | prototypes::id::IDBRequest, |
790 | | PrototypeTraits<prototypes::id::IDBRequest>::Depth, |
791 | | sNativePropertyHooks, |
792 | | "function IDBRequest() {\n [native code]\n}", |
793 | | EventTarget_Binding::GetConstructorObject |
794 | | }; |
795 | | |
796 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
797 | | { |
798 | | "IDBRequestPrototype", |
799 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
800 | | JS_NULL_CLASS_OPS, |
801 | | JS_NULL_CLASS_SPEC, |
802 | | JS_NULL_CLASS_EXT, |
803 | | JS_NULL_OBJECT_OPS |
804 | | }, |
805 | | eInterfacePrototype, |
806 | | false, |
807 | | prototypes::id::IDBRequest, |
808 | | PrototypeTraits<prototypes::id::IDBRequest>::Depth, |
809 | | sNativePropertyHooks, |
810 | | "[object IDBRequestPrototype]", |
811 | | EventTarget_Binding::GetProtoObject |
812 | | }; |
813 | | |
814 | | static const js::ClassOps sClassOps = { |
815 | | _addProperty, /* addProperty */ |
816 | | nullptr, /* delProperty */ |
817 | | nullptr, /* enumerate */ |
818 | | nullptr, /* newEnumerate */ |
819 | | nullptr, /* resolve */ |
820 | | nullptr, /* mayResolve */ |
821 | | _finalize, /* finalize */ |
822 | | nullptr, /* call */ |
823 | | nullptr, /* hasInstance */ |
824 | | nullptr, /* construct */ |
825 | | nullptr, /* trace */ |
826 | | }; |
827 | | |
828 | | static const js::ClassExtension sClassExtension = { |
829 | | nullptr, /* weakmapKeyDelegateOp */ |
830 | | _objectMoved /* objectMovedOp */ |
831 | | }; |
832 | | |
833 | | static const DOMJSClass sClass = { |
834 | | { "IDBRequest", |
835 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
836 | | &sClassOps, |
837 | | JS_NULL_CLASS_SPEC, |
838 | | &sClassExtension, |
839 | | JS_NULL_OBJECT_OPS |
840 | | }, |
841 | | { prototypes::id::EventTarget, prototypes::id::IDBRequest, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
842 | | IsBaseOf<nsISupports, mozilla::dom::IDBRequest >::value, |
843 | | sNativePropertyHooks, |
844 | | FindAssociatedGlobalForNative<mozilla::dom::IDBRequest>::Get, |
845 | | GetProtoObjectHandle, |
846 | | GetCCParticipant<mozilla::dom::IDBRequest>::Get() |
847 | | }; |
848 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
849 | | "Must have the right minimal number of reserved slots."); |
850 | | static_assert(1 >= 1, |
851 | | "Must have enough reserved slots."); |
852 | | |
853 | | const JSClass* |
854 | | GetJSClass() |
855 | 0 | { |
856 | 0 | return sClass.ToJSClass(); |
857 | 0 | } |
858 | | |
859 | | bool |
860 | | Wrap(JSContext* aCx, mozilla::dom::IDBRequest* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
861 | 0 | { |
862 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::IDBRequest>::value, |
863 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
864 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::IDBRequest*>(aObject) == |
865 | 0 | reinterpret_cast<mozilla::dom::IDBRequest*>(aObject), |
866 | 0 | "Multiple inheritance for mozilla::dom::IDBRequest is broken."); |
867 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
868 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
869 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
870 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
871 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
872 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
873 | 0 | "You should probably not be using Wrap() directly; use " |
874 | 0 | "GetOrCreateDOMReflector instead"); |
875 | 0 |
|
876 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
877 | 0 | "nsISupports must be on our primary inheritance chain"); |
878 | 0 |
|
879 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
880 | 0 | if (!global) { |
881 | 0 | return false; |
882 | 0 | } |
883 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
884 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
885 | 0 |
|
886 | 0 | // That might have ended up wrapping us already, due to the wonders |
887 | 0 | // of XBL. Check for that, and bail out as needed. |
888 | 0 | aReflector.set(aCache->GetWrapper()); |
889 | 0 | if (aReflector) { |
890 | | #ifdef DEBUG |
891 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
892 | | #endif // DEBUG |
893 | | return true; |
894 | 0 | } |
895 | 0 |
|
896 | 0 | JSAutoRealm ar(aCx, global); |
897 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
898 | 0 | if (!canonicalProto) { |
899 | 0 | return false; |
900 | 0 | } |
901 | 0 | JS::Rooted<JSObject*> proto(aCx); |
902 | 0 | if (aGivenProto) { |
903 | 0 | proto = aGivenProto; |
904 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
905 | 0 | // coming in, we changed compartments to that of "parent" so may need |
906 | 0 | // to wrap the proto here. |
907 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
908 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
909 | 0 | return false; |
910 | 0 | } |
911 | 0 | } |
912 | 0 | } else { |
913 | 0 | proto = canonicalProto; |
914 | 0 | } |
915 | 0 |
|
916 | 0 | BindingJSObjectCreator<mozilla::dom::IDBRequest> creator(aCx); |
917 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
918 | 0 | if (!aReflector) { |
919 | 0 | return false; |
920 | 0 | } |
921 | 0 | |
922 | 0 | aCache->SetWrapper(aReflector); |
923 | 0 | creator.InitializationSucceeded(); |
924 | 0 |
|
925 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
926 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
927 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
928 | 0 | // otherwise we won't be able to properly recreate it later, since |
929 | 0 | // we won't know what proto to use. Note that we don't check |
930 | 0 | // aGivenProto here, since it's entirely possible (and even |
931 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
932 | 0 | // same as canonicalProto. |
933 | 0 | if (proto != canonicalProto) { |
934 | 0 | PreserveWrapper(aObject); |
935 | 0 | } |
936 | 0 |
|
937 | 0 | return true; |
938 | 0 | } |
939 | | |
940 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
941 | | nullptr, |
942 | | nullptr, |
943 | | nullptr, |
944 | | { sNativeProperties.Upcast(), nullptr }, |
945 | | prototypes::id::IDBRequest, |
946 | | constructors::id::IDBRequest, |
947 | | EventTarget_Binding::sNativePropertyHooks, |
948 | | &DefaultXrayExpandoObjectClass |
949 | | } }; |
950 | | |
951 | | void |
952 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
953 | 0 | { |
954 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
955 | 0 | if (!parentProto) { |
956 | 0 | return; |
957 | 0 | } |
958 | 0 | |
959 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
960 | 0 | if (!constructorProto) { |
961 | 0 | return; |
962 | 0 | } |
963 | 0 | |
964 | 0 | static bool sIdsInited = false; |
965 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
966 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
967 | 0 | return; |
968 | 0 | } |
969 | 0 | sIdsInited = true; |
970 | 0 | } |
971 | 0 |
|
972 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::IDBRequest); |
973 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::IDBRequest); |
974 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
975 | 0 | &sPrototypeClass.mBase, protoCache, |
976 | 0 | nullptr, |
977 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr, |
978 | 0 | interfaceCache, |
979 | 0 | sNativeProperties.Upcast(), |
980 | 0 | nullptr, |
981 | 0 | "IDBRequest", aDefineOnGlobal, |
982 | 0 | nullptr, |
983 | 0 | false); |
984 | 0 | } |
985 | | |
986 | | JSObject* |
987 | | GetProtoObject(JSContext* aCx) |
988 | 0 | { |
989 | 0 | return GetProtoObjectHandle(aCx); |
990 | 0 | } |
991 | | |
992 | | JSObject* |
993 | | GetConstructorObject(JSContext* aCx) |
994 | 0 | { |
995 | 0 | return GetConstructorObjectHandle(aCx); |
996 | 0 | } |
997 | | |
998 | | } // namespace IDBRequest_Binding |
999 | | |
1000 | | |
1001 | | |
1002 | | } // namespace dom |
1003 | | } // namespace mozilla |