Coverage Report

Created: 2018-09-25 14:53

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