Coverage Report

Created: 2018-09-25 14:53

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