Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/CSSMediaRuleBinding.cpp
Line
Count
Source (jump to first uncovered line)
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 binding_detail {}; // Just to make sure it's known as a namespace
18
using namespace mozilla::dom::binding_detail;
19
20
21
namespace CSSMediaRule_Binding {
22
23
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<CSSConditionRule_Binding::NativeType>::value,
24
              "Can't inherit from an interface with a different ownership model.");
25
26
MOZ_CAN_RUN_SCRIPT static bool
27
get_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSMediaRule* self, JSJitGetterCallArgs args)
28
0
{
29
0
  AUTO_PROFILER_LABEL_FAST("get CSSMediaRule.media", DOM, cx);
30
0
31
0
  auto result(StrongOrRawPtr<mozilla::dom::MediaList>(self->Media()));
32
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
33
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
34
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
35
0
    return false;
36
0
  }
37
0
  return true;
38
0
}
39
40
MOZ_CAN_RUN_SCRIPT static bool
41
set_media(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CSSMediaRule* self, JSJitSetterCallArgs args)
42
0
{
43
0
  AUTO_PROFILER_LABEL_FAST("set CSSMediaRule.media", DOM, cx);
44
0
45
0
  JS::Rooted<JS::Value> v(cx);
46
0
  if (!JS_GetProperty(cx, obj, "media", &v)) {
47
0
    return false;
48
0
  }
49
0
50
0
  if (!v.isObject()) {
51
0
    return ThrowErrorMessage(cx, MSG_NOT_OBJECT, "CSSMediaRule.media");
52
0
  }
53
0
54
0
  JS::Rooted<JSObject*> targetObj(cx, &v.toObject());
55
0
  return JS_SetProperty(cx, targetObj, "mediaText", args[0]);
56
0
}
57
58
static const JSJitInfo media_getterinfo = {
59
  { (JSJitGetterOp)get_media },
60
  { prototypes::id::CSSMediaRule },
61
  { PrototypeTraits<prototypes::id::CSSMediaRule>::Depth },
62
  JSJitInfo::Getter,
63
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
64
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
65
  false,  /* isInfallible. False in setters. */
66
  true,  /* isMovable.  Not relevant for setters. */
67
  true, /* isEliminatable.  Not relevant for setters. */
68
  false, /* isAlwaysInSlot.  Only relevant for getters. */
69
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
70
  false,  /* isTypedMethod.  Only relevant for methods. */
71
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
72
};
73
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
74
static_assert(0 < 1, "There is no slot for us");
75
static const JSJitInfo media_setterinfo = {
76
  { (JSJitGetterOp)set_media },
77
  { prototypes::id::CSSMediaRule },
78
  { PrototypeTraits<prototypes::id::CSSMediaRule>::Depth },
79
  JSJitInfo::Setter,
80
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
81
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
82
  false,  /* isInfallible. False in setters. */
83
  false,  /* isMovable.  Not relevant for setters. */
84
  false, /* isEliminatable.  Not relevant for setters. */
85
  false, /* isAlwaysInSlot.  Only relevant for getters. */
86
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
87
  false,  /* isTypedMethod.  Only relevant for methods. */
88
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
89
};
90
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
91
static_assert(0 < 1, "There is no slot for us");
92
93
static bool
94
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
95
0
{
96
0
  mozilla::dom::CSSMediaRule* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSMediaRule>(obj);
97
0
  // We don't want to preserve if we don't have a wrapper, and we
98
0
  // obviously can't preserve if we're not initialized.
99
0
  if (self && self->GetWrapperPreserveColor()) {
100
0
    PreserveWrapper(self);
101
0
  }
102
0
  return true;
103
0
}
104
105
static void
106
_finalize(js::FreeOp* fop, JSObject* obj)
107
0
{
108
0
  mozilla::dom::CSSMediaRule* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSMediaRule>(obj);
109
0
  if (self) {
110
0
    ClearWrapper(self, self, obj);
111
0
    AddForDeferredFinalization<mozilla::dom::CSSMediaRule>(self);
112
0
  }
113
0
}
114
115
static size_t
116
_objectMoved(JSObject* obj, JSObject* old)
117
0
{
118
0
  mozilla::dom::CSSMediaRule* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CSSMediaRule>(obj);
119
0
  if (self) {
120
0
    UpdateWrapper(self, self, obj, old);
121
0
  }
122
0
123
0
  return 0;
124
0
}
125
126
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
127
#if defined(__clang__)
128
#pragma clang diagnostic push
129
#pragma clang diagnostic ignored "-Wmissing-braces"
130
#endif
131
static const JSPropertySpec sAttributes_specs[] = {
132
  { "media", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &media_getterinfo, GenericSetter<NormalThisPolicy>, &media_setterinfo },
133
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
134
};
135
#if defined(__clang__)
136
#pragma clang diagnostic pop
137
#endif
138
139
140
static const Prefable<const JSPropertySpec> sAttributes[] = {
141
  { nullptr, &sAttributes_specs[0] },
142
  { nullptr, nullptr }
143
};
144
145
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
146
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
147
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
148
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
149
150
151
static uint16_t sNativeProperties_sortedPropertyIndices[1];
152
static PropertyInfo sNativeProperties_propertyInfos[1];
153
154
static const NativePropertiesN<1> sNativeProperties = {
155
  false, 0,
156
  false, 0,
157
  false, 0,
158
  true,  0 /* sAttributes */,
159
  false, 0,
160
  false, 0,
161
  false, 0,
162
  -1,
163
  1,
164
  sNativeProperties_sortedPropertyIndices,
165
  {
166
    { sAttributes, &sNativeProperties_propertyInfos[0] }
167
  }
168
};
169
static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
170
    "We have a property info count that is oversized");
