Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/HTMLSlotElementBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM HTMLSlotElement.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "HTMLElementBinding.h"
5
#include "HTMLSlotElementBinding.h"
6
#include "WrapperFactory.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/CustomElementRegistry.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/DocGroup.h"
12
#include "mozilla/dom/HTMLSlotElement.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/SimpleGlobalObject.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
#include "nsDocument.h"
19
#include "nsINode.h"
20
21
namespace mozilla {
22
namespace dom {
23
24
namespace binding_detail {}; // Just to make sure it's known as a namespace
25
using namespace mozilla::dom::binding_detail;
26
27
28
29
AssignedNodesOptions::AssignedNodesOptions()
30
0
{
31
0
  // Safe to pass a null context if we pass a null value
32
0
  Init(nullptr, JS::NullHandleValue);
33
0
}
34
35
36
37
bool
38
AssignedNodesOptions::InitIds(JSContext* cx, AssignedNodesOptionsAtoms* atomsCache)
39
0
{
40
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
41
0
42
0
  // Initialize these in reverse order so that any failure leaves the first one
43
0
  // uninitialized.
44
0
  if (!atomsCache->flatten_id.init(cx, "flatten")) {
45
0
    return false;
46
0
  }
47
0
  return true;
48
0
}
49
50
bool
51
AssignedNodesOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
52
0
{
53
0
  // Passing a null JSContext is OK only if we're initing from null,
54
0
  // Since in that case we will not have to do any property gets
55
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
56
0
  // checkers by static analysis tools
57
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
58
0
  AssignedNodesOptionsAtoms* atomsCache = nullptr;
59
0
  if (cx) {
60
0
    atomsCache = GetAtomCache<AssignedNodesOptionsAtoms>(cx);
61
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
62
0
      return false;
63
0
    }
64
0
  }
65
0
66
0
  if (!IsConvertibleToDictionary(val)) {
67
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
68
0
  }
69
0
70
0
  bool isNull = val.isNullOrUndefined();
71
0
  // We only need these if !isNull, in which case we have |cx|.
72
0
  Maybe<JS::Rooted<JSObject *> > object;
73
0
  Maybe<JS::Rooted<JS::Value> > temp;
74
0
  if (!isNull) {
75
0
    MOZ_ASSERT(cx);
76
0
    object.emplace(cx, &val.toObject());
77
0
    temp.emplace(cx);
78
0
  }
79
0
  if (!isNull) {
80
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->flatten_id, temp.ptr())) {
81
0
      return false;
82
0
    }
83
0
  }
84
0
  if (!isNull && !temp->isUndefined()) {
85
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mFlatten)) {
86
0
      return false;
87
0
    }
88
0
  } else {
89
0
    mFlatten = false;
90
0
  }
91
0
  mIsAnyMemberPresent = true;
92
0
  return true;
93
0
}
94
95
bool
96
AssignedNodesOptions::Init(const nsAString& aJSON)
97
0
{
98
0
  AutoJSAPI jsapi;
99
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
100
0
  if (!cleanGlobal) {
101
0
    return false;
102
0
  }
103
0
  if (!jsapi.Init(cleanGlobal)) {
104
0
    return false;
105
0
  }
106
0
  JSContext* cx = jsapi.cx();
107
0
  JS::Rooted<JS::Value> json(cx);
108
0
  bool ok = ParseJSON(cx, aJSON, &json);
109
0
  NS_ENSURE_TRUE(ok, false);
110
0
  return Init(cx, json);
111
0
}
112
113
bool
114
AssignedNodesOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
115
0
{
116
0
  AssignedNodesOptionsAtoms* atomsCache = GetAtomCache<AssignedNodesOptionsAtoms>(cx);
117
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
118
0
    return false;
119
0
  }
120
0
121
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
122
0
  if (!obj) {
123
0
    return false;
124
0
  }
125
0
  rval.set(JS::ObjectValue(*obj));
