Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM MessageChannel.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "MessageChannelBinding.h"
4 : #include "WrapperFactory.h"
5 : #include "mozilla/OwningNonNull.h"
6 : #include "mozilla/dom/BindingUtils.h"
7 : #include "mozilla/dom/DOMJSClass.h"
8 : #include "mozilla/dom/MessageChannel.h"
9 : #include "mozilla/dom/MessagePort.h"
10 : #include "mozilla/dom/NonRefcountedDOMObject.h"
11 : #include "mozilla/dom/XrayExpandoClass.h"
12 :
13 : namespace mozilla {
14 : namespace dom {
15 :
16 : namespace MessageChannelBinding {
17 :
18 : static bool
19 0 : get_port1(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageChannel* self, JSJitGetterCallArgs args)
20 : {
21 0 : auto result(StrongOrRawPtr<mozilla::dom::MessagePort>(self->Port1()));
22 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
23 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
24 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
25 0 : return false;
26 : }
27 0 : return true;
28 : }
29 :
30 : static const JSJitInfo port1_getterinfo = {
31 : { (JSJitGetterOp)get_port1 },
32 : { prototypes::id::MessageChannel },
33 : { PrototypeTraits<prototypes::id::MessageChannel>::Depth },
34 : JSJitInfo::Getter,
35 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
36 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
37 : false, /* isInfallible. False in setters. */
38 : false, /* isMovable. Not relevant for setters. */
39 : false, /* isEliminatable. Not relevant for setters. */
40 : false, /* isAlwaysInSlot. Only relevant for getters. */
41 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
42 : false, /* isTypedMethod. Only relevant for methods. */
43 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
44 : };
45 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
46 : static_assert(0 < 1, "There is no slot for us");
47 :
48 : static bool
49 0 : get_port2(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MessageChannel* self, JSJitGetterCallArgs args)
50 : {
51 0 : auto result(StrongOrRawPtr<mozilla::dom::MessagePort>(self->Port2()));
52 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
53 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
54 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
55 0 : return false;
56 : }
57 0 : return true;
58 : }
59 :
60 : static const JSJitInfo port2_getterinfo = {
61 : { (JSJitGetterOp)get_port2 },
62 : { prototypes::id::MessageChannel },
63 : { PrototypeTraits<prototypes::id::MessageChannel>::Depth },
64 : JSJitInfo::Getter,
65 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
66 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
67 : false, /* isInfallible. False in setters. */
68 : false, /* isMovable. Not relevant for setters. */
69 : false, /* isEliminatable. Not relevant for setters. */
70 : false, /* isAlwaysInSlot. Only relevant for getters. */
71 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
72 : false, /* isTypedMethod. Only relevant for methods. */
73 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
74 : };
75 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
76 : static_assert(0 < 1, "There is no slot for us");
77 :
78 : static bool
79 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
80 : {
81 0 : mozilla::dom::MessageChannel* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageChannel>(obj);
82 : // We don't want to preserve if we don't have a wrapper, and we
83 : // obviously can't preserve if we're not initialized.
84 0 : if (self && self->GetWrapperPreserveColor()) {
85 0 : PreserveWrapper(self);
86 : }
87 0 : return true;
88 : }
89 :
90 : static void
91 0 : _finalize(js::FreeOp* fop, JSObject* obj)
92 : {
93 0 : mozilla::dom::MessageChannel* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageChannel>(obj);
94 0 : if (self) {
95 0 : ClearWrapper(self, self, obj);
96 0 : AddForDeferredFinalization<mozilla::dom::MessageChannel>(self);
97 : }
98 0 : }
99 :
100 : static void
101 0 : _objectMoved(JSObject* obj, const JSObject* old)
102 : {
103 0 : mozilla::dom::MessageChannel* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MessageChannel>(obj);
104 0 : if (self) {
105 0 : UpdateWrapper(self, self, obj, old);
106 : }
107 0 : }
108 :
109 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
110 : #if defined(__clang__)
111 : #pragma clang diagnostic push
112 : #pragma clang diagnostic ignored "-Wmissing-braces"
113 : #endif
114 : static const JSPropertySpec sAttributes_specs[] = {
115 : { "port1", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &port1_getterinfo, nullptr, nullptr },
116 : { "port2", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &port2_getterinfo, nullptr, nullptr },
117 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
118 : };
119 : #if defined(__clang__)
120 : #pragma clang diagnostic pop
121 : #endif
122 :
123 :
124 : // Can't be const because the pref-enabled boolean needs to be writable
125 : static Prefable<const JSPropertySpec> sAttributes[] = {
126 : { nullptr, &sAttributes_specs[0] },
127 : { nullptr, nullptr }
128 : };
129 :
130 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
131 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
132 : static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
133 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
134 :
135 :
136 : static uint16_t sNativeProperties_sortedPropertyIndices[2];
137 : static PropertyInfo sNativeProperties_propertyInfos[2];
138 :
139 : static const NativePropertiesN<1> sNativeProperties = {
140 : false, 0,
141 : false, 0,
142 : false, 0,
143 : true, 0 /* sAttributes */,
144 : false, 0,
145 : false, 0,
146 : false, 0,
147 : -1,
148 : 2,
149 : sNativeProperties_sortedPropertyIndices,
150 : {
151 : { sAttributes, &sNativeProperties_propertyInfos[0] }
152 : }
153 : };
154 : static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
155 : "We have a property info count that is oversized");
156 :
157 : static bool
158 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
159 : {
160 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
161 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
162 0 : if (!args.isConstructing()) {
163 : // XXXbz wish I could get the name from the callee instead of
164 : // Adding more relocations
165 0 : return ThrowConstructorWithoutNew(cx, "MessageChannel");
166 : }
167 :
168 0 : GlobalObject global(cx, obj);
169 0 : if (global.Failed()) {
170 0 : return false;
171 : }
172 :
173 0 : JS::Rooted<JSObject*> desiredProto(cx);
174 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
175 0 : return false;
176 : }
177 :
178 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
179 0 : Maybe<JSAutoCompartment> ac;
180 0 : if (objIsXray) {
181 0 : obj = js::CheckedUnwrap(obj);
182 0 : if (!obj) {
183 0 : return false;
184 : }
185 0 : ac.emplace(cx, obj);
186 0 : if (!JS_WrapObject(cx, &desiredProto)) {
187 0 : return false;
188 : }
189 : }
190 0 : binding_detail::FastErrorResult rv;
191 0 : auto result(StrongOrRawPtr<mozilla::dom::MessageChannel>(mozilla::dom::MessageChannel::Constructor(global, rv)));
192 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
193 0 : return false;
194 : }
195 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
196 : static_assert(!IsPointer<decltype(result)>::value,
197 : "NewObject implies that we need to keep the object alive with a strong reference.");
198 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
199 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
200 0 : return false;
201 : }
202 0 : return true;
203 : }
204 :
205 : static const js::ClassOps sInterfaceObjectClassOps = {
206 : nullptr, /* addProperty */
207 : nullptr, /* delProperty */
208 : nullptr, /* getProperty */
209 : nullptr, /* setProperty */
210 : nullptr, /* enumerate */
211 : nullptr, /* newEnumerate */
212 : nullptr, /* resolve */
213 : nullptr, /* mayResolve */
214 : nullptr, /* finalize */
215 : _constructor, /* call */
216 : nullptr, /* hasInstance */
217 : _constructor, /* construct */
218 : nullptr, /* trace */
219 : };
220 :
221 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
222 : {
223 : "Function",
224 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
225 : &sInterfaceObjectClassOps,
226 : JS_NULL_CLASS_SPEC,
227 : JS_NULL_CLASS_EXT,
228 : &sInterfaceObjectClassObjectOps
229 : },
230 : eInterface,
231 : true,
232 : prototypes::id::MessageChannel,
233 : PrototypeTraits<prototypes::id::MessageChannel>::Depth,
234 : sNativePropertyHooks,
235 : "function MessageChannel() {\n [native code]\n}",
236 : JS::GetRealmFunctionPrototype
237 : };
238 :
239 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
240 : {
241 : "MessageChannelPrototype",
242 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
243 : JS_NULL_CLASS_OPS,
244 : JS_NULL_CLASS_SPEC,
245 : JS_NULL_CLASS_EXT,
246 : JS_NULL_OBJECT_OPS
247 : },
248 : eInterfacePrototype,
249 : false,
250 : prototypes::id::MessageChannel,
251 : PrototypeTraits<prototypes::id::MessageChannel>::Depth,
252 : sNativePropertyHooks,
253 : "[object MessageChannelPrototype]",
254 : JS::GetRealmObjectPrototype
255 : };
256 :
257 : JSObject*
258 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
259 : {
260 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
261 : }
262 :
263 : static const js::ClassOps sClassOps = {
264 : _addProperty, /* addProperty */
265 : nullptr, /* delProperty */
266 : nullptr, /* getProperty */
267 : nullptr, /* setProperty */
268 : nullptr, /* enumerate */
269 : nullptr, /* newEnumerate */
270 : nullptr, /* resolve */
271 : nullptr, /* mayResolve */
272 : _finalize, /* finalize */
273 : nullptr, /* call */
274 : nullptr, /* hasInstance */
275 : nullptr, /* construct */
276 : nullptr, /* trace */
277 : };
278 :
279 : static const js::ClassExtension sClassExtension = {
280 : nullptr, /* weakmapKeyDelegateOp */
281 : _objectMoved /* objectMovedOp */
282 : };
283 :
284 : static const DOMJSClass sClass = {
285 : { "MessageChannel",
286 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
287 : &sClassOps,
288 : JS_NULL_CLASS_SPEC,
289 : &sClassExtension,
290 : JS_NULL_OBJECT_OPS
291 : },
292 : { prototypes::id::MessageChannel, 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 },
293 : IsBaseOf<nsISupports, mozilla::dom::MessageChannel >::value,
294 : sNativePropertyHooks,
295 : FindAssociatedGlobalForNative<mozilla::dom::MessageChannel>::Get,
296 : GetProtoObjectHandle,
297 : GetCCParticipant<mozilla::dom::MessageChannel>::Get()
298 : };
299 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
300 : "Must have the right minimal number of reserved slots.");
301 : static_assert(1 >= 1,
302 : "Must have enough reserved slots.");
303 :
304 : const JSClass*
305 0 : GetJSClass()
306 : {
307 0 : return sClass.ToJSClass();
308 : }
309 :
310 : bool
311 0 : Wrap(JSContext* aCx, mozilla::dom::MessageChannel* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
312 : {
313 : MOZ_ASSERT(static_cast<mozilla::dom::MessageChannel*>(aObject) ==
314 : reinterpret_cast<mozilla::dom::MessageChannel*>(aObject),
315 : "Multiple inheritance for mozilla::dom::MessageChannel is broken.");
316 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
317 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
318 0 : MOZ_ASSERT(!aCache->GetWrapper(),
319 : "You should probably not be using Wrap() directly; use "
320 : "GetOrCreateDOMReflector instead");
321 :
322 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
323 : "nsISupports must be on our primary inheritance chain");
324 :
325 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
326 0 : if (!global) {
327 0 : return false;
328 : }
329 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
330 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
331 :
332 : // That might have ended up wrapping us already, due to the wonders
333 : // of XBL. Check for that, and bail out as needed.
334 0 : aReflector.set(aCache->GetWrapper());
335 0 : if (aReflector) {
336 : #ifdef DEBUG
337 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
338 : #endif // DEBUG
339 0 : return true;
340 : }
341 :
342 0 : JSAutoCompartment ac(aCx, global);
343 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
344 0 : if (!canonicalProto) {
345 0 : return false;
346 : }
347 0 : JS::Rooted<JSObject*> proto(aCx);
348 0 : if (aGivenProto) {
349 0 : proto = aGivenProto;
350 : // Unfortunately, while aGivenProto was in the compartment of aCx
351 : // coming in, we changed compartments to that of "parent" so may need
352 : // to wrap the proto here.
353 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
354 0 : if (!JS_WrapObject(aCx, &proto)) {
355 0 : return false;
356 : }
357 : }
358 : } else {
359 0 : proto = canonicalProto;
360 : }
361 :
362 0 : BindingJSObjectCreator<mozilla::dom::MessageChannel> creator(aCx);
363 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
364 0 : if (!aReflector) {
365 0 : return false;
366 : }
367 :
368 0 : aCache->SetWrapper(aReflector);
369 0 : creator.InitializationSucceeded();
370 :
371 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
372 : aCache->GetWrapperPreserveColor() == aReflector);
373 : // If proto != canonicalProto, we have to preserve our wrapper;
374 : // otherwise we won't be able to properly recreate it later, since
375 : // we won't know what proto to use. Note that we don't check
376 : // aGivenProto here, since it's entirely possible (and even
377 : // somewhat common) to have a non-null aGivenProto which is the
378 : // same as canonicalProto.
379 0 : if (proto != canonicalProto) {
380 0 : PreserveWrapper(aObject);
381 : }
382 :
383 0 : return true;
384 : }
385 :
386 : const NativePropertyHooks sNativePropertyHooks[] = { {
387 : nullptr,
388 : nullptr,
389 : nullptr,
390 : { sNativeProperties.Upcast(), nullptr },
391 : prototypes::id::MessageChannel,
392 : constructors::id::MessageChannel,
393 : nullptr,
394 : &DefaultXrayExpandoObjectClass
395 : } };
396 :
397 : void
398 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
399 : {
400 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
401 1 : if (!parentProto) {
402 0 : return;
403 : }
404 :
405 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
406 1 : if (!constructorProto) {
407 0 : return;
408 : }
409 :
410 : static bool sIdsInited = false;
411 1 : if (!sIdsInited && NS_IsMainThread()) {
412 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
413 0 : return;
414 : }
415 0 : sIdsInited = true;
416 : }
417 :
418 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MessageChannel);
419 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MessageChannel);
420 2 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
421 : &sPrototypeClass.mBase, protoCache,
422 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
423 : interfaceCache,
424 : sNativeProperties.Upcast(),
425 : nullptr,
426 : "MessageChannel", aDefineOnGlobal,
427 : nullptr,
428 1 : false);
429 : }
430 :
431 : JS::Handle<JSObject*>
432 0 : GetProtoObjectHandle(JSContext* aCx)
433 : {
434 : /* Get the interface prototype object for this class. This will create the
435 : object as needed. */
436 0 : bool aDefineOnGlobal = true;
437 :
438 : /* Make sure our global is sane. Hopefully we can remove this sometime */
439 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
440 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
441 0 : return nullptr;
442 : }
443 :
444 : /* Check to see whether the interface objects are already installed */
445 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
446 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MessageChannel)) {
447 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
448 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
449 : }
450 :
451 : /*
452 : * The object might _still_ be null, but that's OK.
453 : *
454 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
455 : * traced by TraceProtoAndIfaceCache() and its contents are never
456 : * changed after they have been set.
457 : *
458 : * Calling address() avoids the read read barrier that does gray
459 : * unmarking, but it's not possible for the object to be gray here.
460 : */
461 :
462 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MessageChannel);
463 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
464 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
465 : }
466 :
467 : JS::Handle<JSObject*>
468 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
469 : {
470 : /* Get the interface object for this class. This will create the object as
471 : needed. */
472 :
473 : /* Make sure our global is sane. Hopefully we can remove this sometime */
474 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
475 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
476 0 : return nullptr;
477 : }
478 :
479 : /* Check to see whether the interface objects are already installed */
480 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
481 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MessageChannel)) {
482 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
483 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
484 : }
485 :
486 : /*
487 : * The object might _still_ be null, but that's OK.
488 : *
489 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
490 : * traced by TraceProtoAndIfaceCache() and its contents are never
491 : * changed after they have been set.
492 : *
493 : * Calling address() avoids the read read barrier that does gray
494 : * unmarking, but it's not possible for the object to be gray here.
495 : */
496 :
497 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MessageChannel);
498 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
499 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
500 : }
501 :
502 : JSObject*
503 1 : GetConstructorObject(JSContext* aCx)
504 : {
505 1 : return GetConstructorObjectHandle(aCx);
506 : }
507 :
508 : } // namespace MessageChannelBinding
509 :
510 :
511 :
512 : } // namespace dom
513 : } // namespace mozilla
|