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