126
0
127
0
  do {
128
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
129
0
    JS::Rooted<JS::Value> temp(cx);
130
0
    bool const & currentValue = mFlatten;
131
0
    temp.setBoolean(currentValue);
132
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->flatten_id, temp, JSPROP_ENUMERATE)) {
133
0
      return false;
134
0
    }
135
0
    break;
136
0
  } while(false);
137
0
138
0
  return true;
139
0
}
140
141
bool
142
AssignedNodesOptions::ToJSON(nsAString& aJSON) const
143
0
{
144
0
  AutoJSAPI jsapi;
145
0
  jsapi.Init();
146
0
  JSContext *cx = jsapi.cx();
147
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
148
0
  // because we'll only be creating objects, in ways that have no
149
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
150
0
  // which likewise guarantees no side-effects for the sorts of
151
0
  // things we will pass it.
152
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
153
0
  JS::Rooted<JS::Value> val(cx);
154
0
  if (!ToObjectInternal(cx, &val)) {
155
0
    return false;
156
0
  }
157
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
158
0
  return StringifyToJSON(cx, obj, aJSON);
159
0
}
160
161
void
162
AssignedNodesOptions::TraceDictionary(JSTracer* trc)
163
0
{
164
0
}
165
166
AssignedNodesOptions&
167
AssignedNodesOptions::operator=(const AssignedNodesOptions& aOther)
168
0
{
169
0
  DictionaryBase::operator=(aOther);
170
0
  mFlatten = aOther.mFlatten;
171
0
  return *this;
172
0
}
173
174
namespace binding_detail {
175
} // namespace binding_detail
176
177
178
namespace HTMLSlotElement_Binding {
179
180
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<HTMLElement_Binding::NativeType>::value,
181
              "Can't inherit from an interface with a different ownership model.");
182
183
MOZ_CAN_RUN_SCRIPT static bool
184
get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLSlotElement* self, JSJitGetterCallArgs args)
185
0
{
186
0
  AUTO_PROFILER_LABEL_FAST("get HTMLSlotElement.name", DOM, cx);
187
0
188
0
  DOMString result;
189
0
  self->GetName(result);
190
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
191
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
192
0
    return false;
193
0
  }
194
0
  return true;
195
0
}
196
197
MOZ_CAN_RUN_SCRIPT static bool
198
set_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLSlotElement* self, JSJitSetterCallArgs args)
199
0
{
200
0
  AUTO_PROFILER_LABEL_FAST("set HTMLSlotElement.name", DOM, cx);
201
0
202
0
  binding_detail::FakeString arg0;
203
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
204
0
    return false;
205
0
  }
206
0
  Maybe<AutoCEReaction> ceReaction;
207
0
  if (CustomElementRegistry::IsCustomElementEnabled(cx, obj)) {
208
0
    DocGroup* docGroup = self->GetDocGroup();
209
0
    if (docGroup) {
210
0
      ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
211
0
    }
212
0
  }
213
0
  FastErrorResult rv;
214
0
  self->SetName(NonNullHelper(Constify(arg0)), rv);
215
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
216
0
    return false;
217
0
  }
218
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
219
0
220
0
  return true;
