Coverage Report

Created: 2018-09-25 14:53

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