Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/AttrBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM Attr.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AttrBinding.h"
4
#include "NodeBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/Attr.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/Element.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/Nullable.h"
15
#include "mozilla/dom/PrimitiveConversions.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
#include "nsContentUtils.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
namespace Attr_Binding {
27
28
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Node_Binding::NativeType>::value,
29
              "Can't inherit from an interface with a different ownership model.");
30
31
MOZ_CAN_RUN_SCRIPT static bool
32
get_localName(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitGetterCallArgs args)
33
0
{
34
0
  AUTO_PROFILER_LABEL_FAST("get Attr.localName", DOM, cx);
35
0
36
0
  DOMString result;
37
0
  self->GetLocalName(result);
38
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
39
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
40
0
    return false;
41
0
  }
42
0
  return true;
43
0
}
44
45
static const JSJitInfo localName_getterinfo = {
46
  { (JSJitGetterOp)get_localName },
47
  { prototypes::id::Attr },
48
  { PrototypeTraits<prototypes::id::Attr>::Depth },
49
  JSJitInfo::Getter,
50
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
51
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
52
  false,  /* isInfallible. False in setters. */
53
  false,  /* isMovable.  Not relevant for setters. */
54
  false, /* isEliminatable.  Not relevant for setters. */
55
  false, /* isAlwaysInSlot.  Only relevant for getters. */
56
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
57
  false,  /* isTypedMethod.  Only relevant for methods. */
58
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
59
};
60
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
61
static_assert(0 < 1, "There is no slot for us");
62
63
MOZ_CAN_RUN_SCRIPT static bool
64
get_value(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitGetterCallArgs args)
65
0
{
66
0
  AUTO_PROFILER_LABEL_FAST("get Attr.value", DOM, cx);
67
0
68
0
  DOMString result;
69
0
  self->GetValue(result);
70
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
71
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
72
0
    return false;
73
0
  }
74
0
  return true;
75
0
}
76
77
MOZ_CAN_RUN_SCRIPT static bool
78
set_value(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitSetterCallArgs args)
79
0
{
80
0
  AUTO_PROFILER_LABEL_FAST("set Attr.value", DOM, cx);
81
0
82
0
  binding_detail::FakeString arg0;
83
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
84
0
    return false;
85
0
  }
86
0
  Maybe<AutoCEReaction> ceReaction;
87
0
  if (CustomElementRegistry::IsCustomElementEnabled(cx, obj)) {
88
0
    DocGroup* docGroup = self->GetDocGroup();
89
0
    if (docGroup) {
90
0
      ceReaction.emplace(docGroup->CustomElementReactionsStack(), cx);
91
0
    }
92
0
  }
93
0
  FastErrorResult rv;
94
0
  nsIPrincipal* subjectPrincipal;
95
0
  {
96
0
    JS::Realm* realm = js::GetContextRealm(cx);
97
0
    MOZ_ASSERT(realm);
98
0
    JSPrincipals* principals = JS::GetRealmPrincipals(realm);
99
0
    nsIPrincipal* principal = nsJSPrincipals::get(principals);
100
0
    if (nsContentUtils::IsSystemPrincipal(principal)) {
101
0
      principal = nullptr;
102
0
    }
103
0
104
0
    subjectPrincipal = principal;
105
0
  }
106
0
  self->SetValue(NonNullHelper(Constify(arg0)), subjectPrincipal, rv);
107
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
108
0
    return false;
109
0
  }
110
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
111
0
112
0
  return true;