171
172
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
173
  {
174
    "Function",
175
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
176
    &sBoringInterfaceObjectClassClassOps,
177
    JS_NULL_CLASS_SPEC,
178
    JS_NULL_CLASS_EXT,
179
    &sInterfaceObjectClassObjectOps
180
  },
181
  eInterface,
182
  true,
183
  prototypes::id::CSSMediaRule,
184
  PrototypeTraits<prototypes::id::CSSMediaRule>::Depth,
185
  sNativePropertyHooks,
186
  "function CSSMediaRule() {\n    [native code]\n}",
187
  CSSConditionRule_Binding::GetConstructorObject
188
};
189
190
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
191
  {
192
    "CSSMediaRulePrototype",
193
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
194
    JS_NULL_CLASS_OPS,
195
    JS_NULL_CLASS_SPEC,
196
    JS_NULL_CLASS_EXT,
197
    JS_NULL_OBJECT_OPS
198
  },
199
  eInterfacePrototype,
200
  false,
201
  prototypes::id::CSSMediaRule,
202
  PrototypeTraits<prototypes::id::CSSMediaRule>::Depth,
203
  sNativePropertyHooks,
204
  "[object CSSMediaRulePrototype]",
205
  CSSConditionRule_Binding::GetProtoObject
206
};
207
208
static const js::ClassOps sClassOps = {
209
  _addProperty, /* addProperty */
210
  nullptr,               /* delProperty */
211
  nullptr,               /* enumerate */
212
  nullptr, /* newEnumerate */
213
  nullptr, /* resolve */
214
  nullptr, /* mayResolve */
215
  _finalize, /* finalize */
216
  nullptr, /* call */
217
  nullptr,               /* hasInstance */
218
  nullptr,               /* construct */
219
  nullptr, /* trace */
220
};
221
222
static const js::ClassExtension sClassExtension = {
223
  nullptr, /* weakmapKeyDelegateOp */
224
  _objectMoved /* objectMovedOp */
225
};
226
227
static const DOMJSClass sClass = {
228
  { "CSSMediaRule",
229
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
230
    &sClassOps,
231
    JS_NULL_CLASS_SPEC,
232
    &sClassExtension,
233
    JS_NULL_OBJECT_OPS
234
  },
235
  { 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 },
236
  IsBaseOf<nsISupports, mozilla::dom::CSSMediaRule >::value,
237
  sNativePropertyHooks,
238
  FindAssociatedGlobalForNative<mozilla::dom::CSSMediaRule>::Get,
239
  GetProtoObjectHandle,
240
  GetCCParticipant<mozilla::dom::CSSMediaRule>::Get()
241
};
242
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
243
              "Must have the right minimal number of reserved slots.");
244
static_assert(1 >= 1,
245
              "Must have enough reserved slots.");
246
247
const JSClass*
248
GetJSClass()
249
0
{
250
0
  return sClass.ToJSClass();
251
0
}
252
253
bool
254
Wrap(JSContext* aCx, mozilla::dom::CSSMediaRule* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
255
0
{
256
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::CSSMediaRule>::value,
257
0
                "Shouldn't have wrappercached things that are not refcounted.");
258
0
  MOZ_ASSERT(static_cast<mozilla::dom::CSSMediaRule*>(aObject) ==
259
0
             reinterpret_cast<mozilla::dom::CSSMediaRule*>(aObject),
260
0
             "Multiple inheritance for mozilla::dom::CSSMediaRule is broken.");
261
0
  MOZ_ASSERT(static_cast<mozilla::css::ConditionRule*>(aObject) ==
262
0
             reinterpret_cast<mozilla::css::ConditionRule*>(aObject),
263
0
             "Multiple inheritance for mozilla::css::ConditionRule is broken.");
264
0
  MOZ_ASSERT(static_cast<mozilla::css::GroupRule*>(aObject) ==
265
0
             reinterpret_cast<mozilla::css::GroupRule*>(aObject),
266
0
             "Multiple inheritance for mozilla::css::GroupRule is broken.");
267
0
  MOZ_ASSERT(static_cast<mozilla::css::Rule*>(aObject) ==
268
0
             reinterpret_cast<mozilla::css::Rule*>(aObject),
269
0
             "Multiple inheritance for mozilla::css::Rule is broken.");
270
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
271
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
272
0
  MOZ_ASSERT(!aCache->GetWrapper(),
273
0
             "You should probably not be using Wrap() directly; use "
274
0
             "GetOrCreateDOMReflector instead");
275
0
276
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
277
0
             "nsISupports must be on our primary inheritance chain");
