Coverage Report

Created: 2018-09-25 14:53

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