Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM ImageCaptureErrorEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "ImageCaptureErrorEventBinding.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/ImageCaptureError.h"
12 : #include "mozilla/dom/ImageCaptureErrorEvent.h"
13 : #include "mozilla/dom/NonRefcountedDOMObject.h"
14 : #include "mozilla/dom/Nullable.h"
15 : #include "mozilla/dom/PrimitiveConversions.h"
16 : #include "mozilla/dom/ScriptSettings.h"
17 : #include "mozilla/dom/XrayExpandoClass.h"
18 :
19 : namespace mozilla {
20 : namespace dom {
21 :
22 :
23 0 : ImageCaptureErrorEventInit::ImageCaptureErrorEventInit()
24 0 : : EventInit(FastDictionaryInitializer())
25 : {
26 : // Safe to pass a null context if we pass a null value
27 0 : Init(nullptr, JS::NullHandleValue);
28 0 : }
29 :
30 :
31 :
32 : bool
33 0 : ImageCaptureErrorEventInit::InitIds(JSContext* cx, ImageCaptureErrorEventInitAtoms* atomsCache)
34 : {
35 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
36 :
37 : // Initialize these in reverse order so that any failure leaves the first one
38 : // uninitialized.
39 0 : if (!atomsCache->imageCaptureError_id.init(cx, "imageCaptureError")) {
40 0 : return false;
41 : }
42 0 : return true;
43 : }
44 :
45 : bool
46 0 : ImageCaptureErrorEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
47 : {
48 : // Passing a null JSContext is OK only if we're initing from null,
49 : // Since in that case we will not have to do any property gets
50 : // Also evaluate isNullOrUndefined in order to avoid false-positive
51 : // checkers by static analysis tools
52 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
53 0 : ImageCaptureErrorEventInitAtoms* atomsCache = nullptr;
54 0 : if (cx) {
55 0 : atomsCache = GetAtomCache<ImageCaptureErrorEventInitAtoms>(cx);
56 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
57 0 : return false;
58 : }
59 : }
60 :
61 : // Per spec, we init the parent's members first
62 0 : if (!EventInit::Init(cx, val)) {
63 0 : return false;
64 : }
65 :
66 0 : bool isNull = val.isNullOrUndefined();
67 : // We only need these if !isNull, in which case we have |cx|.
68 0 : Maybe<JS::Rooted<JSObject *> > object;
69 0 : Maybe<JS::Rooted<JS::Value> > temp;
70 0 : if (!isNull) {
71 0 : MOZ_ASSERT(cx);
72 0 : object.emplace(cx, &val.toObject());
73 0 : temp.emplace(cx);
74 : }
75 0 : if (!isNull) {
76 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->imageCaptureError_id, temp.ptr())) {
77 0 : return false;
78 : }
79 : }
80 0 : if (!isNull && !temp->isUndefined()) {
81 0 : if (temp.ref().isObject()) {
82 : static_assert(IsRefcounted<mozilla::dom::ImageCaptureError>::value, "We can only store refcounted classes.");{
83 0 : nsresult rv = UnwrapObject<prototypes::id::ImageCaptureError, mozilla::dom::ImageCaptureError>(temp.ptr(), mImageCaptureError);
84 0 : if (NS_FAILED(rv)) {
85 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'imageCaptureError' member of ImageCaptureErrorEventInit", "ImageCaptureError");
86 0 : return false;
87 : }
88 : }
89 0 : } else if (temp.ref().isNullOrUndefined()) {
90 0 : mImageCaptureError = nullptr;
91 : } else {
92 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'imageCaptureError' member of ImageCaptureErrorEventInit");
93 0 : return false;
94 : }
95 : } else {
96 0 : mImageCaptureError = nullptr;
97 : }
98 0 : mIsAnyMemberPresent = true;
99 0 : return true;
100 : }
101 :
102 : bool
103 0 : ImageCaptureErrorEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
104 : {
105 0 : ImageCaptureErrorEventInitAtoms* atomsCache = GetAtomCache<ImageCaptureErrorEventInitAtoms>(cx);
106 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
107 0 : return false;
108 : }
109 :
110 : // Per spec, we define the parent's members first
111 0 : if (!EventInit::ToObjectInternal(cx, rval)) {
112 0 : return false;
113 : }
114 0 : JS::Rooted<JSObject*> obj(cx, &rval.toObject());
115 :
116 : do {
117 : // block for our 'break' successCode and scope for 'temp' and 'currentValue'
118 0 : JS::Rooted<JS::Value> temp(cx);
119 0 : RefPtr<mozilla::dom::ImageCaptureError> const & currentValue = mImageCaptureError;
120 0 : if (!currentValue) {
121 0 : temp.setNull();
122 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->imageCaptureError_id, temp, JSPROP_ENUMERATE)) {
123 0 : return false;
124 : }
125 0 : break;
126 : }
127 0 : if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
128 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
129 0 : return false;
130 : }
131 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->imageCaptureError_id, temp, JSPROP_ENUMERATE)) {
132 0 : return false;
133 : }
134 0 : break;
135 : } while(0);
136 :
137 0 : return true;
138 : }
139 :
140 : void
141 0 : ImageCaptureErrorEventInit::TraceDictionary(JSTracer* trc)
142 : {
143 0 : EventInit::TraceDictionary(trc);
144 0 : }
145 :
146 : ImageCaptureErrorEventInit&
147 0 : ImageCaptureErrorEventInit::operator=(const ImageCaptureErrorEventInit& aOther)
148 : {
149 0 : EventInit::operator=(aOther);
150 0 : mImageCaptureError = aOther.mImageCaptureError;
151 0 : return *this;
152 : }
153 :
154 : namespace binding_detail {
155 : } // namespace binding_detail
156 :
157 :
158 : namespace ImageCaptureErrorBinding {
159 :
160 : static bool
161 0 : get_code(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCaptureError* self, JSJitGetterCallArgs args)
162 : {
163 0 : uint16_t result(self->Code());
164 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
165 0 : args.rval().setInt32(int32_t(result));
166 0 : return true;
167 : }
168 :
169 : static const JSJitInfo code_getterinfo = {
170 : { (JSJitGetterOp)get_code },
171 : { prototypes::id::ImageCaptureError },
172 : { PrototypeTraits<prototypes::id::ImageCaptureError>::Depth },
173 : JSJitInfo::Getter,
174 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
175 : JSVAL_TYPE_INT32, /* returnType. Not relevant for setters. */
176 : true, /* isInfallible. False in setters. */
177 : false, /* isMovable. Not relevant for setters. */
178 : false, /* isEliminatable. Not relevant for setters. */
179 : false, /* isAlwaysInSlot. Only relevant for getters. */
180 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
181 : false, /* isTypedMethod. Only relevant for methods. */
182 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
183 : };
184 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
185 : static_assert(0 < 1, "There is no slot for us");
186 :
187 : static bool
188 0 : get_message(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCaptureError* self, JSJitGetterCallArgs args)
189 : {
190 0 : DOMString result;
191 0 : self->GetMessage(result);
192 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
193 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
194 0 : return false;
195 : }
196 0 : return true;
197 : }
198 :
199 : static const JSJitInfo message_getterinfo = {
200 : { (JSJitGetterOp)get_message },
201 : { prototypes::id::ImageCaptureError },
202 : { PrototypeTraits<prototypes::id::ImageCaptureError>::Depth },
203 : JSJitInfo::Getter,
204 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
205 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
206 : false, /* isInfallible. False in setters. */
207 : false, /* isMovable. Not relevant for setters. */
208 : false, /* isEliminatable. Not relevant for setters. */
209 : false, /* isAlwaysInSlot. Only relevant for getters. */
210 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
211 : false, /* isTypedMethod. Only relevant for methods. */
212 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
213 : };
214 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
215 : static_assert(0 < 1, "There is no slot for us");
216 :
217 : static bool
218 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
219 : {
220 0 : mozilla::dom::ImageCaptureError* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCaptureError>(obj);
221 : // We don't want to preserve if we don't have a wrapper, and we
222 : // obviously can't preserve if we're not initialized.
223 0 : if (self && self->GetWrapperPreserveColor()) {
224 0 : PreserveWrapper(self);
225 : }
226 0 : return true;
227 : }
228 :
229 : static void
230 0 : _finalize(js::FreeOp* fop, JSObject* obj)
231 : {
232 0 : mozilla::dom::ImageCaptureError* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCaptureError>(obj);
233 0 : if (self) {
234 0 : ClearWrapper(self, self, obj);
235 0 : AddForDeferredFinalization<mozilla::dom::ImageCaptureError>(self);
236 : }
237 0 : }
238 :
239 : static void
240 0 : _objectMoved(JSObject* obj, const JSObject* old)
241 : {
242 0 : mozilla::dom::ImageCaptureError* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCaptureError>(obj);
243 0 : if (self) {
244 0 : UpdateWrapper(self, self, obj, old);
245 : }
246 0 : }
247 :
248 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
249 : #if defined(__clang__)
250 : #pragma clang diagnostic push
251 : #pragma clang diagnostic ignored "-Wmissing-braces"
252 : #endif
253 : static const JSPropertySpec sAttributes_specs[] = {
254 : { "code", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &code_getterinfo, nullptr, nullptr },
255 : { "message", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &message_getterinfo, nullptr, nullptr },
256 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
257 : };
258 : #if defined(__clang__)
259 : #pragma clang diagnostic pop
260 : #endif
261 :
262 :
263 : // Can't be const because the pref-enabled boolean needs to be writable
264 : static Prefable<const JSPropertySpec> sAttributes[] = {
265 : { nullptr, &sAttributes_specs[0] },
266 : { nullptr, nullptr }
267 : };
268 :
269 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
270 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
271 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
272 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
273 :
274 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
275 : #if defined(__clang__)
276 : #pragma clang diagnostic push
277 : #pragma clang diagnostic ignored "-Wmissing-braces"
278 : #endif
279 : static const ConstantSpec sConstants_specs[] = {
280 : { "FRAME_GRAB_ERROR", JS::Int32Value(1) },
281 : { "SETTINGS_ERROR", JS::Int32Value(2) },
282 : { "PHOTO_ERROR", JS::Int32Value(3) },
283 : { "ERROR_UNKNOWN", JS::Int32Value(4) },
284 : { 0, JS::UndefinedValue() }
285 : };
286 : #if defined(__clang__)
287 : #pragma clang diagnostic pop
288 : #endif
289 :
290 :
291 : // Can't be const because the pref-enabled boolean needs to be writable
292 : static Prefable<const ConstantSpec> sConstants[] = {
293 : { nullptr, &sConstants_specs[0] },
294 : { nullptr, nullptr }
295 : };
296 :
297 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
298 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
299 : static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
300 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
301 :
302 :
303 : static uint16_t sNativeProperties_sortedPropertyIndices[6];
304 : static PropertyInfo sNativeProperties_propertyInfos[6];
305 :
306 : static const NativePropertiesN<2> sNativeProperties = {
307 : false, 0,
308 : false, 0,
309 : false, 0,
310 : true, 0 /* sAttributes */,
311 : false, 0,
312 : false, 0,
313 : true, 1 /* sConstants */,
314 : -1,
315 : 6,
316 : sNativeProperties_sortedPropertyIndices,
317 : {
318 : { sAttributes, &sNativeProperties_propertyInfos[0] },
319 : { sConstants, &sNativeProperties_propertyInfos[2] }
320 : }
321 : };
322 : static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
323 : "We have a property info count that is oversized");
324 :
325 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
326 : {
327 : "ImageCaptureErrorPrototype",
328 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
329 : JS_NULL_CLASS_OPS,
330 : JS_NULL_CLASS_SPEC,
331 : JS_NULL_CLASS_EXT,
332 : JS_NULL_OBJECT_OPS
333 : },
334 : eInterfacePrototype,
335 : false,
336 : prototypes::id::ImageCaptureError,
337 : PrototypeTraits<prototypes::id::ImageCaptureError>::Depth,
338 : sNativePropertyHooks,
339 : "[object ImageCaptureErrorPrototype]",
340 : JS::GetRealmObjectPrototype
341 : };
342 :
343 : static const js::ClassOps sClassOps = {
344 : _addProperty, /* addProperty */
345 : nullptr, /* delProperty */
346 : nullptr, /* getProperty */
347 : nullptr, /* setProperty */
348 : nullptr, /* enumerate */
349 : nullptr, /* newEnumerate */
350 : nullptr, /* resolve */
351 : nullptr, /* mayResolve */
352 : _finalize, /* finalize */
353 : nullptr, /* call */
354 : nullptr, /* hasInstance */
355 : nullptr, /* construct */
356 : nullptr, /* trace */
357 : };
358 :
359 : static const js::ClassExtension sClassExtension = {
360 : nullptr, /* weakmapKeyDelegateOp */
361 : _objectMoved /* objectMovedOp */
362 : };
363 :
364 : static const DOMJSClass sClass = {
365 : { "ImageCaptureError",
366 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
367 : &sClassOps,
368 : JS_NULL_CLASS_SPEC,
369 : &sClassExtension,
370 : JS_NULL_OBJECT_OPS
371 : },
372 : { prototypes::id::ImageCaptureError, 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 },
373 : IsBaseOf<nsISupports, mozilla::dom::ImageCaptureError >::value,
374 : sNativePropertyHooks,
375 : FindAssociatedGlobalForNative<mozilla::dom::ImageCaptureError>::Get,
376 : GetProtoObjectHandle,
377 : GetCCParticipant<mozilla::dom::ImageCaptureError>::Get()
378 : };
379 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
380 : "Must have the right minimal number of reserved slots.");
381 : static_assert(1 >= 1,
382 : "Must have enough reserved slots.");
383 :
384 : const JSClass*
385 0 : GetJSClass()
386 : {
387 0 : return sClass.ToJSClass();
388 : }
389 :
390 : bool
391 0 : Wrap(JSContext* aCx, mozilla::dom::ImageCaptureError* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
392 : {
393 : MOZ_ASSERT(static_cast<mozilla::dom::ImageCaptureError*>(aObject) ==
394 : reinterpret_cast<mozilla::dom::ImageCaptureError*>(aObject),
395 : "Multiple inheritance for mozilla::dom::ImageCaptureError is broken.");
396 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
397 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
398 0 : MOZ_ASSERT(!aCache->GetWrapper(),
399 : "You should probably not be using Wrap() directly; use "
400 : "GetOrCreateDOMReflector instead");
401 :
402 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
403 : "nsISupports must be on our primary inheritance chain");
404 :
405 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
406 0 : if (!global) {
407 0 : return false;
408 : }
409 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
410 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
411 :
412 : // That might have ended up wrapping us already, due to the wonders
413 : // of XBL. Check for that, and bail out as needed.
414 0 : aReflector.set(aCache->GetWrapper());
415 0 : if (aReflector) {
416 : #ifdef DEBUG
417 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
418 : #endif // DEBUG
419 0 : return true;
420 : }
421 :
422 0 : JSAutoCompartment ac(aCx, global);
423 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
424 0 : if (!canonicalProto) {
425 0 : return false;
426 : }
427 0 : JS::Rooted<JSObject*> proto(aCx);
428 0 : if (aGivenProto) {
429 0 : proto = aGivenProto;
430 : // Unfortunately, while aGivenProto was in the compartment of aCx
431 : // coming in, we changed compartments to that of "parent" so may need
432 : // to wrap the proto here.
433 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
434 0 : if (!JS_WrapObject(aCx, &proto)) {
435 0 : return false;
436 : }
437 : }
438 : } else {
439 0 : proto = canonicalProto;
440 : }
441 :
442 0 : BindingJSObjectCreator<mozilla::dom::ImageCaptureError> creator(aCx);
443 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
444 0 : if (!aReflector) {
445 0 : return false;
446 : }
447 :
448 0 : aCache->SetWrapper(aReflector);
449 0 : creator.InitializationSucceeded();
450 :
451 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
452 : aCache->GetWrapperPreserveColor() == aReflector);
453 : // If proto != canonicalProto, we have to preserve our wrapper;
454 : // otherwise we won't be able to properly recreate it later, since
455 : // we won't know what proto to use. Note that we don't check
456 : // aGivenProto here, since it's entirely possible (and even
457 : // somewhat common) to have a non-null aGivenProto which is the
458 : // same as canonicalProto.
459 0 : if (proto != canonicalProto) {
460 0 : PreserveWrapper(aObject);
461 : }
462 :
463 0 : return true;
464 : }
465 :
466 : const NativePropertyHooks sNativePropertyHooks[] = { {
467 : nullptr,
468 : nullptr,
469 : nullptr,
470 : { sNativeProperties.Upcast(), nullptr },
471 : prototypes::id::ImageCaptureError,
472 : constructors::id::_ID_Count,
473 : nullptr,
474 : &DefaultXrayExpandoObjectClass
475 : } };
476 :
477 : void
478 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
479 : {
480 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
481 0 : if (!parentProto) {
482 0 : return;
483 : }
484 :
485 : static bool sIdsInited = false;
486 0 : if (!sIdsInited && NS_IsMainThread()) {
487 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
488 0 : return;
489 : }
490 0 : sIdsInited = true;
491 : }
492 :
493 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ImageCaptureError);
494 0 : JS::Heap<JSObject*>* interfaceCache = nullptr;
495 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
496 : &sPrototypeClass.mBase, protoCache,
497 : nullptr, nullptr, 0, nullptr,
498 : interfaceCache,
499 : sNativeProperties.Upcast(),
500 : nullptr,
501 : nullptr, aDefineOnGlobal,
502 : nullptr,
503 0 : false);
504 : }
505 :
506 : JS::Handle<JSObject*>
507 0 : GetProtoObjectHandle(JSContext* aCx)
508 : {
509 : /* Get the interface prototype object for this class. This will create the
510 : object as needed. */
511 0 : bool aDefineOnGlobal = true;
512 :
513 : /* Make sure our global is sane. Hopefully we can remove this sometime */
514 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
515 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
516 0 : return nullptr;
517 : }
518 :
519 : /* Check to see whether the interface objects are already installed */
520 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
521 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ImageCaptureError)) {
522 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
523 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
524 : }
525 :
526 : /*
527 : * The object might _still_ be null, but that's OK.
528 : *
529 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
530 : * traced by TraceProtoAndIfaceCache() and its contents are never
531 : * changed after they have been set.
532 : *
533 : * Calling address() avoids the read read barrier that does gray
534 : * unmarking, but it's not possible for the object to be gray here.
535 : */
536 :
537 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ImageCaptureError);
538 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
539 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
540 : }
541 :
542 : } // namespace ImageCaptureErrorBinding
543 :
544 :
545 :
546 : namespace ImageCaptureErrorEventBinding {
547 :
548 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
549 : "Can't inherit from an interface with a different ownership model.");
550 :
551 : static bool
552 0 : get_imageCaptureError(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCaptureErrorEvent* self, JSJitGetterCallArgs args)
553 : {
554 0 : auto result(StrongOrRawPtr<mozilla::dom::ImageCaptureError>(self->GetImageCaptureError()));
555 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
556 0 : if (!result) {
557 0 : args.rval().setNull();
558 0 : return true;
559 : }
560 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
561 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
562 0 : return false;
563 : }
564 0 : return true;
565 : }
566 :
567 : static const JSJitInfo imageCaptureError_getterinfo = {
568 : { (JSJitGetterOp)get_imageCaptureError },
569 : { prototypes::id::ImageCaptureErrorEvent },
570 : { PrototypeTraits<prototypes::id::ImageCaptureErrorEvent>::Depth },
571 : JSJitInfo::Getter,
572 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
573 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
574 : false, /* isInfallible. False in setters. */
575 : false, /* isMovable. Not relevant for setters. */
576 : false, /* isEliminatable. Not relevant for setters. */
577 : false, /* isAlwaysInSlot. Only relevant for getters. */
578 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
579 : false, /* isTypedMethod. Only relevant for methods. */
580 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
581 : };
582 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
583 : static_assert(0 < 1, "There is no slot for us");
584 :
585 : static bool
586 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ImageCaptureErrorEvent* self, JSJitGetterCallArgs args)
587 : {
588 0 : bool result(self->IsTrusted());
589 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
590 0 : args.rval().setBoolean(result);
591 0 : return true;
592 : }
593 :
594 : static const JSJitInfo isTrusted_getterinfo = {
595 : { (JSJitGetterOp)get_isTrusted },
596 : { prototypes::id::ImageCaptureErrorEvent },
597 : { PrototypeTraits<prototypes::id::ImageCaptureErrorEvent>::Depth },
598 : JSJitInfo::Getter,
599 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
600 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
601 : true, /* isInfallible. False in setters. */
602 : true, /* isMovable. Not relevant for setters. */
603 : true, /* isEliminatable. Not relevant for setters. */
604 : false, /* isAlwaysInSlot. Only relevant for getters. */
605 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
606 : false, /* isTypedMethod. Only relevant for methods. */
607 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
608 : };
609 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
610 : static_assert(0 < 1, "There is no slot for us");
611 :
612 : static bool
613 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
614 : {
615 0 : mozilla::dom::ImageCaptureErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCaptureErrorEvent>(obj);
616 : // We don't want to preserve if we don't have a wrapper, and we
617 : // obviously can't preserve if we're not initialized.
618 0 : if (self && self->GetWrapperPreserveColor()) {
619 0 : PreserveWrapper(self);
620 : }
621 0 : return true;
622 : }
623 :
624 : static void
625 0 : _finalize(js::FreeOp* fop, JSObject* obj)
626 : {
627 0 : mozilla::dom::ImageCaptureErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCaptureErrorEvent>(obj);
628 0 : if (self) {
629 0 : ClearWrapper(self, self, obj);
630 0 : AddForDeferredFinalization<mozilla::dom::ImageCaptureErrorEvent>(self);
631 : }
632 0 : }
633 :
634 : static void
635 0 : _objectMoved(JSObject* obj, const JSObject* old)
636 : {
637 0 : mozilla::dom::ImageCaptureErrorEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ImageCaptureErrorEvent>(obj);
638 0 : if (self) {
639 0 : UpdateWrapper(self, self, obj, old);
640 : }
641 0 : }
642 :
643 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
644 : #if defined(__clang__)
645 : #pragma clang diagnostic push
646 : #pragma clang diagnostic ignored "-Wmissing-braces"
647 : #endif
648 : static const JSPropertySpec sAttributes_specs[] = {
649 : { "imageCaptureError", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &imageCaptureError_getterinfo, nullptr, nullptr },
650 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
651 : };
652 : #if defined(__clang__)
653 : #pragma clang diagnostic pop
654 : #endif
655 :
656 :
657 : // Can't be const because the pref-enabled boolean needs to be writable
658 : static Prefable<const JSPropertySpec> sAttributes[] = {
659 : { nullptr, &sAttributes_specs[0] },
660 : { nullptr, nullptr }
661 : };
662 :
663 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
664 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
665 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
666 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
667 :
668 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
669 : #if defined(__clang__)
670 : #pragma clang diagnostic push
671 : #pragma clang diagnostic ignored "-Wmissing-braces"
672 : #endif
673 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
674 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
675 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
676 : };
677 : #if defined(__clang__)
678 : #pragma clang diagnostic pop
679 : #endif
680 :
681 :
682 : // Can't be const because the pref-enabled boolean needs to be writable
683 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
684 : { nullptr, &sUnforgeableAttributes_specs[0] },
685 : { nullptr, nullptr }
686 : };
687 :
688 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
689 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
690 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
691 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
692 :
693 :
694 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
695 : static PropertyInfo sNativeProperties_propertyInfos[2];
696 :
697 : static const NativePropertiesN<2> sNativeProperties = {
698 : false, 0,
699 : false, 0,
700 : false, 0,
701 : true, 0 /* sAttributes */,
702 : false, 0,
703 : true, 1 /* sUnforgeableAttributes */,
704 : false, 0,
705 : -1,
706 : 2,
707 : sNativeProperties_sortedPropertyIndices,
708 : {
709 : { sAttributes, &sNativeProperties_propertyInfos[0] },
710 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
711 : }
712 : };
713 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
714 : "We have a property info count that is oversized");
715 :
716 : static bool
717 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
718 : {
719 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
720 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
721 0 : if (!args.isConstructing()) {
722 : // XXXbz wish I could get the name from the callee instead of
723 : // Adding more relocations
724 0 : return ThrowConstructorWithoutNew(cx, "ImageCaptureErrorEvent");
725 : }
726 :
727 0 : GlobalObject global(cx, obj);
728 0 : if (global.Failed()) {
729 0 : return false;
730 : }
731 :
732 0 : JS::Rooted<JSObject*> desiredProto(cx);
733 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
734 0 : return false;
735 : }
736 :
737 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
738 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ImageCaptureErrorEvent");
739 : }
740 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
741 0 : binding_detail::FakeString arg0;
742 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
743 0 : return false;
744 : }
745 0 : binding_detail::FastImageCaptureErrorEventInit arg1;
746 0 : if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue, "Argument 2 of ImageCaptureErrorEvent.constructor", false)) {
747 0 : return false;
748 : }
749 0 : Maybe<JSAutoCompartment> ac;
750 0 : if (objIsXray) {
751 0 : obj = js::CheckedUnwrap(obj);
752 0 : if (!obj) {
753 0 : return false;
754 : }
755 0 : ac.emplace(cx, obj);
756 0 : if (!JS_WrapObject(cx, &desiredProto)) {
757 0 : return false;
758 : }
759 : }
760 0 : binding_detail::FastErrorResult rv;
761 0 : auto result(StrongOrRawPtr<mozilla::dom::ImageCaptureErrorEvent>(mozilla::dom::ImageCaptureErrorEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
762 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
763 0 : return false;
764 : }
765 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
766 : static_assert(!IsPointer<decltype(result)>::value,
767 : "NewObject implies that we need to keep the object alive with a strong reference.");
768 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
769 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
770 0 : return false;
771 : }
772 0 : return true;
773 : }
774 :
775 : static const js::ClassOps sInterfaceObjectClassOps = {
776 : nullptr, /* addProperty */
777 : nullptr, /* delProperty */
778 : nullptr, /* getProperty */
779 : nullptr, /* setProperty */
780 : nullptr, /* enumerate */
781 : nullptr, /* newEnumerate */
782 : nullptr, /* resolve */
783 : nullptr, /* mayResolve */
784 : nullptr, /* finalize */
785 : _constructor, /* call */
786 : nullptr, /* hasInstance */
787 : _constructor, /* construct */
788 : nullptr, /* trace */
789 : };
790 :
791 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
792 : {
793 : "Function",
794 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
795 : &sInterfaceObjectClassOps,
796 : JS_NULL_CLASS_SPEC,
797 : JS_NULL_CLASS_EXT,
798 : &sInterfaceObjectClassObjectOps
799 : },
800 : eInterface,
801 : true,
802 : prototypes::id::ImageCaptureErrorEvent,
803 : PrototypeTraits<prototypes::id::ImageCaptureErrorEvent>::Depth,
804 : sNativePropertyHooks,
805 : "function ImageCaptureErrorEvent() {\n [native code]\n}",
806 : EventBinding::GetConstructorObject
807 : };
808 :
809 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
810 : {
811 : "ImageCaptureErrorEventPrototype",
812 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
813 : JS_NULL_CLASS_OPS,
814 : JS_NULL_CLASS_SPEC,
815 : JS_NULL_CLASS_EXT,
816 : JS_NULL_OBJECT_OPS
817 : },
818 : eInterfacePrototype,
819 : false,
820 : prototypes::id::ImageCaptureErrorEvent,
821 : PrototypeTraits<prototypes::id::ImageCaptureErrorEvent>::Depth,
822 : sNativePropertyHooks,
823 : "[object ImageCaptureErrorEventPrototype]",
824 : EventBinding::GetProtoObject
825 : };
826 :
827 : bool
828 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
829 : {
830 : static bool sPrefValue;
831 : static bool sPrefCacheSetUp = false;
832 0 : if (!sPrefCacheSetUp) {
833 0 : sPrefCacheSetUp = true;
834 0 : Preferences::AddBoolVarCache(&sPrefValue, "dom.imagecapture.enabled");
835 : }
836 :
837 0 : return sPrefValue;
838 : }
839 :
840 : JSObject*
841 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
842 : {
843 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
844 : }
845 :
846 : static const js::ClassOps sClassOps = {
847 : _addProperty, /* addProperty */
848 : nullptr, /* delProperty */
849 : nullptr, /* getProperty */
850 : nullptr, /* setProperty */
851 : nullptr, /* enumerate */
852 : nullptr, /* newEnumerate */
853 : nullptr, /* resolve */
854 : nullptr, /* mayResolve */
855 : _finalize, /* finalize */
856 : nullptr, /* call */
857 : nullptr, /* hasInstance */
858 : nullptr, /* construct */
859 : nullptr, /* trace */
860 : };
861 :
862 : static const js::ClassExtension sClassExtension = {
863 : nullptr, /* weakmapKeyDelegateOp */
864 : _objectMoved /* objectMovedOp */
865 : };
866 :
867 : static const DOMJSClass sClass = {
868 : { "ImageCaptureErrorEvent",
869 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
870 : &sClassOps,
871 : JS_NULL_CLASS_SPEC,
872 : &sClassExtension,
873 : JS_NULL_OBJECT_OPS
874 : },
875 : { prototypes::id::Event, prototypes::id::ImageCaptureErrorEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
876 : IsBaseOf<nsISupports, mozilla::dom::ImageCaptureErrorEvent >::value,
877 : sNativePropertyHooks,
878 : FindAssociatedGlobalForNative<mozilla::dom::ImageCaptureErrorEvent>::Get,
879 : GetProtoObjectHandle,
880 : GetCCParticipant<mozilla::dom::ImageCaptureErrorEvent>::Get()
881 : };
882 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
883 : "Must have the right minimal number of reserved slots.");
884 : static_assert(1 >= 1,
885 : "Must have enough reserved slots.");
886 :
887 : const JSClass*
888 0 : GetJSClass()
889 : {
890 0 : return sClass.ToJSClass();
891 : }
892 :
893 : bool
894 0 : Wrap(JSContext* aCx, mozilla::dom::ImageCaptureErrorEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
895 : {
896 : MOZ_ASSERT(static_cast<mozilla::dom::ImageCaptureErrorEvent*>(aObject) ==
897 : reinterpret_cast<mozilla::dom::ImageCaptureErrorEvent*>(aObject),
898 : "Multiple inheritance for mozilla::dom::ImageCaptureErrorEvent is broken.");
899 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
900 : reinterpret_cast<mozilla::dom::Event*>(aObject),
901 : "Multiple inheritance for mozilla::dom::Event is broken.");
902 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
903 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
904 0 : MOZ_ASSERT(!aCache->GetWrapper(),
905 : "You should probably not be using Wrap() directly; use "
906 : "GetOrCreateDOMReflector instead");
907 :
908 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
909 : "nsISupports must be on our primary inheritance chain");
910 :
911 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
912 0 : if (!global) {
913 0 : return false;
914 : }
915 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
916 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
917 :
918 : // That might have ended up wrapping us already, due to the wonders
919 : // of XBL. Check for that, and bail out as needed.
920 0 : aReflector.set(aCache->GetWrapper());
921 0 : if (aReflector) {
922 : #ifdef DEBUG
923 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
924 : #endif // DEBUG
925 0 : return true;
926 : }
927 :
928 0 : JSAutoCompartment ac(aCx, global);
929 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
930 0 : if (!canonicalProto) {
931 0 : return false;
932 : }
933 0 : JS::Rooted<JSObject*> proto(aCx);
934 0 : if (aGivenProto) {
935 0 : proto = aGivenProto;
936 : // Unfortunately, while aGivenProto was in the compartment of aCx
937 : // coming in, we changed compartments to that of "parent" so may need
938 : // to wrap the proto here.
939 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
940 0 : if (!JS_WrapObject(aCx, &proto)) {
941 0 : return false;
942 : }
943 : }
944 : } else {
945 0 : proto = canonicalProto;
946 : }
947 :
948 0 : BindingJSObjectCreator<mozilla::dom::ImageCaptureErrorEvent> creator(aCx);
949 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
950 0 : if (!aReflector) {
951 0 : return false;
952 : }
953 :
954 0 : aCache->SetWrapper(aReflector);
955 :
956 : // Important: do unforgeable property setup after we have handed
957 : // over ownership of the C++ object to obj as needed, so that if
958 : // we fail and it ends up GCed it won't have problems in the
959 : // finalizer trying to drop its ownership of the C++ object.
960 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
961 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
962 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
963 0 : aCache->ReleaseWrapper(aObject);
964 0 : aCache->ClearWrapper();
965 0 : return false;
966 : }
967 0 : creator.InitializationSucceeded();
968 :
969 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
970 : aCache->GetWrapperPreserveColor() == aReflector);
971 : // If proto != canonicalProto, we have to preserve our wrapper;
972 : // otherwise we won't be able to properly recreate it later, since
973 : // we won't know what proto to use. Note that we don't check
974 : // aGivenProto here, since it's entirely possible (and even
975 : // somewhat common) to have a non-null aGivenProto which is the
976 : // same as canonicalProto.
977 0 : if (proto != canonicalProto) {
978 0 : PreserveWrapper(aObject);
979 : }
980 :
981 0 : return true;
982 : }
983 :
984 : const NativePropertyHooks sNativePropertyHooks[] = { {
985 : nullptr,
986 : nullptr,
987 : nullptr,
988 : { sNativeProperties.Upcast(), nullptr },
989 : prototypes::id::ImageCaptureErrorEvent,
990 : constructors::id::ImageCaptureErrorEvent,
991 : EventBinding::sNativePropertyHooks,
992 : &DefaultXrayExpandoObjectClass
993 : } };
994 :
995 : void
996 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
997 : {
998 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
999 0 : if (!parentProto) {
1000 0 : return;
1001 : }
1002 :
1003 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
1004 0 : if (!constructorProto) {
1005 0 : return;
1006 : }
1007 :
1008 : static bool sIdsInited = false;
1009 0 : if (!sIdsInited && NS_IsMainThread()) {
1010 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1011 0 : return;
1012 : }
1013 0 : sIdsInited = true;
1014 : }
1015 :
1016 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ImageCaptureErrorEvent);
1017 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ImageCaptureErrorEvent);
1018 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1019 : &sPrototypeClass.mBase, protoCache,
1020 : constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
1021 : interfaceCache,
1022 : sNativeProperties.Upcast(),
1023 : nullptr,
1024 : "ImageCaptureErrorEvent", aDefineOnGlobal,
1025 : nullptr,
1026 0 : false);
1027 :
1028 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
1029 : {
1030 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
1031 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
1032 0 : if (!unforgeableHolder) {
1033 0 : *protoCache = nullptr;
1034 0 : if (interfaceCache) {
1035 0 : *interfaceCache = nullptr;
1036 : }
1037 0 : return;
1038 : }
1039 : }
1040 :
1041 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
1042 0 : *protoCache = nullptr;
1043 0 : if (interfaceCache) {
1044 0 : *interfaceCache = nullptr;
1045 : }
1046 0 : return;
1047 : }
1048 :
1049 0 : if (*protoCache) {
1050 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
1051 0 : JS::ObjectValue(*unforgeableHolder));
1052 : }
1053 : }
1054 :
1055 : JS::Handle<JSObject*>
1056 0 : GetProtoObjectHandle(JSContext* aCx)
1057 : {
1058 : /* Get the interface prototype object for this class. This will create the
1059 : object as needed. */
1060 0 : bool aDefineOnGlobal = true;
1061 :
1062 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1063 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1064 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1065 0 : return nullptr;
1066 : }
1067 :
1068 : /* Check to see whether the interface objects are already installed */
1069 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1070 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::ImageCaptureErrorEvent)) {
1071 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1072 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1073 : }
1074 :
1075 : /*
1076 : * The object might _still_ be null, but that's OK.
1077 : *
1078 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1079 : * traced by TraceProtoAndIfaceCache() and its contents are never
1080 : * changed after they have been set.
1081 : *
1082 : * Calling address() avoids the read read barrier that does gray
1083 : * unmarking, but it's not possible for the object to be gray here.
1084 : */
1085 :
1086 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::ImageCaptureErrorEvent);
1087 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1088 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1089 : }
1090 :
1091 : JS::Handle<JSObject*>
1092 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1093 : {
1094 : /* Get the interface object for this class. This will create the object as
1095 : needed. */
1096 :
1097 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1098 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1099 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1100 0 : return nullptr;
1101 : }
1102 :
1103 : /* Check to see whether the interface objects are already installed */
1104 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1105 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::ImageCaptureErrorEvent)) {
1106 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1107 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1108 : }
1109 :
1110 : /*
1111 : * The object might _still_ be null, but that's OK.
1112 : *
1113 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1114 : * traced by TraceProtoAndIfaceCache() and its contents are never
1115 : * changed after they have been set.
1116 : *
1117 : * Calling address() avoids the read read barrier that does gray
1118 : * unmarking, but it's not possible for the object to be gray here.
1119 : */
1120 :
1121 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::ImageCaptureErrorEvent);
1122 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1123 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1124 : }
1125 :
1126 : JSObject*
1127 0 : GetConstructorObject(JSContext* aCx)
1128 : {
1129 0 : return GetConstructorObjectHandle(aCx);
1130 : }
1131 :
1132 : } // namespace ImageCaptureErrorEventBinding
1133 :
1134 :
1135 :
1136 : } // namespace dom
1137 : } // namespace mozilla
|