278
0
279
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
280
0
  if (!global) {
281
0
    return false;
282
0
  }
283
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
284
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
285
0
286
0
  // That might have ended up wrapping us already, due to the wonders
287
0
  // of XBL.  Check for that, and bail out as needed.
288
0
  aReflector.set(aCache->GetWrapper());
289
0
  if (aReflector) {
290
#ifdef DEBUG
291
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
292
#endif // DEBUG
293
    return true;
294
0
  }
295
0
296
0
  JSAutoRealm ar(aCx, global);
297
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
298
0
  if (!canonicalProto) {
299
0
    return false;
300
0
  }
301
0
  JS::Rooted<JSObject*> proto(aCx);
302
0
  if (aGivenProto) {
303
0
    proto = aGivenProto;
304
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
305
0
    // coming in, we changed compartments to that of "parent" so may need
306
0
    // to wrap the proto here.
307
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
308
0
      if (!JS_WrapObject(aCx, &proto)) {
309
0
        return false;
310
0
      }
311
0
    }
312
0
  } else {
313
0
    proto = canonicalProto;
314
0
  }
315
0
316
0
  BindingJSObjectCreator<mozilla::dom::CSSMediaRule> creator(aCx);
317
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
318
0
  if (!aReflector) {
319
0
    return false;
320
0
  }
321
0
322
0
  aCache->SetWrapper(aReflector);
323
0
  creator.InitializationSucceeded();
324
0
325
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
326
0
             aCache->GetWrapperPreserveColor() == aReflector);
327
0
  // If proto != canonicalProto, we have to preserve our wrapper;
328
0
  // otherwise we won't be able to properly recreate it later, since
329
0
  // we won't know what proto to use.  Note that we don't check
330
0
  // aGivenProto here, since it's entirely possible (and even
331
0
  // somewhat common) to have a non-null aGivenProto which is the
332
0
  // same as canonicalProto.
333
0
  if (proto != canonicalProto) {
334
0
    PreserveWrapper(aObject);
335
0
  }
336
0
337
0
  return true;
338
0
}
339
340
const NativePropertyHooks sNativePropertyHooks[] = { {
341
  nullptr,
342
  nullptr,
343
  nullptr,
344
  { sNativeProperties.Upcast(), nullptr },
345
  prototypes::id::CSSMediaRule,
346
  constructors::id::CSSMediaRule,
347
  CSSConditionRule_Binding::sNativePropertyHooks,
348
  &DefaultXrayExpandoObjectClass
349
} };
350
351
void
352
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
353
0
{
354
0
  JS::Handle<JSObject*> parentProto(CSSConditionRule_Binding::GetProtoObjectHandle(aCx));
355
0
  if (!parentProto) {
356
0
    return;
357
0
  }
358
0
359
0
  JS::Handle<JSObject*> constructorProto(CSSConditionRule_Binding::GetConstructorObjectHandle(aCx));
360
0
  if (!constructorProto) {
361
0
    return;
362
0
  }
363
0
364
0
  static bool sIdsInited = false;
365
0
  if (!sIdsInited && NS_IsMainThread()) {
366
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
367
0
      return;
368
0
    }
369
0
    sIdsInited = true;
370
0
  }
371
0
372
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CSSMediaRule);
373
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CSSMediaRule);
374
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
375
0
                              &sPrototypeClass.mBase, protoCache,
376
0
                              nullptr,
377
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
378
0
                              interfaceCache,
379
0
                              sNativeProperties.Upcast(),
380
0
                              nullptr,
381
0
                              "CSSMediaRule", aDefineOnGlobal,
382
0
                              nullptr,
383
0
                              false);
384
0
}
385
386
JSObject*
387
GetConstructorObject(JSContext* aCx)
388
0
{
389
0
  return GetConstructorObjectHandle(aCx);
390
0
}
391
392
} // namespace CSSMediaRule_Binding
393
394
395
396
} // namespace dom
397
} // namespace mozilla