113
0
}
114
115
static const JSJitInfo value_getterinfo = {
116
  { (JSJitGetterOp)get_value },
117
  { prototypes::id::Attr },
118
  { PrototypeTraits<prototypes::id::Attr>::Depth },
119
  JSJitInfo::Getter,
120
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
121
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
122
  false,  /* isInfallible. False in setters. */
123
  false,  /* isMovable.  Not relevant for setters. */
124
  false, /* isEliminatable.  Not relevant for setters. */
125
  false, /* isAlwaysInSlot.  Only relevant for getters. */
126
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
127
  false,  /* isTypedMethod.  Only relevant for methods. */
128
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
129
};
130
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
131
static_assert(0 < 1, "There is no slot for us");
132
static const JSJitInfo value_setterinfo = {
133
  { (JSJitGetterOp)set_value },
134
  { prototypes::id::Attr },
135
  { PrototypeTraits<prototypes::id::Attr>::Depth },
136
  JSJitInfo::Setter,
137
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
138
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
139
  false,  /* isInfallible. False in setters. */
140
  false,  /* isMovable.  Not relevant for setters. */
141
  false, /* isEliminatable.  Not relevant for setters. */
142
  false, /* isAlwaysInSlot.  Only relevant for getters. */
143
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
144
  false,  /* isTypedMethod.  Only relevant for methods. */
145
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
146
};
147
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
148
static_assert(0 < 1, "There is no slot for us");
149
150
MOZ_CAN_RUN_SCRIPT static bool
151
get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitGetterCallArgs args)
152
0
{
153
0
  AUTO_PROFILER_LABEL_FAST("get Attr.name", DOM, cx);
154
0
155
0
  DOMString result;
156
0
  self->GetName(result);
157
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
158
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
159
0
    return false;
160
0
  }
161
0
  return true;
162
0
}
163
164
static const JSJitInfo name_getterinfo = {
165
  { (JSJitGetterOp)get_name },
166
  { prototypes::id::Attr },
167
  { PrototypeTraits<prototypes::id::Attr>::Depth },
168
  JSJitInfo::Getter,
169
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
170
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
171
  false,  /* isInfallible. False in setters. */
172
  true,  /* isMovable.  Not relevant for setters. */
173
  true, /* isEliminatable.  Not relevant for setters. */
174
  false, /* isAlwaysInSlot.  Only relevant for getters. */
175
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
176
  false,  /* isTypedMethod.  Only relevant for methods. */
177
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
178
};
179
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
180
static_assert(0 < 1, "There is no slot for us");
181
182
MOZ_CAN_RUN_SCRIPT static bool
183
get_namespaceURI(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitGetterCallArgs args)
184
0
{
185
0
  AUTO_PROFILER_LABEL_FAST("get Attr.namespaceURI", DOM, cx);
186
0
187
0
  DOMString result;
188
0
  self->GetNamespaceURI(result);
189
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
190
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
191
0
    return false;
192
0
  }
193
0
  return true;
194
0
}
195
196
static const JSJitInfo namespaceURI_getterinfo = {
197
  { (JSJitGetterOp)get_namespaceURI },
198
  { prototypes::id::Attr },
199
  { PrototypeTraits<prototypes::id::Attr>::Depth },
200
  JSJitInfo::Getter,
201
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
202
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
203
  false,  /* isInfallible. False in setters. */
204
  true,  /* isMovable.  Not relevant for setters. */
205
  true, /* isEliminatable.  Not relevant for setters. */
206
  false, /* isAlwaysInSlot.  Only relevant for getters. */
207
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
208
  false,  /* isTypedMethod.  Only relevant for methods. */
209
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
210
};
211
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
212
static_assert(0 < 1, "There is no slot for us");
213
214
MOZ_CAN_RUN_SCRIPT static bool
215
get_prefix(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitGetterCallArgs args)
216
0
{
217
0
  AUTO_PROFILER_LABEL_FAST("get Attr.prefix", DOM, cx);
218
0
219
0
  DOMString result;
220
0
  self->GetPrefix(result);
221
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
222
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
223
0
    return false;
224
0
  }
225
0
  return true;