221
0
}
222
223
static const JSJitInfo name_getterinfo = {
224
  { (JSJitGetterOp)get_name },
225
  { prototypes::id::HTMLSlotElement },
226
  { PrototypeTraits<prototypes::id::HTMLSlotElement>::Depth },
227
  JSJitInfo::Getter,
228
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
229
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
230
  false,  /* isInfallible. False in setters. */
231
  false,  /* isMovable.  Not relevant for setters. */
232
  false, /* isEliminatable.  Not relevant for setters. */
233
  false, /* isAlwaysInSlot.  Only relevant for getters. */
234
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
235
  false,  /* isTypedMethod.  Only relevant for methods. */
236
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
237
};
238
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
239
static_assert(0 < 1, "There is no slot for us");
240
static const JSJitInfo name_setterinfo = {
241
  { (JSJitGetterOp)set_name },
242
  { prototypes::id::HTMLSlotElement },
243
  { PrototypeTraits<prototypes::id::HTMLSlotElement>::Depth },
244
  JSJitInfo::Setter,
245
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
246
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
247
  false,  /* isInfallible. False in setters. */
248
  false,  /* isMovable.  Not relevant for setters. */
249
  false, /* isEliminatable.  Not relevant for setters. */
250
  false, /* isAlwaysInSlot.  Only relevant for getters. */
251
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
252
  false,  /* isTypedMethod.  Only relevant for methods. */
253
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
254
};
255
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
256
static_assert(0 < 1, "There is no slot for us");
257
258
MOZ_CAN_RUN_SCRIPT static bool
259
assignedNodes(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::HTMLSlotElement* self, const JSJitMethodCallArgs& args)
260
0
{
261
0
  AUTO_PROFILER_LABEL_FAST("HTMLSlotElement.assignedNodes", DOM, cx);
262
0
263
0
  binding_detail::FastAssignedNodesOptions arg0;
264
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of HTMLSlotElement.assignedNodes", false)) {
265
0
    return false;
266
0
  }
267
0
  nsTArray<StrongPtrForMember<nsINode>::Type> result;
268
0
  self->AssignedNodes(Constify(arg0), result);
269
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
270
0
271
0
  uint32_t length = result.Length();
272
0
  JS::Rooted<JSObject*> returnArray(cx, JS_NewArrayObject(cx, length));
273
0
  if (!returnArray) {
274
0
    return false;
275
0
  }
276
0
  // Scope for 'tmp'
277
0
  {
278
0
    JS::Rooted<JS::Value> tmp(cx);
279
0
    for (uint32_t sequenceIdx0 = 0; sequenceIdx0 < length; ++sequenceIdx0) {
280
0
      // Control block to let us common up the JS_DefineElement calls when there
281
0
      // are different ways to succeed at wrapping the object.
282
0
      do {
283
0
        if (!GetOrCreateDOMReflector(cx, result[sequenceIdx0], &tmp)) {
284
0
          MOZ_ASSERT(JS_IsExceptionPending(cx));
285
0
          return false;
286
0
        }
287
0
        break;
288
0
      } while (false);
289
0
      if (!JS_DefineElement(cx, returnArray, sequenceIdx0, tmp,
290
0
                            JSPROP_ENUMERATE)) {
291
0
        return false;
292
0
      }
293
0
    }
294
0
  }
295
0
  args.rval().setObject(*returnArray);
296
0
  return true;
