Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM MediaStreamTrackEvent.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "AtomList.h"
4 : #include "EventBinding.h"
5 : #include "MediaStreamTrackEventBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "mozilla/OwningNonNull.h"
8 : #include "mozilla/dom/BindingUtils.h"
9 : #include "mozilla/dom/DOMJSClass.h"
10 : #include "mozilla/dom/MediaStreamTrack.h"
11 : #include "mozilla/dom/MediaStreamTrackEvent.h"
12 : #include "mozilla/dom/NonRefcountedDOMObject.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/ScriptSettings.h"
15 : #include "mozilla/dom/XrayExpandoClass.h"
16 :
17 : namespace mozilla {
18 : namespace dom {
19 :
20 :
21 0 : MediaStreamTrackEventInit::MediaStreamTrackEventInit()
22 0 : : EventInit(FastDictionaryInitializer())
23 : {
24 : // Safe to pass a null context if we pass a null value
25 0 : Init(nullptr, JS::NullHandleValue);
26 0 : }
27 :
28 :
29 :
30 : bool
31 0 : MediaStreamTrackEventInit::InitIds(JSContext* cx, MediaStreamTrackEventInitAtoms* atomsCache)
32 : {
33 0 : MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
34 :
35 : // Initialize these in reverse order so that any failure leaves the first one
36 : // uninitialized.
37 0 : if (!atomsCache->track_id.init(cx, "track")) {
38 0 : return false;
39 : }
40 0 : return true;
41 : }
42 :
43 : bool
44 0 : MediaStreamTrackEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
45 : {
46 : // Passing a null JSContext is OK only if we're initing from null,
47 : // Since in that case we will not have to do any property gets
48 : // Also evaluate isNullOrUndefined in order to avoid false-positive
49 : // checkers by static analysis tools
50 0 : MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
51 0 : MediaStreamTrackEventInitAtoms* atomsCache = nullptr;
52 0 : if (cx) {
53 0 : atomsCache = GetAtomCache<MediaStreamTrackEventInitAtoms>(cx);
54 0 : if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
55 0 : return false;
56 : }
57 : }
58 :
59 : // Per spec, we init the parent's members first
60 0 : if (!EventInit::Init(cx, val)) {
61 0 : return false;
62 : }
63 :
64 0 : bool isNull = val.isNullOrUndefined();
65 : // We only need these if !isNull, in which case we have |cx|.
66 0 : Maybe<JS::Rooted<JSObject *> > object;
67 0 : Maybe<JS::Rooted<JS::Value> > temp;
68 0 : if (!isNull) {
69 0 : MOZ_ASSERT(cx);
70 0 : object.emplace(cx, &val.toObject());
71 0 : temp.emplace(cx);
72 : }
73 0 : if (!isNull) {
74 0 : if (!JS_GetPropertyById(cx, *object, atomsCache->track_id, temp.ptr())) {
75 0 : return false;
76 : }
77 : }
78 0 : if (!isNull && !temp->isUndefined()) {
79 0 : if (temp.ref().isObject()) {
80 : static_assert(IsRefcounted<mozilla::dom::MediaStreamTrack>::value, "We can only store refcounted classes.");{
81 0 : nsresult rv = UnwrapObject<prototypes::id::MediaStreamTrack, mozilla::dom::MediaStreamTrack>(temp.ptr(), mTrack);
82 0 : if (NS_FAILED(rv)) {
83 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'track' member of MediaStreamTrackEventInit", "MediaStreamTrack");
84 0 : return false;
85 : }
86 : }
87 : } else {
88 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'track' member of MediaStreamTrackEventInit");
89 0 : return false;
90 : }
91 0 : mIsAnyMemberPresent = true;
92 0 : } else if (cx) {
93 : // Don't error out if we have no cx. In that
94 : // situation the caller is default-constructing us and we'll
95 : // just assume they know what they're doing.
96 0 : return ThrowErrorMessage(cx, MSG_MISSING_REQUIRED_DICTIONARY_MEMBER,
97 0 : "'track' member of MediaStreamTrackEventInit");
98 : }
99 0 : return true;
100 : }
101 :
102 : bool
103 0 : MediaStreamTrackEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
104 : {
105 0 : MediaStreamTrackEventInitAtoms* atomsCache = GetAtomCache<MediaStreamTrackEventInitAtoms>(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 : OwningNonNull<mozilla::dom::MediaStreamTrack> const & currentValue = mTrack;
120 0 : if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
121 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
122 0 : return false;
123 : }
124 0 : if (!JS_DefinePropertyById(cx, obj, atomsCache->track_id, temp, JSPROP_ENUMERATE)) {
125 0 : return false;
126 : }
127 0 : break;
128 : } while(0);
129 :
130 0 : return true;
131 : }
132 :
133 : void
134 0 : MediaStreamTrackEventInit::TraceDictionary(JSTracer* trc)
135 : {
136 0 : EventInit::TraceDictionary(trc);
137 0 : }
138 :
139 : MediaStreamTrackEventInit&
140 0 : MediaStreamTrackEventInit::operator=(const MediaStreamTrackEventInit& aOther)
141 : {
142 0 : EventInit::operator=(aOther);
143 0 : mTrack = aOther.mTrack;
144 0 : return *this;
145 : }
146 :
147 : namespace binding_detail {
148 : } // namespace binding_detail
149 :
150 :
151 : namespace MediaStreamTrackEventBinding {
152 :
153 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventBinding::NativeType>::value,
154 : "Can't inherit from an interface with a different ownership model.");
155 :
156 : static bool
157 0 : get_track(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaStreamTrackEvent* self, JSJitGetterCallArgs args)
158 : {
159 0 : auto result(StrongOrRawPtr<mozilla::dom::MediaStreamTrack>(self->Track()));
160 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
161 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
162 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
163 0 : return false;
164 : }
165 0 : return true;
166 : }
167 :
168 : static const JSJitInfo track_getterinfo = {
169 : { (JSJitGetterOp)get_track },
170 : { prototypes::id::MediaStreamTrackEvent },
171 : { PrototypeTraits<prototypes::id::MediaStreamTrackEvent>::Depth },
172 : JSJitInfo::Getter,
173 : JSJitInfo::AliasNone, /* aliasSet. Not relevant for setters. */
174 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
175 : false, /* isInfallible. False in setters. */
176 : true, /* isMovable. Not relevant for setters. */
177 : true, /* isEliminatable. Not relevant for setters. */
178 : false, /* isAlwaysInSlot. Only relevant for getters. */
179 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
180 : false, /* isTypedMethod. Only relevant for methods. */
181 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
182 : };
183 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
184 : static_assert(0 < 1, "There is no slot for us");
185 :
186 : static bool
187 0 : get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaStreamTrackEvent* self, JSJitGetterCallArgs args)
188 : {
189 0 : bool result(self->IsTrusted());
190 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
191 0 : args.rval().setBoolean(result);
192 0 : return true;
193 : }
194 :
195 : static const JSJitInfo isTrusted_getterinfo = {
196 : { (JSJitGetterOp)get_isTrusted },
197 : { prototypes::id::MediaStreamTrackEvent },
198 : { PrototypeTraits<prototypes::id::MediaStreamTrackEvent>::Depth },
199 : JSJitInfo::Getter,
200 : JSJitInfo::AliasDOMSets, /* aliasSet. Not relevant for setters. */
201 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
202 : true, /* isInfallible. False in setters. */
203 : true, /* isMovable. Not relevant for setters. */
204 : true, /* isEliminatable. Not relevant for setters. */
205 : false, /* isAlwaysInSlot. Only relevant for getters. */
206 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
207 : false, /* isTypedMethod. Only relevant for methods. */
208 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
209 : };
210 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
211 : static_assert(0 < 1, "There is no slot for us");
212 :
213 : static bool
214 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
215 : {
216 0 : mozilla::dom::MediaStreamTrackEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamTrackEvent>(obj);
217 : // We don't want to preserve if we don't have a wrapper, and we
218 : // obviously can't preserve if we're not initialized.
219 0 : if (self && self->GetWrapperPreserveColor()) {
220 0 : PreserveWrapper(self);
221 : }
222 0 : return true;
223 : }
224 :
225 : static void
226 0 : _finalize(js::FreeOp* fop, JSObject* obj)
227 : {
228 0 : mozilla::dom::MediaStreamTrackEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamTrackEvent>(obj);
229 0 : if (self) {
230 0 : ClearWrapper(self, self, obj);
231 0 : AddForDeferredFinalization<mozilla::dom::MediaStreamTrackEvent>(self);
232 : }
233 0 : }
234 :
235 : static void
236 0 : _objectMoved(JSObject* obj, const JSObject* old)
237 : {
238 0 : mozilla::dom::MediaStreamTrackEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaStreamTrackEvent>(obj);
239 0 : if (self) {
240 0 : UpdateWrapper(self, self, obj, old);
241 : }
242 0 : }
243 :
244 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
245 : #if defined(__clang__)
246 : #pragma clang diagnostic push
247 : #pragma clang diagnostic ignored "-Wmissing-braces"
248 : #endif
249 : static const JSPropertySpec sAttributes_specs[] = {
250 : { "track", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &track_getterinfo, nullptr, nullptr },
251 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
252 : };
253 : #if defined(__clang__)
254 : #pragma clang diagnostic pop
255 : #endif
256 :
257 :
258 : // Can't be const because the pref-enabled boolean needs to be writable
259 : static Prefable<const JSPropertySpec> sAttributes[] = {
260 : { nullptr, &sAttributes_specs[0] },
261 : { nullptr, nullptr }
262 : };
263 :
264 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
265 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
266 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
267 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
268 :
269 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
270 : #if defined(__clang__)
271 : #pragma clang diagnostic push
272 : #pragma clang diagnostic ignored "-Wmissing-braces"
273 : #endif
274 : static const JSPropertySpec sUnforgeableAttributes_specs[] = {
275 : { "isTrusted", JSPROP_SHARED | JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericBindingGetter, &isTrusted_getterinfo, nullptr, nullptr },
276 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
277 : };
278 : #if defined(__clang__)
279 : #pragma clang diagnostic pop
280 : #endif
281 :
282 :
283 : // Can't be const because the pref-enabled boolean needs to be writable
284 : static Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
285 : { nullptr, &sUnforgeableAttributes_specs[0] },
286 : { nullptr, nullptr }
287 : };
288 :
289 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
290 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
291 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
292 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
293 :
294 :
295 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
296 : static PropertyInfo sNativeProperties_propertyInfos[2];
297 :
298 : static const NativePropertiesN<2> sNativeProperties = {
299 : false, 0,
300 : false, 0,
301 : false, 0,
302 : true, 0 /* sAttributes */,
303 : false, 0,
304 : true, 1 /* sUnforgeableAttributes */,
305 : false, 0,
306 : -1,
307 : 2,
308 : sNativeProperties_sortedPropertyIndices,
309 : {
310 : { sAttributes, &sNativeProperties_propertyInfos[0] },
311 : { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
312 : }
313 : };
314 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
315 : "We have a property info count that is oversized");
316 :
317 : static bool
318 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
319 : {
320 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
321 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
322 0 : if (!args.isConstructing()) {
323 : // XXXbz wish I could get the name from the callee instead of
324 : // Adding more relocations
325 0 : return ThrowConstructorWithoutNew(cx, "MediaStreamTrackEvent");
326 : }
327 :
328 0 : GlobalObject global(cx, obj);
329 0 : if (global.Failed()) {
330 0 : return false;
331 : }
332 :
333 0 : JS::Rooted<JSObject*> desiredProto(cx);
334 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
335 0 : return false;
336 : }
337 :
338 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
339 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaStreamTrackEvent");
340 : }
341 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
342 0 : binding_detail::FakeString arg0;
343 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
344 0 : return false;
345 : }
346 0 : binding_detail::FastMediaStreamTrackEventInit arg1;
347 0 : if (!arg1.Init(cx, args[1], "Argument 2 of MediaStreamTrackEvent.constructor", false)) {
348 0 : return false;
349 : }
350 0 : Maybe<JSAutoCompartment> ac;
351 0 : if (objIsXray) {
352 0 : obj = js::CheckedUnwrap(obj);
353 0 : if (!obj) {
354 0 : return false;
355 : }
356 0 : ac.emplace(cx, obj);
357 0 : if (!JS_WrapObject(cx, &desiredProto)) {
358 0 : return false;
359 : }
360 : }
361 0 : binding_detail::FastErrorResult rv;
362 0 : auto result(StrongOrRawPtr<mozilla::dom::MediaStreamTrackEvent>(mozilla::dom::MediaStreamTrackEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
363 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
364 0 : return false;
365 : }
366 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
367 : static_assert(!IsPointer<decltype(result)>::value,
368 : "NewObject implies that we need to keep the object alive with a strong reference.");
369 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
370 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
371 0 : return false;
372 : }
373 0 : return true;
374 : }
375 :
376 : static const js::ClassOps sInterfaceObjectClassOps = {
377 : nullptr, /* addProperty */
378 : nullptr, /* delProperty */
379 : nullptr, /* getProperty */
380 : nullptr, /* setProperty */
381 : nullptr, /* enumerate */
382 : nullptr, /* newEnumerate */
383 : nullptr, /* resolve */
384 : nullptr, /* mayResolve */
385 : nullptr, /* finalize */
386 : _constructor, /* call */
387 : nullptr, /* hasInstance */
388 : _constructor, /* construct */
389 : nullptr, /* trace */
390 : };
391 :
392 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
393 : {
394 : "Function",
395 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
396 : &sInterfaceObjectClassOps,
397 : JS_NULL_CLASS_SPEC,
398 : JS_NULL_CLASS_EXT,
399 : &sInterfaceObjectClassObjectOps
400 : },
401 : eInterface,
402 : true,
403 : prototypes::id::MediaStreamTrackEvent,
404 : PrototypeTraits<prototypes::id::MediaStreamTrackEvent>::Depth,
405 : sNativePropertyHooks,
406 : "function MediaStreamTrackEvent() {\n [native code]\n}",
407 : EventBinding::GetConstructorObject
408 : };
409 :
410 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
411 : {
412 : "MediaStreamTrackEventPrototype",
413 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
414 : JS_NULL_CLASS_OPS,
415 : JS_NULL_CLASS_SPEC,
416 : JS_NULL_CLASS_EXT,
417 : JS_NULL_OBJECT_OPS
418 : },
419 : eInterfacePrototype,
420 : false,
421 : prototypes::id::MediaStreamTrackEvent,
422 : PrototypeTraits<prototypes::id::MediaStreamTrackEvent>::Depth,
423 : sNativePropertyHooks,
424 : "[object MediaStreamTrackEventPrototype]",
425 : EventBinding::GetProtoObject
426 : };
427 :
428 : JSObject*
429 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
430 : {
431 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
432 : }
433 :
434 : static const js::ClassOps sClassOps = {
435 : _addProperty, /* addProperty */
436 : nullptr, /* delProperty */
437 : nullptr, /* getProperty */
438 : nullptr, /* setProperty */
439 : nullptr, /* enumerate */
440 : nullptr, /* newEnumerate */
441 : nullptr, /* resolve */
442 : nullptr, /* mayResolve */
443 : _finalize, /* finalize */
444 : nullptr, /* call */
445 : nullptr, /* hasInstance */
446 : nullptr, /* construct */
447 : nullptr, /* trace */
448 : };
449 :
450 : static const js::ClassExtension sClassExtension = {
451 : nullptr, /* weakmapKeyDelegateOp */
452 : _objectMoved /* objectMovedOp */
453 : };
454 :
455 : static const DOMJSClass sClass = {
456 : { "MediaStreamTrackEvent",
457 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
458 : &sClassOps,
459 : JS_NULL_CLASS_SPEC,
460 : &sClassExtension,
461 : JS_NULL_OBJECT_OPS
462 : },
463 : { prototypes::id::Event, prototypes::id::MediaStreamTrackEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
464 : IsBaseOf<nsISupports, mozilla::dom::MediaStreamTrackEvent >::value,
465 : sNativePropertyHooks,
466 : FindAssociatedGlobalForNative<mozilla::dom::MediaStreamTrackEvent>::Get,
467 : GetProtoObjectHandle,
468 : GetCCParticipant<mozilla::dom::MediaStreamTrackEvent>::Get()
469 : };
470 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
471 : "Must have the right minimal number of reserved slots.");
472 : static_assert(1 >= 1,
473 : "Must have enough reserved slots.");
474 :
475 : const JSClass*
476 0 : GetJSClass()
477 : {
478 0 : return sClass.ToJSClass();
479 : }
480 :
481 : bool
482 0 : Wrap(JSContext* aCx, mozilla::dom::MediaStreamTrackEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
483 : {
484 : MOZ_ASSERT(static_cast<mozilla::dom::MediaStreamTrackEvent*>(aObject) ==
485 : reinterpret_cast<mozilla::dom::MediaStreamTrackEvent*>(aObject),
486 : "Multiple inheritance for mozilla::dom::MediaStreamTrackEvent is broken.");
487 : MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
488 : reinterpret_cast<mozilla::dom::Event*>(aObject),
489 : "Multiple inheritance for mozilla::dom::Event is broken.");
490 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
491 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
492 0 : MOZ_ASSERT(!aCache->GetWrapper(),
493 : "You should probably not be using Wrap() directly; use "
494 : "GetOrCreateDOMReflector instead");
495 :
496 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
497 : "nsISupports must be on our primary inheritance chain");
498 :
499 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
500 0 : if (!global) {
501 0 : return false;
502 : }
503 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
504 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
505 :
506 : // That might have ended up wrapping us already, due to the wonders
507 : // of XBL. Check for that, and bail out as needed.
508 0 : aReflector.set(aCache->GetWrapper());
509 0 : if (aReflector) {
510 : #ifdef DEBUG
511 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
512 : #endif // DEBUG
513 0 : return true;
514 : }
515 :
516 0 : JSAutoCompartment ac(aCx, global);
517 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
518 0 : if (!canonicalProto) {
519 0 : return false;
520 : }
521 0 : JS::Rooted<JSObject*> proto(aCx);
522 0 : if (aGivenProto) {
523 0 : proto = aGivenProto;
524 : // Unfortunately, while aGivenProto was in the compartment of aCx
525 : // coming in, we changed compartments to that of "parent" so may need
526 : // to wrap the proto here.
527 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
528 0 : if (!JS_WrapObject(aCx, &proto)) {
529 0 : return false;
530 : }
531 : }
532 : } else {
533 0 : proto = canonicalProto;
534 : }
535 :
536 0 : BindingJSObjectCreator<mozilla::dom::MediaStreamTrackEvent> creator(aCx);
537 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
538 0 : if (!aReflector) {
539 0 : return false;
540 : }
541 :
542 0 : aCache->SetWrapper(aReflector);
543 :
544 : // Important: do unforgeable property setup after we have handed
545 : // over ownership of the C++ object to obj as needed, so that if
546 : // we fail and it ends up GCed it won't have problems in the
547 : // finalizer trying to drop its ownership of the C++ object.
548 : JS::Rooted<JSObject*> unforgeableHolder(aCx,
549 0 : &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
550 0 : if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
551 0 : aCache->ReleaseWrapper(aObject);
552 0 : aCache->ClearWrapper();
553 0 : return false;
554 : }
555 0 : creator.InitializationSucceeded();
556 :
557 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
558 : aCache->GetWrapperPreserveColor() == aReflector);
559 : // If proto != canonicalProto, we have to preserve our wrapper;
560 : // otherwise we won't be able to properly recreate it later, since
561 : // we won't know what proto to use. Note that we don't check
562 : // aGivenProto here, since it's entirely possible (and even
563 : // somewhat common) to have a non-null aGivenProto which is the
564 : // same as canonicalProto.
565 0 : if (proto != canonicalProto) {
566 0 : PreserveWrapper(aObject);
567 : }
568 :
569 0 : return true;
570 : }
571 :
572 : const NativePropertyHooks sNativePropertyHooks[] = { {
573 : nullptr,
574 : nullptr,
575 : nullptr,
576 : { sNativeProperties.Upcast(), nullptr },
577 : prototypes::id::MediaStreamTrackEvent,
578 : constructors::id::MediaStreamTrackEvent,
579 : EventBinding::sNativePropertyHooks,
580 : &DefaultXrayExpandoObjectClass
581 : } };
582 :
583 : void
584 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
585 : {
586 0 : JS::Handle<JSObject*> parentProto(EventBinding::GetProtoObjectHandle(aCx));
587 0 : if (!parentProto) {
588 0 : return;
589 : }
590 :
591 0 : JS::Handle<JSObject*> constructorProto(EventBinding::GetConstructorObjectHandle(aCx));
592 0 : if (!constructorProto) {
593 0 : return;
594 : }
595 :
596 : static bool sIdsInited = false;
597 0 : if (!sIdsInited && NS_IsMainThread()) {
598 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
599 0 : return;
600 : }
601 0 : sIdsInited = true;
602 : }
603 :
604 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaStreamTrackEvent);
605 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaStreamTrackEvent);
606 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
607 : &sPrototypeClass.mBase, protoCache,
608 : constructorProto, &sInterfaceObjectClass.mBase, 2, nullptr,
609 : interfaceCache,
610 : sNativeProperties.Upcast(),
611 : nullptr,
612 : "MediaStreamTrackEvent", aDefineOnGlobal,
613 : nullptr,
614 0 : false);
615 :
616 0 : JS::Rooted<JSObject*> unforgeableHolder(aCx);
617 : {
618 0 : JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
619 0 : unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
620 0 : if (!unforgeableHolder) {
621 0 : *protoCache = nullptr;
622 0 : if (interfaceCache) {
623 0 : *interfaceCache = nullptr;
624 : }
625 0 : return;
626 : }
627 : }
628 :
629 0 : if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
630 0 : *protoCache = nullptr;
631 0 : if (interfaceCache) {
632 0 : *interfaceCache = nullptr;
633 : }
634 0 : return;
635 : }
636 :
637 0 : if (*protoCache) {
638 0 : js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
639 0 : JS::ObjectValue(*unforgeableHolder));
640 : }
641 : }
642 :
643 : JS::Handle<JSObject*>
644 0 : GetProtoObjectHandle(JSContext* aCx)
645 : {
646 : /* Get the interface prototype object for this class. This will create the
647 : object as needed. */
648 0 : bool aDefineOnGlobal = true;
649 :
650 : /* Make sure our global is sane. Hopefully we can remove this sometime */
651 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
652 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
653 0 : return nullptr;
654 : }
655 :
656 : /* Check to see whether the interface objects are already installed */
657 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
658 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MediaStreamTrackEvent)) {
659 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
660 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
661 : }
662 :
663 : /*
664 : * The object might _still_ be null, but that's OK.
665 : *
666 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
667 : * traced by TraceProtoAndIfaceCache() and its contents are never
668 : * changed after they have been set.
669 : *
670 : * Calling address() avoids the read read barrier that does gray
671 : * unmarking, but it's not possible for the object to be gray here.
672 : */
673 :
674 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MediaStreamTrackEvent);
675 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
676 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
677 : }
678 :
679 : JS::Handle<JSObject*>
680 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
681 : {
682 : /* Get the interface object for this class. This will create the object as
683 : needed. */
684 :
685 : /* Make sure our global is sane. Hopefully we can remove this sometime */
686 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
687 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
688 0 : return nullptr;
689 : }
690 :
691 : /* Check to see whether the interface objects are already installed */
692 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
693 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MediaStreamTrackEvent)) {
694 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
695 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
696 : }
697 :
698 : /*
699 : * The object might _still_ be null, but that's OK.
700 : *
701 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
702 : * traced by TraceProtoAndIfaceCache() and its contents are never
703 : * changed after they have been set.
704 : *
705 : * Calling address() avoids the read read barrier that does gray
706 : * unmarking, but it's not possible for the object to be gray here.
707 : */
708 :
709 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MediaStreamTrackEvent);
710 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
711 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
712 : }
713 :
714 : JSObject*
715 0 : GetConstructorObject(JSContext* aCx)
716 : {
717 0 : return GetConstructorObjectHandle(aCx);
718 : }
719 :
720 : } // namespace MediaStreamTrackEventBinding
721 :
722 :
723 :
724 : } // namespace dom
725 : } // namespace mozilla
|