Coverage Report

Created: 2018-09-25 14:53

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