297
0
}
298
299
static const JSJitInfo assignedNodes_methodinfo = {
300
  { (JSJitGetterOp)assignedNodes },
301
  { prototypes::id::HTMLSlotElement },
302
  { PrototypeTraits<prototypes::id::HTMLSlotElement>::Depth },
303
  JSJitInfo::Method,
304
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
305
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
306
  false,  /* isInfallible. False in setters. */
307
  false,  /* isMovable.  Not relevant for setters. */
308
  false, /* isEliminatable.  Not relevant for setters. */
309
  false, /* isAlwaysInSlot.  Only relevant for getters. */
310
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
311
  false,  /* isTypedMethod.  Only relevant for methods. */
312
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
313
};
314
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
315
static_assert(0 < 1, "There is no slot for us");
316
317
static bool
318
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
319
0
{
320
0
  mozilla::dom::HTMLSlotElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLSlotElement>(obj);
321
0
  // We don't want to preserve if we don't have a wrapper, and we
322
0
  // obviously can't preserve if we're not initialized.
323
0
  if (self && self->GetWrapperPreserveColor()) {
324
0
    PreserveWrapper(self);
325
0
  }
326
0
  return true;
327
0
}
328
329
static void
330
_finalize(js::FreeOp* fop, JSObject* obj)
331
0
{
332
0
  mozilla::dom::HTMLSlotElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLSlotElement>(obj);
333
0
  if (self) {
334
0
    ClearWrapper(self, self, obj);
335
0
    AddForDeferredFinalization<mozilla::dom::HTMLSlotElement>(self);
336
0
  }
337
0
}
338
339
static size_t
340
_objectMoved(JSObject* obj, JSObject* old)
341
0
{
342
0
  mozilla::dom::HTMLSlotElement* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::HTMLSlotElement>(obj);
343
0
  if (self) {
344
0
    UpdateWrapper(self, self, obj, old);
345
0
  }
346
0
347
0
  return 0;
348
0
}
349
350
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
351
#if defined(__clang__)
352
#pragma clang diagnostic push
353
#pragma clang diagnostic ignored "-Wmissing-braces"
354
#endif
355
static const JSFunctionSpec sMethods_specs[] = {
356
  JS_FNSPEC("assignedNodes", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&assignedNodes_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
357
  JS_FS_END
358
};
359
#if defined(__clang__)
360
#pragma clang diagnostic pop
361
#endif
362
363
364
static const Prefable<const JSFunctionSpec> sMethods[] = {
365
  { nullptr, &sMethods_specs[0] },
366
  { nullptr, nullptr }
367
};
368
369
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
370
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
371
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
372
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
373
374
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
375
#if defined(__clang__)
376
#pragma clang diagnostic push
377
#pragma clang diagnostic ignored "-Wmissing-braces"
378
#endif
379
static const JSPropertySpec sAttributes_specs[] = {
380
  { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, GenericSetter<NormalThisPolicy>, &name_setterinfo },
381
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
382
};
383
#if defined(__clang__)
384
#pragma clang diagnostic pop
385
#endif
386
387
388
static const Prefable<const JSPropertySpec> sAttributes[] = {
389
  { nullptr, &sAttributes_specs[0] },
390
  { nullptr, nullptr }
391
};
392
393
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
394
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
395
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
396
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
397
398
399
static uint16_t sNativeProperties_sortedPropertyIndices[2];
400
static PropertyInfo sNativeProperties_propertyInfos[2];
401
402
static const NativePropertiesN<2> sNativeProperties = {
403
  false, 0,
404
  false, 0,
405
  true,  0 /* sMethods */,
406
  true,  1 /* sAttributes */,
407
  false, 0,
408
  false, 0,
409
  false, 0,
410
  -1,
411
  2,
412
  sNativeProperties_sortedPropertyIndices,
413
  {
414
    { sMethods, &sNativeProperties_propertyInfos[0] },
415
    { sAttributes, &sNativeProperties_propertyInfos[1] }
416
  }
417
};
418
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
419
    "We have a property info count that is oversized");
420
421
static bool
422
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
423
0
{
424
0
  AUTO_PROFILER_LABEL_FAST("HTMLSlotElement constructor", DOM, cx);
425
0
426
0
  return HTMLConstructor(cx, argc, vp,
427
0
                         constructors::id::HTMLSlotElement,
428
0
                         prototypes::id::HTMLSlotElement,
429
0
                         CreateInterfaceObjects);
430
0
}
431
432
static const js::ClassOps sInterfaceObjectClassOps = {
433
    nullptr,               /* addProperty */
434
    nullptr,               /* delProperty */
435
    nullptr,               /* enumerate */
436
    nullptr,               /* newEnumerate */
437
    nullptr,               /* resolve */
438
    nullptr,               /* mayResolve */
439
    nullptr,               /* finalize */
440
    _constructor, /* call */
441
    nullptr,               /* hasInstance */
442
    _constructor, /* construct */
443
    nullptr,               /* trace */
444
};
445
446
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
447
  {
448
    "Function",
449
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
450
    &sInterfaceObjectClassOps,
451
    JS_NULL_CLASS_SPEC,
452
    JS_NULL_CLASS_EXT,
453
    &sInterfaceObjectClassObjectOps
454
  },
455
  eInterface,
456
  true,
457
  prototypes::id::HTMLSlotElement,
458
  PrototypeTraits<prototypes::id::HTMLSlotElement>::Depth,
459
  sNativePropertyHooks,
460
  "function HTMLSlotElement() {\n    [native code]\n}",
461
  HTMLElement_Binding::GetConstructorObject
