Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/NodeListBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM NodeList.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "NodeListBinding.h"
4
#include "WrapperFactory.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/dom/BindingUtils.h"
7
#include "mozilla/dom/DOMJSClass.h"
8
#include "mozilla/dom/DOMJSProxyHandler.h"
9
#include "mozilla/dom/NonRefcountedDOMObject.h"
10
#include "mozilla/dom/Nullable.h"
11
#include "mozilla/dom/PrimitiveConversions.h"
12
#include "mozilla/dom/ToJSValue.h"
13
#include "mozilla/dom/XrayExpandoClass.h"
14
#include "nsINode.h"
15
#include "nsINodeList.h"
16
17
namespace mozilla {
18
namespace dom {
19
20
namespace binding_detail {}; // Just to make sure it's known as a namespace
21
using namespace mozilla::dom::binding_detail;
22
23
24
namespace NodeList_Binding {
25
26
MOZ_CAN_RUN_SCRIPT static bool
27
item(JSContext* cx, JS::Handle<JSObject*> obj, nsINodeList* self, const JSJitMethodCallArgs& args)
28
0
{
29
0
  AUTO_PROFILER_LABEL_FAST("NodeList.item", DOM, cx);
30
0
31
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
32
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "NodeList.item");
33
0
  }
34
0
  uint32_t arg0;
35
0
  if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
36
0
    return false;
37
0
  }
38
0
  auto result(StrongOrRawPtr<nsINode>(self->Item(arg0)));
39
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
40
0
  if (!result) {
41
0
    args.rval().setNull();
42
0
    return true;
43
0
  }
44
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
45
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
46
0
    return false;
47
0
  }
48
0
  return true;
