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