462
};
463
464
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
465
  {
466
    "HTMLSlotElementPrototype",
467
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
468
    JS_NULL_CLASS_OPS,
469
    JS_NULL_CLASS_SPEC,
470
    JS_NULL_CLASS_EXT,
471
    JS_NULL_OBJECT_OPS
472
  },
473
  eInterfacePrototype,
474
  false,
475
  prototypes::id::HTMLSlotElement,
476
  PrototypeTraits<prototypes::id::HTMLSlotElement>::Depth,
477
  sNativePropertyHooks,
478
  "[object HTMLSlotElementPrototype]",
479
  HTMLElement_Binding::GetProtoObject
480
};
481
482
bool
483
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
484
0
{
485
0
  return nsDocument::IsShadowDOMEnabled(aCx, aObj);
486
0
}
487
488
static const js::ClassOps sClassOps = {
489
  _addProperty, /* addProperty */
490
  nullptr,               /* delProperty */
491
  nullptr,               /* enumerate */
492
  nullptr, /* newEnumerate */
493
  nullptr, /* resolve */
494
  nullptr, /* mayResolve */
495
  _finalize, /* finalize */
496
  nullptr, /* call */
497
  nullptr,               /* hasInstance */
498
  nullptr,               /* construct */
499
  nullptr, /* trace */
500
};
501
502
static const js::ClassExtension sClassExtension = {
503
  nullptr, /* weakmapKeyDelegateOp */
504
  _objectMoved /* objectMovedOp */
505
};
506
507
static const DOMJSClass sClass = {
508
  { "HTMLSlotElement",
509
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
510
    &sClassOps,
511
    JS_NULL_CLASS_SPEC,
512
    &sClassExtension,
513
    JS_NULL_OBJECT_OPS
514
  },
515
  { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Element, prototypes::id::HTMLElement, prototypes::id::HTMLSlotElement, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
516
  IsBaseOf<nsISupports, mozilla::dom::HTMLSlotElement >::value,
517
  sNativePropertyHooks,
518
  FindAssociatedGlobalForNative<mozilla::dom::HTMLSlotElement>::Get,
519
  GetProtoObjectHandle,
520
  GetCCParticipant<mozilla::dom::HTMLSlotElement>::Get()
521
};
522
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
523
              "Must have the right minimal number of reserved slots.");
524
static_assert(1 >= 1,
525
              "Must have enough reserved slots.");
526
527
const JSClass*
528
GetJSClass()
529
0
{
530
0
  return sClass.ToJSClass();
531
0
}
532
533
bool
534
Wrap(JSContext* aCx, mozilla::dom::HTMLSlotElement* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
535
0
{
536
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::HTMLSlotElement>::value,
537
0
                "Shouldn't have wrappercached things that are not refcounted.");
538
0
  MOZ_ASSERT(static_cast<mozilla::dom::HTMLSlotElement*>(aObject) ==
539
0
             reinterpret_cast<mozilla::dom::HTMLSlotElement*>(aObject),
540
0
             "Multiple inheritance for mozilla::dom::HTMLSlotElement is broken.");
541
0
  MOZ_ASSERT(static_cast<nsGenericHTMLElement*>(aObject) ==
542
0
             reinterpret_cast<nsGenericHTMLElement*>(aObject),
543
0
             "Multiple inheritance for nsGenericHTMLElement is broken.");
544
0
  MOZ_ASSERT(static_cast<mozilla::dom::Element*>(aObject) ==
545
0
             reinterpret_cast<mozilla::dom::Element*>(aObject),
546
0
             "Multiple inheritance for mozilla::dom::Element is broken.");
547
0
  MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
548
0
             reinterpret_cast<nsINode*>(aObject),
549
0
             "Multiple inheritance for nsINode is broken.");
550
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
551
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
552
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
553
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
554
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
555
0
  MOZ_ASSERT(!aCache->GetWrapper(),
556
0
             "You should probably not be using Wrap() directly; use "
557
0
             "GetOrCreateDOMReflector instead");