49
0
}
50
51
static const JSJitInfo item_methodinfo = {
52
  { (JSJitGetterOp)item },
53
  { prototypes::id::NodeList },
54
  { PrototypeTraits<prototypes::id::NodeList>::Depth },
55
  JSJitInfo::Method,
56
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
57
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
58
  false,  /* isInfallible. False in setters. */
59
  false,  /* isMovable.  Not relevant for setters. */
60
  false, /* isEliminatable.  Not relevant for setters. */
61
  false, /* isAlwaysInSlot.  Only relevant for getters. */
62
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
63
  false,  /* isTypedMethod.  Only relevant for methods. */
64
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
65
};
66
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
67
static_assert(0 < 1, "There is no slot for us");
68
69
MOZ_CAN_RUN_SCRIPT static bool
70
get_length(JSContext* cx, JS::Handle<JSObject*> obj, nsINodeList* self, JSJitGetterCallArgs args)
71
0
{
72
0
  AUTO_PROFILER_LABEL_FAST("get NodeList.length", DOM, cx);
73
0
74
0
  uint32_t result(self->Length());
75
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
76
0
  args.rval().setNumber(result);
77
0
  return true;
78
0
}
79
80
static const JSJitInfo length_getterinfo = {
81
  { (JSJitGetterOp)get_length },
82
  { prototypes::id::NodeList },
83
  { PrototypeTraits<prototypes::id::NodeList>::Depth },
84
  JSJitInfo::Getter,
85
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
86
  JSVAL_TYPE_DOUBLE,  /* returnType.  Not relevant for setters. */
87
  true,  /* isInfallible. False in setters. */
88
  false,  /* isMovable.  Not relevant for setters. */
89
  false, /* isEliminatable.  Not relevant for setters. */
90
  false, /* isAlwaysInSlot.  Only relevant for getters. */
91
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
92
  false,  /* isTypedMethod.  Only relevant for methods. */
93
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
94
};
95
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
96
static_assert(0 < 1, "There is no slot for us");
97
98
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
99
#if defined(__clang__)
100
#pragma clang diagnostic push
101
#pragma clang diagnostic ignored "-Wmissing-braces"
102
#endif
103
static const JSFunctionSpec sMethods_specs[] = {
104
  JS_FNSPEC("item", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
105
  JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
106
  JS_FNSPEC("keys", nullptr, nullptr, 0, JSPROP_ENUMERATE, "ArrayKeys"),
107
  JS_FNSPEC("values", nullptr, nullptr, 0, JSPROP_ENUMERATE, "ArrayValues"),
108
  JS_FNSPEC("entries", nullptr, nullptr, 0, JSPROP_ENUMERATE, "ArrayEntries"),
109
  JS_FNSPEC("forEach", nullptr, nullptr, 1, JSPROP_ENUMERATE, "ArrayForEach"),
110
  JS_FS_END
111
};
112
#if defined(__clang__)
113
#pragma clang diagnostic pop
114
#endif
115
116
117
static const Prefable<const JSFunctionSpec> sMethods[] = {
118
  { nullptr, &sMethods_specs[0] },
119
  { nullptr, nullptr }
120
};
121
122
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
123
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
124
static_assert(6 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
125
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
126
127
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
128
#if defined(__clang__)
129
#pragma clang diagnostic push
130
#pragma clang diagnostic ignored "-Wmissing-braces"
131
#endif
132
static const JSPropertySpec sAttributes_specs[] = {
133
  { "length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr },
134
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
135
};
136
#if defined(__clang__)
137
#pragma clang diagnostic pop
138
#endif
139
140
141
static const Prefable<const JSPropertySpec> sAttributes[] = {
142
  { nullptr, &sAttributes_specs[0] },
143
  { nullptr, nullptr }
144
};
145
146
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
147
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
148
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
149
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
150
151
152
static uint16_t sNativeProperties_sortedPropertyIndices[7];
153
static PropertyInfo sNativeProperties_propertyInfos[7];
154
155
static const NativePropertiesN<2> sNativeProperties = {
156
  false, 0,
157
  false, 0,
158
  true,  0 /* sMethods */,
159
  true,  1 /* sAttributes */,
160
  false, 0,
161
  false, 0,
162
  false, 0,
163
  -1,
164
  7,
165
  sNativeProperties_sortedPropertyIndices,
166
  {
167
    { sMethods, &sNativeProperties_propertyInfos[0] },
168
    { sAttributes, &sNativeProperties_propertyInfos[6] }
169
  }
170
};
171
static_assert(7 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
172
    "We have a property info count that is oversized");
173
174
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
175
  {
176
    "Function",
177
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
178
    &sBoringInterfaceObjectClassClassOps,
179
    JS_NULL_CLASS_SPEC,
180
    JS_NULL_CLASS_EXT,
181
    &sInterfaceObjectClassObjectOps
182
  },
183
  eInterface,
184
  true,
185
  prototypes::id::NodeList,
186
  PrototypeTraits<prototypes::id::NodeList>::Depth,
187
  sNativePropertyHooks,
188
  "function NodeList() {\n    [native code]\n}",
189
  JS::GetRealmFunctionPrototype
190
};
191
192
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
193
  {
194
    "NodeListPrototype",
195
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
196
    JS_NULL_CLASS_OPS,
197
    JS_NULL_CLASS_SPEC,
198
    JS_NULL_CLASS_EXT,
199
    JS_NULL_OBJECT_OPS
200
  },
201
  eInterfacePrototype,
202
  false,
203
  prototypes::id::NodeList,
204
  PrototypeTraits<prototypes::id::NodeList>::Depth,
205
  sNativePropertyHooks,
206
  "[object NodeListPrototype]",
207
  JS::GetRealmObjectPrototype
208
};
209
210
static_assert(IsBaseOf<nsISupports, nsINodeList >::value,
211
                  "We don't support non-nsISupports native classes for "
212
                  "proxy-based bindings yet");
213
214
215
class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
216
{
217
public:
218
  explicit constexpr DOMProxyHandler()
219
0
  {
220
0
  }
221
222
  virtual bool
223
  getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
224
225
  virtual bool
226
  defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
227
228
  using mozilla::dom::DOMProxyHandler::defineProperty;
229
230
  virtual bool
231
  ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
232
233
  virtual bool
234
  hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
235
236
  virtual bool
237
  get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
238
239
  virtual const char*
240
  className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
241
242
  virtual bool
243
  finalizeInBackground(const JS::Value& priv) const override;
244
245
  virtual void
246
  finalize(JSFreeOp* fop, JSObject* proxy) const override;
247
248
  static const DOMProxyHandler*
249
  getInstance();
250
251
  virtual bool
252
  delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
253
254
  virtual bool
255
  getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
256
257
  virtual bool
258
  canNurseryAllocate() const override;
259
260
  virtual size_t
261
  objectMoved(JSObject* obj, JSObject* old) const override;
262
};
263
264
MOZ_ALWAYS_INLINE bool
265
IsProxy(JSObject* obj)
266
0
{
267
0
  return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
268
0
}
269
270
MOZ_ALWAYS_INLINE nsINodeList*
271
UnwrapProxy(JSObject* obj)
272
0
{
273
0
  MOZ_ASSERT(js::IsProxy(obj));
274
0
  if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
275
0
    MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
276
0
    obj = js::UncheckedUnwrap(obj);
277
0
  }
278
0
  MOZ_ASSERT(IsProxy(obj));
279
0
  return static_cast<nsINodeList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
280
0
}
281
282
bool
283
DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
284
0
{
285
0
  bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
286
0
  uint32_t index = GetArrayIndexFromId(cx, id);
287
0
  if (IsArrayIndex(index)) {
288
0
    nsINodeList* self = UnwrapProxy(proxy);
289
0
    bool found = false;
290
0
    auto result(StrongOrRawPtr<nsINode>(self->IndexedGetter(index, found)));
291
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
292
0
293
0
    if (found) {
294
0
      if (!result) {
295
0
        desc.value().setNull();
296
0
        FillPropertyDescriptor(desc, proxy, true);
297
0
        return true;
298
0
      }
299
0
      if (!GetOrCreateDOMReflector(cx, result, desc.value())) {
300
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
301
0
        return false;
302
0
      }
303
0
      FillPropertyDescriptor(desc, proxy, true);
304
0
      return true;
305
0
    }
306
0
  }
307
0
308
0
  JS::Rooted<JSObject*> expando(cx);
309
0
  if (!isXray && (expando = GetExpandoObject(proxy))) {
310
0
    if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
311
0
      return false;
312
0
    }
313
0
    if (desc.object()) {
314
0
      // Pretend the property lives on the wrapper.
315
0
      desc.object().set(proxy);
316
0
      return true;
317
0
    }
318
0
  }