226
0
}
227
228
static const JSJitInfo prefix_getterinfo = {
229
  { (JSJitGetterOp)get_prefix },
230
  { prototypes::id::Attr },
231
  { PrototypeTraits<prototypes::id::Attr>::Depth },
232
  JSJitInfo::Getter,
233
  JSJitInfo::AliasNone, /* aliasSet.  Not relevant for setters. */
234
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
235
  false,  /* isInfallible. False in setters. */
236
  true,  /* isMovable.  Not relevant for setters. */
237
  true, /* isEliminatable.  Not relevant for setters. */
238
  false, /* isAlwaysInSlot.  Only relevant for getters. */
239
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
240
  false,  /* isTypedMethod.  Only relevant for methods. */
241
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
242
};
243
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
244
static_assert(0 < 1, "There is no slot for us");
245
246
MOZ_CAN_RUN_SCRIPT static bool
247
get_specified(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitGetterCallArgs args)
248
0
{
249
0
  AUTO_PROFILER_LABEL_FAST("get Attr.specified", DOM, cx);
250
0
251
0
  bool result(self->Specified());
252
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
253
0
  args.rval().setBoolean(result);
254
0
  return true;
255
0
}
256
257
static const JSJitInfo specified_getterinfo = {
258
  { (JSJitGetterOp)get_specified },
259
  { prototypes::id::Attr },
260
  { PrototypeTraits<prototypes::id::Attr>::Depth },
261
  JSJitInfo::Getter,
262
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
263
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
264
  true,  /* isInfallible. False in setters. */
265
  false,  /* isMovable.  Not relevant for setters. */
266
  false, /* isEliminatable.  Not relevant for setters. */
267
  false, /* isAlwaysInSlot.  Only relevant for getters. */
268
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
269
  false,  /* isTypedMethod.  Only relevant for methods. */
270
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
271
};
272
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
273
static_assert(0 < 1, "There is no slot for us");
274
275
MOZ_CAN_RUN_SCRIPT static bool
276
get_ownerElement(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Attr* self, JSJitGetterCallArgs args)
277
0
{
278
0
  AUTO_PROFILER_LABEL_FAST("get Attr.ownerElement", DOM, cx);
279
0
280
0
  FastErrorResult rv;
281
0
  auto result(StrongOrRawPtr<mozilla::dom::Element>(self->GetOwnerElement(rv)));
282
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
283
0
    return false;
284
0
  }
285
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
286
0
  if (!result) {
287
0
    args.rval().setNull();
288
0
    return true;
289
0
  }
290
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
291
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
292
0
    return false;
293
0
  }
294
0
  return true;
295
0
}
296
297
static const JSJitInfo ownerElement_getterinfo = {
298
  { (JSJitGetterOp)get_ownerElement },
299
  { prototypes::id::Attr },
300
  { PrototypeTraits<prototypes::id::Attr>::Depth },
301
  JSJitInfo::Getter,
302
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
303
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
304
  false,  /* isInfallible. False in setters. */
305
  false,  /* isMovable.  Not relevant for setters. */
306
  false, /* isEliminatable.  Not relevant for setters. */
307
  false, /* isAlwaysInSlot.  Only relevant for getters. */
308
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
309
  false,  /* isTypedMethod.  Only relevant for methods. */
310
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
311
};
312
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
313
static_assert(0 < 1, "There is no slot for us");
314
315
static bool
316
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
317
0
{
318
0
  mozilla::dom::Attr* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Attr>(obj);
319
0
  // We don't want to preserve if we don't have a wrapper, and we
320
0
  // obviously can't preserve if we're not initialized.
321
0
  if (self && self->GetWrapperPreserveColor()) {
322
0
    PreserveWrapper(self);
323
0
  }
324
0
  return true;
325
0
}
326
327
static void
328
_finalize(js::FreeOp* fop, JSObject* obj)
329
0
{
330
0
  mozilla::dom::Attr* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Attr>(obj);
331
0
  if (self) {
332
0
    ClearWrapper(self, self, obj);
333
0
    AddForDeferredFinalization<mozilla::dom::Attr>(self);
334
0
  }
335
0
}
336
337
static size_t
338
_objectMoved(JSObject* obj, JSObject* old)
339
0
{
340
0
  mozilla::dom::Attr* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Attr>(obj);
341
0
  if (self) {
342
0
    UpdateWrapper(self, self, obj, old);
343
0
  }
344
0
345
0
  return 0;
346
0
}
347
348
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
349
#if defined(__clang__)
350
#pragma clang diagnostic push
351
#pragma clang diagnostic ignored "-Wmissing-braces"
352
#endif
353
static const JSPropertySpec sAttributes_specs[] = {
354
  { "localName", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &localName_getterinfo, nullptr, nullptr },
355
  { "value", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &value_getterinfo, GenericSetter<NormalThisPolicy>, &value_setterinfo },
356
  { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr },
357
  { "namespaceURI", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &namespaceURI_getterinfo, nullptr, nullptr },
358
  { "prefix", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &prefix_getterinfo, nullptr, nullptr },
359
  { "specified", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &specified_getterinfo, nullptr, nullptr },
360
  { "ownerElement", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &ownerElement_getterinfo, nullptr, nullptr },
361
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
362
};
363
#if defined(__clang__)
364
#pragma clang diagnostic pop
365
#endif
366
367
368
static const Prefable<const JSPropertySpec> sAttributes[] = {
369
  { nullptr, &sAttributes_specs[0] },
370
  { nullptr, nullptr }
371
};
372
373
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
374
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
375
static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
376
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
377
378
379
static uint16_t sNativeProperties_sortedPropertyIndices[7];
380
static PropertyInfo sNativeProperties_propertyInfos[7];
381
382
static const NativePropertiesN<1> sNativeProperties = {
383
  false, 0,
384
  false, 0,
385
  false, 0,
386
  true,  0 /* sAttributes */,
387
  false, 0,
388
  false, 0,
389
  false, 0,
390
  -1,
391
  7,
392
  sNativeProperties_sortedPropertyIndices,
393
  {
394
    { sAttributes, &sNativeProperties_propertyInfos[0] }
395
  }
396
};
397
static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
398
    "We have a property info count that is oversized");
