Coverage Report

Created: 2018-09-25 14:53

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