319
0
320
0
  desc.object().set(nullptr);
321
0
  return true;
322
0
}
323
324
bool
325
DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
326
0
{
327
0
  if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
328
0
    *defined = true;
329
0
    return opresult.failNoIndexedSetter();
330
0
  }
331
0
  return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined);
332
0
}
333
334
335
bool
336
DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
337
0
{
338
0
  bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
339
0
340
0
  uint32_t length = UnwrapProxy(proxy)->Length();
341
0
  MOZ_ASSERT(int32_t(length) >= 0);
342
0
  for (int32_t i = 0; i < int32_t(length); ++i) {
343
0
    if (!props.append(INT_TO_JSID(i))) {
344
0
      return false;
345
0
    }
346
0
  }
347
0
348
0
  JS::Rooted<JSObject*> expando(cx);
349
0
  if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
350
0
      !js::GetPropertyKeys(cx, expando, flags, &props)) {
351
0
    return false;
352
0
  }
353
0
354
0
  return true;
355
0
}
356
357
bool
358
DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
359
0
{
360
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
361
0
            "Should not have a XrayWrapper here");
362
0
363
0
  uint32_t index = GetArrayIndexFromId(cx, id);
364
0
  if (IsArrayIndex(index)) {
365
0
    bool found = false;
366
0
    nsINodeList* self = UnwrapProxy(proxy);
367
0
    auto result(StrongOrRawPtr<nsINode>(self->IndexedGetter(index, found)));
368
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
369
0
    (void)result;
370
0
371
0
    *bp = found;
372
0
    return true;
373
0
  }
374
0
375
0
376
0
  JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
377
0
  if (expando) {
378
0
    bool b = true;
379
0
    bool ok = JS_HasPropertyById(cx, expando, id, &b);
380
0
    *bp = !!b;
381
0
    if (!ok || *bp) {
382
0
      return ok;
383
0
    }
384
0
  }
385
0
386
0
  *bp = false;
387
0
  return true;
388
0
}
389
390
bool
391
DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
392
0
{
393
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
394
0
              "Should not have a XrayWrapper here");
395
0
396
0
  uint32_t index = GetArrayIndexFromId(cx, id);
397
0
  if (IsArrayIndex(index)) {
398
0
    nsINodeList* self = UnwrapProxy(proxy);
399
0
    bool found = false;
400
0
    auto result(StrongOrRawPtr<nsINode>(self->IndexedGetter(index, found)));
401
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
402
0
403
0
    if (found) {
404
0
      if (!result) {
405
0
        vp.setNull();
406
0
        return true;
407
0
      }
408
0
      if (!GetOrCreateDOMReflector(cx, result, vp)) {
409
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
410
0
        return false;
411
0
      }
412
0
      return true;
413
0
    }
414
0
    // Even if we don't have this index, we don't forward the
415
0
    // get on to our expando object.
416
0
  } else {
417
0
    { // Scope for expando
418
0
      JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
419
0
      if (expando) {
420
0
        bool hasProp;
421
0
        if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
422
0
          return false;
423
0
        }
424
0
425
0
        if (hasProp) {
426
0
          // Forward the get to the expando object, but our receiver is whatever our
427
0
          // receiver is.
428
0
          return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp);
429
0
        }
430
0
      }