399
400
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
401
  {
402
    "Function",
403
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
404
    &sBoringInterfaceObjectClassClassOps,
405
    JS_NULL_CLASS_SPEC,
406
    JS_NULL_CLASS_EXT,
407
    &sInterfaceObjectClassObjectOps
408
  },
409
  eInterface,
410
  true,
411
  prototypes::id::Attr,
412
  PrototypeTraits<prototypes::id::Attr>::Depth,
413
  sNativePropertyHooks,
414
  "function Attr() {\n    [native code]\n}",
415
  Node_Binding::GetConstructorObject
416
};
417
418
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
419
  {
420
    "AttrPrototype",
421
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
422
    JS_NULL_CLASS_OPS,
423
    JS_NULL_CLASS_SPEC,
424
    JS_NULL_CLASS_EXT,
425
    JS_NULL_OBJECT_OPS
426
  },
427
  eInterfacePrototype,
428
  false,
429
  prototypes::id::Attr,
430
  PrototypeTraits<prototypes::id::Attr>::Depth,
431
  sNativePropertyHooks,
432
  "[object AttrPrototype]",
433
  Node_Binding::GetProtoObject
434
};
435
436
static const js::ClassOps sClassOps = {
437
  _addProperty, /* addProperty */
438
  nullptr,               /* delProperty */
439
  nullptr,               /* enumerate */
440
  nullptr, /* newEnumerate */
441
  nullptr, /* resolve */
442
  nullptr, /* mayResolve */
443
  _finalize, /* finalize */
444
  nullptr, /* call */
445
  nullptr,               /* hasInstance */
446
  nullptr,               /* construct */
447
  nullptr, /* trace */
448
};
449
450
static const js::ClassExtension sClassExtension = {
451
  nullptr, /* weakmapKeyDelegateOp */
452
  _objectMoved /* objectMovedOp */
453
};
454
455
static const DOMJSClass sClass = {
456
  { "Attr",
457
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
458
    &sClassOps,
459
    JS_NULL_CLASS_SPEC,
460
    &sClassExtension,
461
    JS_NULL_OBJECT_OPS
462
  },
463
  { prototypes::id::EventTarget, prototypes::id::Node, prototypes::id::Attr, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
464
  IsBaseOf<nsISupports, mozilla::dom::Attr >::value,
465
  sNativePropertyHooks,
466
  FindAssociatedGlobalForNative<mozilla::dom::Attr>::Get,
467
  GetProtoObjectHandle,
468
  GetCCParticipant<mozilla::dom::Attr>::Get()
469
};
470
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
471
              "Must have the right minimal number of reserved slots.");
472
static_assert(1 >= 1,
473
              "Must have enough reserved slots.");
474
475
const JSClass*
476
GetJSClass()
477
0
{
478
0
  return sClass.ToJSClass();
479
0
}
480
481
bool
482
Wrap(JSContext* aCx, mozilla::dom::Attr* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
483
0
{
484
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Attr>::value,
485
0
                "Shouldn't have wrappercached things that are not refcounted.");
486
0
  MOZ_ASSERT(static_cast<mozilla::dom::Attr*>(aObject) ==
487
0
             reinterpret_cast<mozilla::dom::Attr*>(aObject),
488
0
             "Multiple inheritance for mozilla::dom::Attr is broken.");
489
0
  MOZ_ASSERT(static_cast<nsINode*>(aObject) ==
490
0
             reinterpret_cast<nsINode*>(aObject),
491
0
             "Multiple inheritance for nsINode is broken.");
492
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
493
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
494
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
495
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
496
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
497
0
  MOZ_ASSERT(!aCache->GetWrapper(),
498
0
             "You should probably not be using Wrap() directly; use "
499
0
             "GetOrCreateDOMReflector instead");
500
0
501
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
502
0
             "nsISupports must be on our primary inheritance chain");