558
0
559
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
560
0
             "nsISupports must be on our primary inheritance chain");
561
0
562
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
563
0
  if (!global) {
564
0
    return false;
565
0
  }
566
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
567
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
568
0
569
0
  // That might have ended up wrapping us already, due to the wonders
570
0
  // of XBL.  Check for that, and bail out as needed.
571
0
  aReflector.set(aCache->GetWrapper());
572
0
  if (aReflector) {
573
#ifdef DEBUG
574
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
575
#endif // DEBUG
576
    return true;
577
0
  }
578
0
579
0
  JSAutoRealm ar(aCx, global);
580
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
581
0
  if (!canonicalProto) {
582
0
    return false;
583
0
  }
584
0
  JS::Rooted<JSObject*> proto(aCx);
585
0
  if (aGivenProto) {
586
0
    proto = aGivenProto;
587
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
588
0
    // coming in, we changed compartments to that of "parent" so may need
589
0
    // to wrap the proto here.
590
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
591
0
      if (!JS_WrapObject(aCx, &proto)) {
592
0
        return false;
593
0
      }
594
0
    }
595
0
  } else {
596
0
    proto = canonicalProto;
597
0
  }
598
0
599
0
  BindingJSObjectCreator<mozilla::dom::HTMLSlotElement> creator(aCx);
600
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
601
0
  if (!aReflector) {
602
0
    return false;
603
0
  }
604
0
605
0
  aCache->SetWrapper(aReflector);
606
0
  creator.InitializationSucceeded();
607
0
608
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
609
0
             aCache->GetWrapperPreserveColor() == aReflector);
610
0
  // If proto != canonicalProto, we have to preserve our wrapper;
611
0
  // otherwise we won't be able to properly recreate it later, since
612
0
  // we won't know what proto to use.  Note that we don't check
613
0
  // aGivenProto here, since it's entirely possible (and even
614
0
  // somewhat common) to have a non-null aGivenProto which is the
615
0
  // same as canonicalProto.
616
0
  if (proto != canonicalProto) {
617
0
    PreserveWrapper(aObject);
618
0
  }
619
0
620
0
  return true;
621
0
}
622
623
const NativePropertyHooks sNativePropertyHooks[] = { {
624
  nullptr,
625
  nullptr,
626
  nullptr,
627
  { sNativeProperties.Upcast(), nullptr },
628
  prototypes::id::HTMLSlotElement,
629
  constructors::id::HTMLSlotElement,
630
  HTMLElement_Binding::sNativePropertyHooks,
631
  &DefaultXrayExpandoObjectClass
632
} };
633
634
void
635
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
636
0
{
637
0
  JS::Handle<JSObject*> parentProto(HTMLElement_Binding::GetProtoObjectHandle(aCx));
638
0
  if (!parentProto) {
639
0
    return;
640
0
  }
641
0
642
0
  JS::Handle<JSObject*> constructorProto(HTMLElement_Binding::GetConstructorObjectHandle(aCx));
643
0
  if (!constructorProto) {
644
0
    return;
645
0
  }
646
0
647
0
  static bool sIdsInited = false;
648
0
  if (!sIdsInited && NS_IsMainThread()) {
649
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
650
0
      return;
651
0
    }
652
0
    sIdsInited = true;
653
0
  }
654
0
655
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::HTMLSlotElement);
656
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::HTMLSlotElement);
657
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
658
0
                              &sPrototypeClass.mBase, protoCache,
659
0
                              nullptr,
660
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
661
0
                              interfaceCache,
662
0
                              sNativeProperties.Upcast(),
663
0
                              nullptr,
664
0
                              "HTMLSlotElement", aDefineOnGlobal,
665
0
                              nullptr,
666
0
                              false);
667
0
}
668
669
JSObject*
670
GetConstructorObject(JSContext* aCx)
671
0
{
672
0
  return GetConstructorObjectHandle(aCx);
673
0
}
674
675
} // namespace HTMLSlotElement_Binding
676
677
678
679
} // namespace dom
680
} // namespace mozilla