431
0
    }
432
0
  }
433
0
434
0
  bool foundOnPrototype;
435
0
  if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
436
0
    return false;
437
0
  }
438
0
439
0
  if (foundOnPrototype) {
440
0
    return true;
441
0
  }
442
0
443
0
  vp.setUndefined();
444
0
  return true;
445
0
}
446
447
const char*
448
DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
449
0
{
450
0
  return "NodeList";
451
0
}
452
453
bool
454
DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
455
0
{
456
0
  return false;
457
0
}
458
459
void
460
DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
461
0
{
462
0
  nsINodeList* self = UnwrapPossiblyNotInitializedDOMObject<nsINodeList>(proxy);
463
0
  if (self) {
464
0
    ClearWrapper(self, self, proxy);
465
0
    AddForDeferredFinalization<nsINodeList>(self);
466
0
  }
467
0
}
468
469
const DOMProxyHandler*
470
DOMProxyHandler::getInstance()
471
0
{
472
0
  static const DOMProxyHandler instance;
473
0
  return &instance;
474
0
}
475
476
bool
477
DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
478
0
{
479
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
480
0
            "Should not have a XrayWrapper here");
481
0
482
0
  uint32_t index = GetArrayIndexFromId(cx, id);
483
0
  if (IsArrayIndex(index)) {
484
0
    bool deleteSucceeded;
485
0
    bool found = false;
486
0
    nsINodeList* self = UnwrapProxy(proxy);
487
0
    auto result(StrongOrRawPtr<nsINode>(self->IndexedGetter(index, found)));
488
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
489
0
    (void)result;
490
0
    deleteSucceeded = !found;
491
0
    return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
492
0
  }
493
0
494
0
  return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
495
0
}
496
497
bool
498
DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
499
0
{
500
0
  JS::Rooted<JS::Value> temp(cx);
501
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
502
0
             "Should not have a XrayWrapper here");
503
0
504
0
  nsINodeList* self = UnwrapProxy(proxy);
505
0
  uint32_t length = self->Length();
506
0
  // Compute the end of the indices we'll get ourselves
507
0
  uint32_t ourEnd = std::max(begin, std::min(end, length));
508
0
509
0
  for (uint32_t index = begin; index < ourEnd; ++index) {
510
0
    bool found = false;
511
0
    auto result(StrongOrRawPtr<nsINode>(self->IndexedGetter(index, found)));
512
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
513
0
514
0
    MOZ_ASSERT(found);
515
0
    if (!result) {
516
0
      temp.setNull();
517
0
      if (!adder->append(cx, temp)) return false;
518
0
      continue;
519
0
    }
520
0
    if (!GetOrCreateDOMReflector(cx, result, &temp)) {
521
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
522
0
      return false;
523
0
    }
524
0
    if (!adder->append(cx, temp)) return false;
525
0
    continue;
526
0
  }
527
0
528
0
  if (end > ourEnd) {
529
0
    JS::Rooted<JSObject*> proto(cx);
530
0
    if (!js::GetObjectProto(cx, proxy, &proto)) {
531
0
      return false;
532
0
    }
533
0
    return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
534
0
  }
535
0
536
0
  return true;
537
0
}
538
539
bool
540
DOMProxyHandler::canNurseryAllocate() const
541
0
{
542
0
  return true;
543
0
}
544
545
size_t
546
DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const
547
0
{
548
0
  nsINodeList* self = UnwrapPossiblyNotInitializedDOMObject<nsINodeList>(obj);
549
0
  if (self) {
550
0
    UpdateWrapper(self, self, obj, old);
551
0
  }
552
0
553
0
  return 0;
554
0
}
555
556
static const DOMJSClass sClass = {
557
  PROXY_CLASS_DEF("NodeList",
558
                  JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)),
559
  { prototypes::id::NodeList, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
560
  IsBaseOf<nsISupports, nsINodeList >::value,
561
  sNativePropertyHooks,
562
  FindAssociatedGlobalForNative<nsINodeList>::Get,
563
  GetProtoObjectHandle,
564
  GetCCParticipant<nsINodeList>::Get()
565
};
566
567
bool
568
Wrap(JSContext* aCx, nsINodeList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
569
0
{
570
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, nsINodeList>::value,
571
0
                "Shouldn't have wrappercached things that are not refcounted.");
572
0
  MOZ_ASSERT(static_cast<nsINodeList*>(aObject) ==
573
0
             reinterpret_cast<nsINodeList*>(aObject),
574
0
             "Multiple inheritance for nsINodeList is broken.");
575
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
576
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
577
0
  MOZ_ASSERT(!aCache->GetWrapper(),
578
0
             "You should probably not be using Wrap() directly; use "
579
0
             "GetOrCreateDOMReflector instead");
580
0
581
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
582
0
             "nsISupports must be on our primary inheritance chain");
