/work/obj-fuzz/dom/bindings/ImageCaptureBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM ImageCapture.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "EventHandlerBinding.h" |
4 | | #include "EventTargetBinding.h" |
5 | | #include "ImageCaptureBinding.h" |
6 | | #include "WrapperFactory.h" |
7 | | #include "mozilla/OwningNonNull.h" |
8 | | #include "mozilla/Preferences.h" |
9 | | #include "mozilla/dom/BindingUtils.h" |
10 | | #include "mozilla/dom/DOMJSClass.h" |
11 | | #include "mozilla/dom/ImageCapture.h" |
12 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
13 | | #include "mozilla/dom/Nullable.h" |
14 | | #include "mozilla/dom/VideoStreamTrack.h" |
15 | | #include "mozilla/dom/XrayExpandoClass.h" |
16 | | |
17 | | namespace mozilla { |
18 | | namespace dom { |
19 | | |
20 | | namespace binding_detail {}; // Just to make sure it's known as a namespace |
21 | | using namespace mozilla::dom::binding_detail; |
22 | | |
23 | | |
24 | | namespace ImageCapture_Binding { |
25 | | |
26 | | static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value, |
27 | | "Can't inherit from an interface with a different ownership model."); |
28 | | |
29 | | MOZ_CAN_RUN_SCRIPT static bool |
30 | | get_videoStreamTrack(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCapture* self, JSJitGetterCallArgs args) |
31 | 0 | { |
32 | 0 | AUTO_PROFILER_LABEL_FAST("get ImageCapture.videoStreamTrack", DOM, cx); |
33 | 0 |
|
34 | 0 | auto result(StrongOrRawPtr<mozilla::dom::VideoStreamTrack>(self->GetVideoStreamTrack())); |
35 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
36 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval())) { |
37 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
38 | 0 | return false; |
39 | 0 | } |
40 | 0 | return true; |
41 | 0 | } |
42 | | |
43 | | static const JSJitInfo videoStreamTrack_getterinfo = { |
44 | | { (JSJitGetterOp)get_videoStreamTrack }, |
45 | | { prototypes::id::ImageCapture }, |
46 | | { PrototypeTraits<prototypes::id::ImageCapture>::Depth }, |
47 | | JSJitInfo::Getter, |
48 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
49 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
50 | | false, /* isInfallible. False in setters. */ |
51 | | false, /* isMovable. Not relevant for setters. */ |
52 | | false, /* isEliminatable. Not relevant for setters. */ |
53 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
54 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
55 | | false, /* isTypedMethod. Only relevant for methods. */ |
56 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
57 | | }; |
58 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
59 | | static_assert(0 < 1, "There is no slot for us"); |
60 | | |
61 | | MOZ_CAN_RUN_SCRIPT static bool |
62 | | get_onphoto(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCapture* self, JSJitGetterCallArgs args) |
63 | 0 | { |
64 | 0 | AUTO_PROFILER_LABEL_FAST("get ImageCapture.onphoto", DOM, cx); |
65 | 0 |
|
66 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnphoto()); |
67 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
68 | 0 | if (result) { |
69 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
70 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
71 | 0 | return false; |
72 | 0 | } |
73 | 0 | return true; |
74 | 0 | } else { |
75 | 0 | args.rval().setNull(); |
76 | 0 | return true; |
77 | 0 | } |
78 | 0 | } |
79 | | |
80 | | MOZ_CAN_RUN_SCRIPT static bool |
81 | | set_onphoto(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCapture* self, JSJitSetterCallArgs args) |
82 | 0 | { |
83 | 0 | AUTO_PROFILER_LABEL_FAST("set ImageCapture.onphoto", DOM, cx); |
84 | 0 |
|
85 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
86 | 0 | if (args[0].isObject()) { |
87 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
88 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
89 | 0 | } |
90 | 0 | } else { |
91 | 0 | arg0 = nullptr; |
92 | 0 | } |
93 | 0 | self->SetOnphoto(Constify(arg0)); |
94 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
95 | 0 |
|
96 | 0 | return true; |
97 | 0 | } |
98 | | |
99 | | static const JSJitInfo onphoto_getterinfo = { |
100 | | { (JSJitGetterOp)get_onphoto }, |
101 | | { prototypes::id::ImageCapture }, |
102 | | { PrototypeTraits<prototypes::id::ImageCapture>::Depth }, |
103 | | JSJitInfo::Getter, |
104 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
105 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
106 | | false, /* isInfallible. False in setters. */ |
107 | | false, /* isMovable. Not relevant for setters. */ |
108 | | false, /* isEliminatable. Not relevant for setters. */ |
109 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
110 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
111 | | false, /* isTypedMethod. Only relevant for methods. */ |
112 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
113 | | }; |
114 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
115 | | static_assert(0 < 1, "There is no slot for us"); |
116 | | static const JSJitInfo onphoto_setterinfo = { |
117 | | { (JSJitGetterOp)set_onphoto }, |
118 | | { prototypes::id::ImageCapture }, |
119 | | { PrototypeTraits<prototypes::id::ImageCapture>::Depth }, |
120 | | JSJitInfo::Setter, |
121 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
122 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
123 | | false, /* isInfallible. False in setters. */ |
124 | | false, /* isMovable. Not relevant for setters. */ |
125 | | false, /* isEliminatable. Not relevant for setters. */ |
126 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
127 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
128 | | false, /* isTypedMethod. Only relevant for methods. */ |
129 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
130 | | }; |
131 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
132 | | static_assert(0 < 1, "There is no slot for us"); |
133 | | |
134 | | MOZ_CAN_RUN_SCRIPT static bool |
135 | | get_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCapture* self, JSJitGetterCallArgs args) |
136 | 0 | { |
137 | 0 | AUTO_PROFILER_LABEL_FAST("get ImageCapture.onerror", DOM, cx); |
138 | 0 |
|
139 | 0 | RefPtr<EventHandlerNonNull> result(self->GetOnerror()); |
140 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
141 | 0 | if (result) { |
142 | 0 | args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result)); |
143 | 0 | if (!MaybeWrapObjectOrNullValue(cx, args.rval())) { |
144 | 0 | return false; |
145 | 0 | } |
146 | 0 | return true; |
147 | 0 | } else { |
148 | 0 | args.rval().setNull(); |
149 | 0 | return true; |
150 | 0 | } |
151 | 0 | } |
152 | | |
153 | | MOZ_CAN_RUN_SCRIPT static bool |
154 | | set_onerror(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCapture* self, JSJitSetterCallArgs args) |
155 | 0 | { |
156 | 0 | AUTO_PROFILER_LABEL_FAST("set ImageCapture.onerror", DOM, cx); |
157 | 0 |
|
158 | 0 | RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx); |
159 | 0 | if (args[0].isObject()) { |
160 | 0 | { // scope for tempRoot and tempGlobalRoot if needed |
161 | 0 | arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx)); |
162 | 0 | } |
163 | 0 | } else { |
164 | 0 | arg0 = nullptr; |
165 | 0 | } |
166 | 0 | self->SetOnerror(Constify(arg0)); |
167 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
168 | 0 |
|
169 | 0 | return true; |
170 | 0 | } |
171 | | |
172 | | static const JSJitInfo onerror_getterinfo = { |
173 | | { (JSJitGetterOp)get_onerror }, |
174 | | { prototypes::id::ImageCapture }, |
175 | | { PrototypeTraits<prototypes::id::ImageCapture>::Depth }, |
176 | | JSJitInfo::Getter, |
177 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
178 | | JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */ |
179 | | false, /* isInfallible. False in setters. */ |
180 | | false, /* isMovable. Not relevant for setters. */ |
181 | | false, /* isEliminatable. Not relevant for setters. */ |
182 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
183 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
184 | | false, /* isTypedMethod. Only relevant for methods. */ |
185 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
186 | | }; |
187 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
188 | | static_assert(0 < 1, "There is no slot for us"); |
189 | | static const JSJitInfo onerror_setterinfo = { |
190 | | { (JSJitGetterOp)set_onerror }, |
191 | | { prototypes::id::ImageCapture }, |
192 | | { PrototypeTraits<prototypes::id::ImageCapture>::Depth }, |
193 | | JSJitInfo::Setter, |
194 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
195 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
196 | | false, /* isInfallible. False in setters. */ |
197 | | false, /* isMovable. Not relevant for setters. */ |
198 | | false, /* isEliminatable. Not relevant for setters. */ |
199 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
200 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
201 | | false, /* isTypedMethod. Only relevant for methods. */ |
202 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
203 | | }; |
204 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
205 | | static_assert(0 < 1, "There is no slot for us"); |
206 | | |
207 | | MOZ_CAN_RUN_SCRIPT static bool |
208 | | takePhoto(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCapture* self, const JSJitMethodCallArgs& args) |
209 | 0 | { |
210 | 0 | AUTO_PROFILER_LABEL_FAST("ImageCapture.takePhoto", DOM, cx); |
211 | 0 |
|
212 | 0 | FastErrorResult rv; |
213 | 0 | self->TakePhoto(rv); |
214 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
215 | 0 | return false; |
216 | 0 | } |
217 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
218 | 0 | args.rval().setUndefined(); |
219 | 0 | return true; |
220 | 0 | } |
221 | | |
222 | | static const JSJitInfo takePhoto_methodinfo = { |
223 | | { (JSJitGetterOp)takePhoto }, |
224 | | { prototypes::id::ImageCapture }, |
225 | | { PrototypeTraits<prototypes::id::ImageCapture>::Depth }, |
226 | | JSJitInfo::Method, |
227 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
228 | | JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */ |
229 | | false, /* isInfallible. False in setters. */ |
230 | | false, /* isMovable. Not relevant for setters. */ |
231 | | false, /* isEliminatable. Not relevant for setters. */ |
232 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
233 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
234 | | false, /* isTypedMethod. Only relevant for methods. */ |
235 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
236 | | }; |
237 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
238 | | static_assert(0 < 1, "There is no slot for us"); |
239 | | |
240 | | static bool |
241 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
242 | 0 | { |
243 | 0 | mozilla::dom::ImageCapture* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCapture>(obj); |
244 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
245 | 0 | // obviously can't preserve if we're not initialized. |
246 | 0 | if (self && self->GetWrapperPreserveColor()) { |
247 | 0 | PreserveWrapper(self); |
248 | 0 | } |
249 | 0 | return true; |
250 | 0 | } |
251 | | |
252 | | static void |
253 | | _finalize(js::FreeOp* fop, JSObject* obj) |
254 | 0 | { |
255 | 0 | mozilla::dom::ImageCapture* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCapture>(obj); |
256 | 0 | if (self) { |
257 | 0 | ClearWrapper(self, self, obj); |
258 | 0 | AddForDeferredFinalization<mozilla::dom::ImageCapture>(self); |
259 | 0 | } |
260 | 0 | } |
261 | | |
262 | | static size_t |
263 | | _objectMoved(JSObject* obj, JSObject* old) |
264 | 0 | { |
265 | 0 | mozilla::dom::ImageCapture* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCapture>(obj); |
266 | 0 | if (self) { |
267 | 0 | UpdateWrapper(self, self, obj, old); |
268 | 0 | } |
269 | 0 |
|
270 | 0 | return 0; |
271 | 0 | } |
272 | | |
273 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
274 | | #if defined(__clang__) |
275 | | #pragma clang diagnostic push |
276 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
277 | | #endif |
278 | | static const JSFunctionSpec sMethods_specs[] = { |
279 | | JS_FNSPEC("takePhoto", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&takePhoto_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
280 | | JS_FS_END |
281 | | }; |
282 | | #if defined(__clang__) |
283 | | #pragma clang diagnostic pop |
284 | | #endif |
285 | | |
286 | | |
287 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
288 | | { nullptr, &sMethods_specs[0] }, |
289 | | { nullptr, nullptr } |
290 | | }; |
291 | | |
292 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
293 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
294 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
295 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
296 | | |
297 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
298 | | #if defined(__clang__) |
299 | | #pragma clang diagnostic push |
300 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
301 | | #endif |
302 | | static const JSPropertySpec sAttributes_specs[] = { |
303 | | { "videoStreamTrack", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &videoStreamTrack_getterinfo, nullptr, nullptr }, |
304 | | { "onphoto", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onphoto_getterinfo, GenericSetter<NormalThisPolicy>, &onphoto_setterinfo }, |
305 | | { "onerror", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onerror_getterinfo, GenericSetter<NormalThisPolicy>, &onerror_setterinfo }, |
306 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
307 | | }; |
308 | | #if defined(__clang__) |
309 | | #pragma clang diagnostic pop |
310 | | #endif |
311 | | |
312 | | |
313 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
314 | | { nullptr, &sAttributes_specs[0] }, |
315 | | { nullptr, nullptr } |
316 | | }; |
317 | | |
318 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
319 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
320 | | static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
321 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
322 | | |
323 | | |
324 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
325 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
326 | | |
327 | | static const NativePropertiesN<2> sNativeProperties = { |
328 | | false, 0, |
329 | | false, 0, |
330 | | true, 0 /* sMethods */, |
331 | | true, 1 /* sAttributes */, |
332 | | false, 0, |
333 | | false, 0, |
334 | | false, 0, |
335 | | -1, |
336 | | 4, |
337 | | sNativeProperties_sortedPropertyIndices, |
338 | | { |
339 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
340 | | { sAttributes, &sNativeProperties_propertyInfos[1] } |
341 | | } |
342 | | }; |
343 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
344 | | "We have a property info count that is oversized"); |
345 | | |
346 | | static bool |
347 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
348 | 0 | { |
349 | 0 | AUTO_PROFILER_LABEL_FAST("ImageCapture constructor", DOM, cx); |
350 | 0 |
|
351 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
352 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
353 | 0 | if (!args.isConstructing()) { |
354 | 0 | // XXXbz wish I could get the name from the callee instead of |
355 | 0 | // Adding more relocations |
356 | 0 | return ThrowConstructorWithoutNew(cx, "ImageCapture"); |
357 | 0 | } |
358 | 0 | |
359 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
360 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
361 | 0 | return false; |
362 | 0 | } |
363 | 0 | |
364 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
365 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ImageCapture"); |
366 | 0 | } |
367 | 0 | GlobalObject global(cx, obj); |
368 | 0 | if (global.Failed()) { |
369 | 0 | return false; |
370 | 0 | } |
371 | 0 | |
372 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
373 | 0 | NonNull<mozilla::dom::VideoStreamTrack> arg0; |
374 | 0 | if (args[0].isObject()) { |
375 | 0 | { |
376 | 0 | nsresult rv = UnwrapObject<prototypes::id::VideoStreamTrack, mozilla::dom::VideoStreamTrack>(args[0], arg0); |
377 | 0 | if (NS_FAILED(rv)) { |
378 | 0 | ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of ImageCapture.constructor", "VideoStreamTrack"); |
379 | 0 | return false; |
380 | 0 | } |
381 | 0 | } |
382 | 0 | } else { |
383 | 0 | ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of ImageCapture.constructor"); |
384 | 0 | return false; |
385 | 0 | } |
386 | 0 | Maybe<JSAutoRealm> ar; |
387 | 0 | if (objIsXray) { |
388 | 0 | obj = js::CheckedUnwrap(obj); |
389 | 0 | if (!obj) { |
390 | 0 | return false; |
391 | 0 | } |
392 | 0 | ar.emplace(cx, obj); |
393 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
394 | 0 | return false; |
395 | 0 | } |
396 | 0 | } |
397 | 0 | FastErrorResult rv; |
398 | 0 | auto result(StrongOrRawPtr<mozilla::dom::ImageCapture>(mozilla::dom::ImageCapture::Constructor(global, MOZ_KnownLive(NonNullHelper(arg0)), rv))); |
399 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
400 | 0 | return false; |
401 | 0 | } |
402 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
403 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
404 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
405 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
406 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
407 | 0 | return false; |
408 | 0 | } |
409 | 0 | return true; |
410 | 0 | } |
411 | | |
412 | | static const js::ClassOps sInterfaceObjectClassOps = { |
413 | | nullptr, /* addProperty */ |
414 | | nullptr, /* delProperty */ |
415 | | nullptr, /* enumerate */ |
416 | | nullptr, /* newEnumerate */ |
417 | | nullptr, /* resolve */ |
418 | | nullptr, /* mayResolve */ |
419 | | nullptr, /* finalize */ |
420 | | _constructor, /* call */ |
421 | | nullptr, /* hasInstance */ |
422 | | _constructor, /* construct */ |
423 | | nullptr, /* trace */ |
424 | | }; |
425 | | |
426 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
427 | | { |
428 | | "Function", |
429 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
430 | | &sInterfaceObjectClassOps, |
431 | | JS_NULL_CLASS_SPEC, |
432 | | JS_NULL_CLASS_EXT, |
433 | | &sInterfaceObjectClassObjectOps |
434 | | }, |
435 | | eInterface, |
436 | | true, |
437 | | prototypes::id::ImageCapture, |
438 | | PrototypeTraits<prototypes::id::ImageCapture>::Depth, |
439 | | sNativePropertyHooks, |
440 | | "function ImageCapture() {\n [native code]\n}", |
441 | | EventTarget_Binding::GetConstructorObject |
442 | | }; |
443 | | |
444 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
445 | | { |
446 | | "ImageCapturePrototype", |
447 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
448 | | JS_NULL_CLASS_OPS, |
449 | | JS_NULL_CLASS_SPEC, |
450 | | JS_NULL_CLASS_EXT, |
451 | | JS_NULL_OBJECT_OPS |
452 | | }, |
453 | | eInterfacePrototype, |
454 | | false, |
455 | | prototypes::id::ImageCapture, |
456 | | PrototypeTraits<prototypes::id::ImageCapture>::Depth, |
457 | | sNativePropertyHooks, |
458 | | "[object ImageCapturePrototype]", |
459 | | EventTarget_Binding::GetProtoObject |
460 | | }; |
461 | | |
462 | | bool |
463 | | ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj) |
464 | 0 | { |
465 | 0 | static bool sPrefValue; |
466 | 0 | static bool sPrefCacheSetUp = false; |
467 | 0 | if (!sPrefCacheSetUp) { |
468 | 0 | sPrefCacheSetUp = true; |
469 | 0 | Preferences::AddBoolVarCache(&sPrefValue, "dom.imagecapture.enabled"); |
470 | 0 | } |
471 | 0 |
|
472 | 0 | return sPrefValue; |
473 | 0 | } |
474 | | |
475 | | static const js::ClassOps sClassOps = { |
476 | | _addProperty, /* addProperty */ |
477 | | nullptr, /* delProperty */ |
478 | | nullptr, /* enumerate */ |
479 | | nullptr, /* newEnumerate */ |
480 | | nullptr, /* resolve */ |
481 | | nullptr, /* mayResolve */ |
482 | | _finalize, /* finalize */ |
483 | | nullptr, /* call */ |
484 | | nullptr, /* hasInstance */ |
485 | | nullptr, /* construct */ |
486 | | nullptr, /* trace */ |
487 | | }; |
488 | | |
489 | | static const js::ClassExtension sClassExtension = { |
490 | | nullptr, /* weakmapKeyDelegateOp */ |
491 | | _objectMoved /* objectMovedOp */ |
492 | | }; |
493 | | |
494 | | static const DOMJSClass sClass = { |
495 | | { "ImageCapture", |
496 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
497 | | &sClassOps, |
498 | | JS_NULL_CLASS_SPEC, |
499 | | &sClassExtension, |
500 | | JS_NULL_OBJECT_OPS |
501 | | }, |
502 | | { prototypes::id::EventTarget, prototypes::id::ImageCapture, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count }, |
503 | | IsBaseOf<nsISupports, mozilla::dom::ImageCapture >::value, |
504 | | sNativePropertyHooks, |
505 | | FindAssociatedGlobalForNative<mozilla::dom::ImageCapture>::Get, |
506 | | GetProtoObjectHandle, |
507 | | GetCCParticipant<mozilla::dom::ImageCapture>::Get() |
508 | | }; |
509 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
510 | | "Must have the right minimal number of reserved slots."); |
511 | | static_assert(1 >= 1, |
512 | | "Must have enough reserved slots."); |
513 | | |
514 | | const JSClass* |
515 | | GetJSClass() |
516 | 0 | { |
517 | 0 | return sClass.ToJSClass(); |
518 | 0 | } |
519 | | |
520 | | bool |
521 | | Wrap(JSContext* aCx, mozilla::dom::ImageCapture* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
522 | 0 | { |
523 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ImageCapture>::value, |
524 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
525 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::ImageCapture*>(aObject) == |
526 | 0 | reinterpret_cast<mozilla::dom::ImageCapture*>(aObject), |
527 | 0 | "Multiple inheritance for mozilla::dom::ImageCapture is broken."); |
528 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) == |
529 | 0 | reinterpret_cast<mozilla::dom::EventTarget*>(aObject), |
530 | 0 | "Multiple inheritance for mozilla::dom::EventTarget is broken."); |
531 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
532 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
533 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
534 | 0 | "You should probably not be using Wrap() directly; use " |
535 | 0 | "GetOrCreateDOMReflector instead"); |
536 | 0 |
|
537 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
538 | 0 | "nsISupports must be on our primary inheritance chain"); |
539 | 0 |
|
540 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
541 | 0 | if (!global) { |
542 | 0 | return false; |
543 | 0 | } |
544 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
545 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
546 | 0 |
|
547 | 0 | // That might have ended up wrapping us already, due to the wonders |
548 | 0 | // of XBL. Check for that, and bail out as needed. |
549 | 0 | aReflector.set(aCache->GetWrapper()); |
550 | 0 | if (aReflector) { |
551 | | #ifdef DEBUG |
552 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
553 | | #endif // DEBUG |
554 | | return true; |
555 | 0 | } |
556 | 0 |
|
557 | 0 | JSAutoRealm ar(aCx, global); |
558 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
559 | 0 | if (!canonicalProto) { |
560 | 0 | return false; |
561 | 0 | } |
562 | 0 | JS::Rooted<JSObject*> proto(aCx); |
563 | 0 | if (aGivenProto) { |
564 | 0 | proto = aGivenProto; |
565 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
566 | 0 | // coming in, we changed compartments to that of "parent" so may need |
567 | 0 | // to wrap the proto here. |
568 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
569 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
570 | 0 | return false; |
571 | 0 | } |
572 | 0 | } |
573 | 0 | } else { |
574 | 0 | proto = canonicalProto; |
575 | 0 | } |
576 | 0 |
|
577 | 0 | BindingJSObjectCreator<mozilla::dom::ImageCapture> creator(aCx); |
578 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
579 | 0 | if (!aReflector) { |
580 | 0 | return false; |
581 | 0 | } |
582 | 0 | |
583 | 0 | aCache->SetWrapper(aReflector); |
584 | 0 | creator.InitializationSucceeded(); |
585 | 0 |
|
586 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
587 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
588 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
589 | 0 | // otherwise we won't be able to properly recreate it later, since |
590 | 0 | // we won't know what proto to use. Note that we don't check |
591 | 0 | // aGivenProto here, since it's entirely possible (and even |
592 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
593 | 0 | // same as canonicalProto. |
594 | 0 | if (proto != canonicalProto) { |
595 | 0 | PreserveWrapper(aObject); |
596 | 0 | } |
597 | 0 |
|
598 | 0 | return true; |
599 | 0 | } |
600 | | |
601 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
602 | | nullptr, |
603 | | nullptr, |
604 | | nullptr, |
605 | | { sNativeProperties.Upcast(), nullptr }, |
606 | | prototypes::id::ImageCapture, |
607 | | constructors::id::ImageCapture, |
608 | | EventTarget_Binding::sNativePropertyHooks, |
609 | | &DefaultXrayExpandoObjectClass |
610 | | } }; |
611 | | |
612 | | void |
613 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
614 | 0 | { |
615 | 0 | JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx)); |
616 | 0 | if (!parentProto) { |
617 | 0 | return; |
618 | 0 | } |
619 | 0 | |
620 | 0 | JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx)); |
621 | 0 | if (!constructorProto) { |
622 | 0 | return; |
623 | 0 | } |
624 | 0 | |
625 | 0 | static bool sIdsInited = false; |
626 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
627 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
628 | 0 | return; |
629 | 0 | } |
630 | 0 | sIdsInited = true; |
631 | 0 | } |
632 | 0 |
|
633 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ImageCapture); |
634 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ImageCapture); |
635 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
636 | 0 | &sPrototypeClass.mBase, protoCache, |
637 | 0 | nullptr, |
638 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
639 | 0 | interfaceCache, |
640 | 0 | sNativeProperties.Upcast(), |
641 | 0 | nullptr, |
642 | 0 | "ImageCapture", aDefineOnGlobal, |
643 | 0 | nullptr, |
644 | 0 | false); |
645 | 0 | } |
646 | | |
647 | | JSObject* |
648 | | GetConstructorObject(JSContext* aCx) |
649 | 0 | { |
650 | 0 | return GetConstructorObjectHandle(aCx); |
651 | 0 | } |
652 | | |
653 | | } // namespace ImageCapture_Binding |
654 | | |
655 | | |
656 | | |
657 | | } // namespace dom |
658 | | } // namespace mozilla |