503
0
504
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
505
0
  if (!global) {
506
0
    return false;
507
0
  }
508
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
509
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
510
0
511
0
  // That might have ended up wrapping us already, due to the wonders
512
0
  // of XBL.  Check for that, and bail out as needed.
513
0
  aReflector.set(aCache->GetWrapper());
514
0
  if (aReflector) {
515
#ifdef DEBUG
516
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
517
#endif // DEBUG
518
    return true;
519
0
  }
520
0
521
0
  JSAutoRealm ar(aCx, global);
522
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
523
0
  if (!canonicalProto) {
524
0
    return false;
525
0
  }
526
0
  JS::Rooted<JSObject*> proto(aCx);
527
0
  if (aGivenProto) {
528
0
    proto = aGivenProto;
529
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
530
0
    // coming in, we changed compartments to that of "parent" so may need
531
0
    // to wrap the proto here.
532
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
533
0
      if (!JS_WrapObject(aCx, &proto)) {
534
0
        return false;
535
0
      }
536
0
    }
537
0
  } else {
538
0
    proto = canonicalProto;
539
0
  }
540
0
541
0
  BindingJSObjectCreator<mozilla::dom::Attr> creator(aCx);
542
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
543
0
  if (!aReflector) {
544
0
    return false;
545
0
  }
546
0
547
0
  aCache->SetWrapper(aReflector);
548
0
  creator.InitializationSucceeded();
549
0
550
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
551
0
             aCache->GetWrapperPreserveColor() == aReflector);
552
0
  // If proto != canonicalProto, we have to preserve our wrapper;
553
0
  // otherwise we won't be able to properly recreate it later, since
554
0
  // we won't know what proto to use.  Note that we don't check
555
0
  // aGivenProto here, since it's entirely possible (and even
556
0
  // somewhat common) to have a non-null aGivenProto which is the
557
0
  // same as canonicalProto.
558
0
  if (proto != canonicalProto) {
559
0
    PreserveWrapper(aObject);
560
0
  }
561
0
562
0
  return true;
563
0
}
564
565
const NativePropertyHooks sNativePropertyHooks[] = { {
566
  nullptr,
567
  nullptr,
568
  nullptr,
569
  { sNativeProperties.Upcast(), nullptr },
570
  prototypes::id::Attr,
571
  constructors::id::Attr,
572
  Node_Binding::sNativePropertyHooks,
573
  &DefaultXrayExpandoObjectClass
574
} };
575
576
void
577
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
578
0
{
579
0
  JS::Handle<JSObject*> parentProto(Node_Binding::GetProtoObjectHandle(aCx));
580
0
  if (!parentProto) {
581
0
    return;
582
0
  }
583
0
584
0
  JS::Handle<JSObject*> constructorProto(Node_Binding::GetConstructorObjectHandle(aCx));
585
0
  if (!constructorProto) {
586
0
    return;
587
0
  }
588
0
589
0
  static bool sIdsInited = false;
590
0
  if (!sIdsInited && NS_IsMainThread()) {
591
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
592
0
      return;
593
0
    }
594
0
    sIdsInited = true;
595
0
  }
596
0
597
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Attr);
598
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Attr);
599
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
600
0
                              &sPrototypeClass.mBase, protoCache,
601
0
                              nullptr,
602
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
603
0
                              interfaceCache,
604
0
                              sNativeProperties.Upcast(),
605
0
                              nullptr,
606
0
                              "Attr", aDefineOnGlobal,
607
0
                              nullptr,
608
0
                              false);
609
0
}
610
611
JSObject*
612
GetConstructorObject(JSContext* aCx)
613
0
{
614
0
  return GetConstructorObjectHandle(aCx);
615
0
}
616
617
} // namespace Attr_Binding
618
619
620
621
} // namespace dom
622
} // namespace mozilla