583
0
584
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
585
0
  if (!global) {
586
0
    return false;
587
0
  }
588
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
589
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
590
0
591
0
  // That might have ended up wrapping us already, due to the wonders
592
0
  // of XBL.  Check for that, and bail out as needed.
593
0
  aReflector.set(aCache->GetWrapper());
594
0
  if (aReflector) {
595
#ifdef DEBUG
596
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
597
#endif // DEBUG
598
    return true;
599
0
  }
600
0
601
0
  JSAutoRealm ar(aCx, global);
602
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
603
0
  if (!canonicalProto) {
604
0
    return false;
605
0
  }
606
0
  JS::Rooted<JSObject*> proto(aCx);
607
0
  if (aGivenProto) {
608
0
    proto = aGivenProto;
609
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
610
0
    // coming in, we changed compartments to that of "parent" so may need
611
0
    // to wrap the proto here.
612
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
613
0
      if (!JS_WrapObject(aCx, &proto)) {
614
0
        return false;
615
0
      }
616
0
    }
617
0
  } else {
618
0
    proto = canonicalProto;
619
0
  }
620
0
621
0
  BindingJSObjectCreator<nsINodeList> creator(aCx);
622
0
  creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
623
0
                            proto, aObject, JS::UndefinedHandleValue, aReflector);
624
0
  if (!aReflector) {
625
0
    return false;
626
0
  }
627
0
628
0
  aCache->SetWrapper(aReflector);
629
0
  creator.InitializationSucceeded();
630
0
631
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
632
0
             aCache->GetWrapperPreserveColor() == aReflector);
633
0
  // If proto != canonicalProto, we have to preserve our wrapper;
634
0
  // otherwise we won't be able to properly recreate it later, since
635
0
  // we won't know what proto to use.  Note that we don't check
636
0
  // aGivenProto here, since it's entirely possible (and even
637
0
  // somewhat common) to have a non-null aGivenProto which is the
638
0
  // same as canonicalProto.
639
0
  if (proto != canonicalProto) {
640
0
    PreserveWrapper(aObject);
641
0
  }
642
0
643
0
  return true;
644
0
}
645
646
static bool
647
ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
648
0
{
649
0
  return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
650
0
}
651
652
static bool
653
EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
654
0
{
655
0
  return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
656
0
}
657
658
const NativePropertyHooks sNativePropertyHooks[] = { {
659
  ResolveOwnProperty,
660
  EnumerateOwnProperties,
661
  nullptr,
662
  { sNativeProperties.Upcast(), nullptr },
663
  prototypes::id::NodeList,
664
  constructors::id::NodeList,
665
  nullptr,
666
  &DefaultXrayExpandoObjectClass
667
} };
668
669
void
670
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
671
0
{
672
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
673
0
  if (!parentProto) {
674
0
    return;
675
0
  }
676
0
677
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
678
0
  if (!constructorProto) {
679
0
    return;
680
0
  }
681
0
682
0
  static bool sIdsInited = false;
683
0
  if (!sIdsInited && NS_IsMainThread()) {
684
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
685
0
      return;
686
0
    }
687
0
    sIdsInited = true;
688
0
  }
689
0
690
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::NodeList);
691
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::NodeList);
692
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
693
0
                              &sPrototypeClass.mBase, protoCache,
694
0
                              nullptr,
695
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
696
0
                              interfaceCache,
697
0
                              sNativeProperties.Upcast(),
698
0
                              nullptr,
699
0
                              "NodeList", aDefineOnGlobal,
700
0
                              nullptr,
701
0
                              false);
702
0
}
703
704
JSObject*
705
GetProtoObject(JSContext* aCx)
706
0
{
707
0
  return GetProtoObjectHandle(aCx);
708
0
}
709
710
JSObject*
711
GetConstructorObject(JSContext* aCx)
712
0
{
713
0
  return GetConstructorObjectHandle(aCx);
714
0
}
715
716
} // namespace NodeList_Binding
717
718
719
720
} // namespace dom
721
} // namespace mozilla