Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MozStorageStatementParamsBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MozStorageStatementParams.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "MozStorageStatementParamsBinding.h"
4
#include "WrapperFactory.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/dom/BindingUtils.h"
7
#include "mozilla/dom/DOMJSClass.h"
8
#include "mozilla/dom/DOMJSProxyHandler.h"
9
#include "mozilla/dom/NonRefcountedDOMObject.h"
10
#include "mozilla/dom/PrimitiveConversions.h"
11
#include "mozilla/dom/XrayExpandoClass.h"
12
#include "mozilla/storage/mozStorageStatementParams.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 MozStorageStatementParams_Binding {
23
24
MOZ_CAN_RUN_SCRIPT static bool
25
get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::storage::StatementParams* self, JSJitGetterCallArgs args)
26
0
{
27
0
  AUTO_PROFILER_LABEL_FAST("get MozStorageStatementParams.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::MozStorageStatementParams },
38
  { PrototypeTraits<prototypes::id::MozStorageStatementParams>::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
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
54
#if defined(__clang__)
55
#pragma clang diagnostic push
56
#pragma clang diagnostic ignored "-Wmissing-braces"
57
#endif
58
static const JSFunctionSpec sMethods_specs[] = {
59
  JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
60
  JS_FS_END
61
};
62
#if defined(__clang__)
63
#pragma clang diagnostic pop
64
#endif
65
66
67
static const Prefable<const JSFunctionSpec> sMethods[] = {
68
  { nullptr, &sMethods_specs[0] },
69
  { nullptr, nullptr }
70
};
71
72
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
73
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
74
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
75
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
76
77
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
78
#if defined(__clang__)
79
#pragma clang diagnostic push
80
#pragma clang diagnostic ignored "-Wmissing-braces"
81
#endif
82
static const JSPropertySpec sAttributes_specs[] = {
83
  { "length", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &length_getterinfo, nullptr, nullptr },
84
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
85
};
86
#if defined(__clang__)
87
#pragma clang diagnostic pop
88
#endif
89
90
91
static const Prefable<const JSPropertySpec> sAttributes[] = {
92
  { nullptr, &sAttributes_specs[0] },
93
  { nullptr, nullptr }
94
};
95
96
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
97
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
98
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
99
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
100
101
102
static uint16_t sNativeProperties_sortedPropertyIndices[2];
103
static PropertyInfo sNativeProperties_propertyInfos[2];
104
105
static const NativePropertiesN<2> sNativeProperties = {
106
  false, 0,
107
  false, 0,
108
  true,  0 /* sMethods */,
109
  true,  1 /* sAttributes */,
110
  false, 0,
111
  false, 0,
112
  false, 0,
113
  -1,
114
  2,
115
  sNativeProperties_sortedPropertyIndices,
116
  {
117
    { sMethods, &sNativeProperties_propertyInfos[0] },
118
    { sAttributes, &sNativeProperties_propertyInfos[1] }
119
  }
120
};
121
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
122
    "We have a property info count that is oversized");
123
124
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
125
  {
126
    "Function",
127
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
128
    &sBoringInterfaceObjectClassClassOps,
129
    JS_NULL_CLASS_SPEC,
130
    JS_NULL_CLASS_EXT,
131
    &sInterfaceObjectClassObjectOps
132
  },
133
  eInterface,
134
  true,
135
  prototypes::id::MozStorageStatementParams,
136
  PrototypeTraits<prototypes::id::MozStorageStatementParams>::Depth,
137
  sNativePropertyHooks,
138
  "function MozStorageStatementParams() {\n    [native code]\n}",
139
  JS::GetRealmFunctionPrototype
140
};
141
142
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
143
  {
144
    "MozStorageStatementParamsPrototype",
145
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
146
    JS_NULL_CLASS_OPS,
147
    JS_NULL_CLASS_SPEC,
148
    JS_NULL_CLASS_EXT,
149
    JS_NULL_OBJECT_OPS
150
  },
151
  eInterfacePrototype,
152
  false,
153
  prototypes::id::MozStorageStatementParams,
154
  PrototypeTraits<prototypes::id::MozStorageStatementParams>::Depth,
155
  sNativePropertyHooks,
156
  "[object MozStorageStatementParamsPrototype]",
157
  JS::GetRealmObjectPrototype
158
};
159
160
bool
161
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
162
0
{
163
0
  return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
164
0
}
165
166
static_assert(IsBaseOf<nsISupports, mozilla::storage::StatementParams >::value,
167
                  "We don't support non-nsISupports native classes for "
168
                  "proxy-based bindings yet");
169
170
171
class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
172
{
173
public:
174
  explicit constexpr DOMProxyHandler()
175
0
  {
176
0
  }
177
178
  virtual bool
179
  getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
180
181
  virtual bool
182
  defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
183
184
  using mozilla::dom::DOMProxyHandler::defineProperty;
185
186
  virtual bool
187
  ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
188
189
  virtual bool
190
  hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
191
192
  virtual bool
193
  get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
194
195
  virtual const char*
196
  className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
197
198
  virtual bool
199
  finalizeInBackground(const JS::Value& priv) const override;
200
201
  virtual void
202
  finalize(JSFreeOp* fop, JSObject* proxy) const override;
203
204
  static const DOMProxyHandler*
205
  getInstance();
206
207
  virtual bool
208
  delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
209
210
  virtual bool
211
  getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
212
213
  virtual bool
214
  setCustom(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::Value> v, bool* done) const override;
215
216
  virtual size_t
217
  objectMoved(JSObject* obj, JSObject* old) const override;
218
};
219
220
MOZ_ALWAYS_INLINE bool
221
IsProxy(JSObject* obj)
222
0
{
223
0
  return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
224
0
}
225
226
MOZ_ALWAYS_INLINE mozilla::storage::StatementParams*
227
UnwrapProxy(JSObject* obj)
228
0
{
229
0
  MOZ_ASSERT(js::IsProxy(obj));
230
0
  if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
231
0
    MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
232
0
    obj = js::UncheckedUnwrap(obj);
233
0
  }
234
0
  MOZ_ASSERT(IsProxy(obj));
235
0
  return static_cast<mozilla::storage::StatementParams*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
236
0
}
237
238
bool
239
DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
240
0
{
241
0
  bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
242
0
  uint32_t index = GetArrayIndexFromId(cx, id);
243
0
  if (IsArrayIndex(index)) {
244
0
    mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
245
0
    bool found = false;
246
0
    FastErrorResult rv;
247
0
    JS::Rooted<JS::Value> result(cx);
248
0
    self->IndexedGetter(cx, index, found, &result, rv);
249
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
250
0
      return false;
251
0
    }
252
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
253
0
254
0
    if (found) {
255
0
      JS::ExposeValueToActiveJS(result);
256
0
      desc.value().set(result);
257
0
      if (!MaybeWrapValue(cx, desc.value())) {
258
0
        return false;
259
0
      }
260
0
      FillPropertyDescriptor(desc, proxy, false);
261
0
      return true;
262
0
    }
263
0
  }
264
0
265
0
  JS::Rooted<JSObject*> expando(cx);
266
0
  if (!isXray && (expando = GetExpandoObject(proxy))) {
267
0
    if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
268
0
      return false;
269
0
    }
270
0
    if (desc.object()) {
271
0
      // Pretend the property lives on the wrapper.
272
0
      desc.object().set(proxy);
273
0
      return true;
274
0
    }
275
0
  }
276
0
277
0
  bool callNamedGetter = false;
278
0
  if (!IsArrayIndex(index) && !ignoreNamedProps) {
279
0
    bool hasOnProto;
280
0
    if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) {
281
0
      return false;
282
0
    }
283
0
    callNamedGetter = !hasOnProto;
284
0
  }
285
0
  if (callNamedGetter) {
286
0
    FakeString name;
287
0
    bool isSymbol;
288
0
    if (!ConvertIdToString(cx, id, name, isSymbol)) {
289
0
      return false;
290
0
    }
291
0
    if (!isSymbol) {
292
0
      mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
293
0
      bool found = false;
294
0
      FastErrorResult rv;
295
0
      JS::Rooted<JS::Value> result(cx);
296
0
      self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv);
297
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
298
0
        return false;
299
0
      }
300
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
301
0
302
0
      if (found) {
303
0
        JS::ExposeValueToActiveJS(result);
304
0
        desc.value().set(result);
305
0
        if (!MaybeWrapValue(cx, desc.value())) {
306
0
          return false;
307
0
        }
308
0
        FillPropertyDescriptor(desc, proxy, false, true);
309
0
        return true;
310
0
      }
311
0
    }
312
0
  }
313
0
314
0
  desc.object().set(nullptr);
315
0
  return true;
316
0
}
317
318
bool
319
DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
320
0
{
321
0
  uint32_t index = GetArrayIndexFromId(cx, id);
322
0
  if (IsArrayIndex(index)) {
323
0
    *defined = true;
324
0
    // https://heycam.github.io/webidl/#legacy-platform-object-defineownproperty
325
0
    // Step 1.1.  The no-indexed-setter case is handled by step 1.2.
326
0
    if (!desc.isDataDescriptor()) {
327
0
      return opresult.failNotDataDescriptor();
328
0
    }
329
0
330
0
    mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
331
0
    JS::Rooted<JS::Value> rootedValue(cx, desc.value());
332
0
    JS::Rooted<JS::Value> arg(cx);
333
0
    arg = desc.value();
334
0
    FastErrorResult rv;
335
0
    self->IndexedSetter(cx, index, arg, rv);
336
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
337
0
      return false;
338
0
    }
339
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
340
0
    return opresult.succeed();
341
0
  }
342
0
  *defined = true;
343
0
  FakeString name;
344
0
  bool isSymbol;
345
0
  if (!ConvertIdToString(cx, id, name, isSymbol)) {
346
0
    return false;
347
0
  }
348
0
  if (!isSymbol) {
349
0
    mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
350
0
    JS::Rooted<JS::Value> rootedValue(cx, desc.value());
351
0
    JS::Rooted<JS::Value> arg(cx);
352
0
    arg = desc.value();
353
0
    FastErrorResult rv;
354
0
    self->NamedSetter(cx, NonNullHelper(Constify(name)), arg, rv);
355
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
356
0
      return false;
357
0
    }
358
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
359
0
  }
360
0
361
0
  return opresult.succeed();
362
0
}
363
364
365
bool
366
DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
367
0
{
368
0
  bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
369
0
370
0
  uint32_t length = UnwrapProxy(proxy)->Length();
371
0
  MOZ_ASSERT(int32_t(length) >= 0);
372
0
  for (int32_t i = 0; i < int32_t(length); ++i) {
373
0
    if (!props.append(INT_TO_JSID(i))) {
374
0
      return false;
375
0
    }
376
0
  }
377
0
378
0
  nsTArray<nsString> names;
379
0
  UnwrapProxy(proxy)->GetSupportedNames(names);
380
0
  if (!AppendNamedPropertyIds(cx, proxy, names, false, props)) {
381
0
    return false;
382
0
  }
383
0
384
0
  JS::Rooted<JSObject*> expando(cx);
385
0
  if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
386
0
      !js::GetPropertyKeys(cx, expando, flags, &props)) {
387
0
    return false;
388
0
  }
389
0
390
0
  return true;
391
0
}
392
393
bool
394
DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
395
0
{
396
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
397
0
            "Should not have a XrayWrapper here");
398
0
399
0
  uint32_t index = GetArrayIndexFromId(cx, id);
400
0
  if (IsArrayIndex(index)) {
401
0
    bool found = false;
402
0
    mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
403
0
    FastErrorResult rv;
404
0
    JS::Rooted<JS::Value> result(cx);
405
0
    self->IndexedGetter(cx, index, found, &result, rv);
406
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
407
0
      return false;
408
0
    }
409
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
410
0
    (void)result;
411
0
412
0
    *bp = found;
413
0
    return true;
414
0
  }
415
0
416
0
417
0
  JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
418
0
  if (expando) {
419
0
    bool b = true;
420
0
    bool ok = JS_HasPropertyById(cx, expando, id, &b);
421
0
    *bp = !!b;
422
0
    if (!ok || *bp) {
423
0
      return ok;
424
0
    }
425
0
  }
426
0
427
0
  bool hasOnProto;
428
0
  if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) {
429
0
    return false;
430
0
  }
431
0
  if (!hasOnProto) {
432
0
    bool found = false;
433
0
    FakeString name;
434
0
    bool isSymbol;
435
0
    if (!ConvertIdToString(cx, id, name, isSymbol)) {
436
0
      return false;
437
0
    }
438
0
    if (!isSymbol) {
439
0
      mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
440
0
      FastErrorResult rv;
441
0
      JS::Rooted<JS::Value> result(cx);
442
0
      self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv);
443
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
444
0
        return false;
445
0
      }
446
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
447
0
      (void)result;
448
0
    }
449
0
450
0
    *bp = found;
451
0
    return true;
452
0
  }
453
0
  *bp = false;
454
0
  return true;
455
0
}
456
457
bool
458
DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
459
0
{
460
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
461
0
              "Should not have a XrayWrapper here");
462
0
463
0
  uint32_t index = GetArrayIndexFromId(cx, id);
464
0
  if (IsArrayIndex(index)) {
465
0
    mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
466
0
    bool found = false;
467
0
    FastErrorResult rv;
468
0
    JS::Rooted<JS::Value> result(cx);
469
0
    self->IndexedGetter(cx, index, found, &result, rv);
470
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
471
0
      return false;
472
0
    }
473
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
474
0
475
0
    if (found) {
476
0
      JS::ExposeValueToActiveJS(result);
477
0
      vp.set(result);
478
0
      if (!MaybeWrapValue(cx, vp)) {
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
  if (!IsArrayIndex(index)) {
513
0
    FakeString name;
514
0
    bool isSymbol;
515
0
    if (!ConvertIdToString(cx, id, name, isSymbol)) {
516
0
      return false;
517
0
    }
518
0
    if (!isSymbol) {
519
0
      mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
520
0
      bool found = false;
521
0
      FastErrorResult rv;
522
0
      JS::Rooted<JS::Value> result(cx);
523
0
      self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv);
524
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
525
0
        return false;
526
0
      }
527
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
528
0
529
0
      if (found) {
530
0
        JS::ExposeValueToActiveJS(result);
531
0
        vp.set(result);
532
0
        if (!MaybeWrapValue(cx, vp)) {
533
0
          return false;
534
0
        }
535
0
        return true;
536
0
      }
537
0
    }
538
0
  }
539
0
540
0
  vp.setUndefined();
541
0
  return true;
542
0
}
543
544
const char*
545
DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
546
0
{
547
0
  return "MozStorageStatementParams";
548
0
}
549
550
bool
551
DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
552
0
{
553
0
  return false;
554
0
}
555
556
void
557
DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
558
0
{
559
0
  mozilla::storage::StatementParams* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::storage::StatementParams>(proxy);
560
0
  if (self) {
561
0
    ClearWrapper(self, self, proxy);
562
0
    AddForDeferredFinalization<mozilla::storage::StatementParams>(self);
563
0
  }
564
0
}
565
566
const DOMProxyHandler*
567
DOMProxyHandler::getInstance()
568
0
{
569
0
  static const DOMProxyHandler instance;
570
0
  return &instance;
571
0
}
572
573
bool
574
DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
575
0
{
576
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
577
0
            "Should not have a XrayWrapper here");
578
0
579
0
  uint32_t index = GetArrayIndexFromId(cx, id);
580
0
  if (IsArrayIndex(index)) {
581
0
    bool deleteSucceeded;
582
0
    bool found = false;
583
0
    mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
584
0
    FastErrorResult rv;
585
0
    JS::Rooted<JS::Value> result(cx);
586
0
    self->IndexedGetter(cx, index, found, &result, rv);
587
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
588
0
      return false;
589
0
    }
590
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
591
0
    (void)result;
592
0
    deleteSucceeded = !found;
593
0
    return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
594
0
  }
595
0
  // Try named delete only if the named property visibility
596
0
  // algorithm says the property is visible.
597
0
  bool tryNamedDelete = true;
598
0
  { // Scope for expando
599
0
    JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
600
0
    if (expando) {
601
0
      bool hasProp;
602
0
      if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
603
0
        return false;
604
0
      }
605
0
      tryNamedDelete = !hasProp;
606
0
    }
607
0
  }
608
0
  if (tryNamedDelete) {
609
0
    bool hasOnProto;
610
0
    if (!HasPropertyOnPrototype(cx, proxy, id, &hasOnProto)) {
611
0
      return false;
612
0
    }
613
0
    tryNamedDelete = !hasOnProto;
614
0
  }
615
0
  if (tryNamedDelete) {
616
0
    bool found = false;
617
0
    bool deleteSucceeded;
618
0
    FakeString name;
619
0
    bool isSymbol;
620
0
    if (!ConvertIdToString(cx, id, name, isSymbol)) {
621
0
      return false;
622
0
    }
623
0
    if (!isSymbol) {
624
0
      mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
625
0
      FastErrorResult rv;
626
0
      JS::Rooted<JS::Value> result(cx);
627
0
      self->NamedGetter(cx, NonNullHelper(Constify(name)), found, &result, rv);
628
0
      if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
629
0
        return false;
630
0
      }
631
0
      MOZ_ASSERT(!JS_IsExceptionPending(cx));
632
0
      (void)result;
633
0
    }
634
0
    deleteSucceeded = !found;
635
0
    if (found) {
636
0
      return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
637
0
    }
638
0
  }
639
0
640
0
  return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
641
0
}
642
643
bool
644
DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
645
0
{
646
0
  JS::Rooted<JS::Value> temp(cx);
647
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
648
0
             "Should not have a XrayWrapper here");
649
0
650
0
  mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
651
0
  uint32_t length = self->Length();
652
0
  // Compute the end of the indices we'll get ourselves
653
0
  uint32_t ourEnd = std::max(begin, std::min(end, length));
654
0
655
0
  for (uint32_t index = begin; index < ourEnd; ++index) {
656
0
    bool found = false;
657
0
    FastErrorResult rv;
658
0
    JS::Rooted<JS::Value> result(cx);
659
0
    self->IndexedGetter(cx, index, found, &result, rv);
660
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
661
0
      return false;
662
0
    }
663
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
664
0
665
0
    MOZ_ASSERT(found);
666
0
    JS::ExposeValueToActiveJS(result);
667
0
    temp.set(result);
668
0
    if (!MaybeWrapValue(cx, &temp)) {
669
0
      return false;
670
0
    }
671
0
    if (!adder->append(cx, temp)) return false;
672
0
    continue;
673
0
  }
674
0
675
0
  if (end > ourEnd) {
676
0
    JS::Rooted<JSObject*> proto(cx);
677
0
    if (!js::GetObjectProto(cx, proxy, &proto)) {
678
0
      return false;
679
0
    }
680
0
    return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
681
0
  }
682
0
683
0
  return true;
684
0
}
685
686
bool
687
DOMProxyHandler::setCustom(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::Value> v, bool* done) const
688
0
{
689
0
  MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
690
0
             "Should not have a XrayWrapper here");
691
0
  uint32_t index = GetArrayIndexFromId(cx, id);
692
0
  if (IsArrayIndex(index)) {
693
0
    mozilla::storage::StatementParams* self = UnwrapProxy(proxy);
694
0
    JS::Rooted<JS::Value> rootedValue(cx, v);
695
0
    JS::Rooted<JS::Value> arg(cx);
696
0
    arg = v;
697
0
    FastErrorResult rv;
698
0
    self->IndexedSetter(cx, index, arg, rv);
699
0
    if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
700
0
      return false;
701
0
    }
702
0
    MOZ_ASSERT(!JS_IsExceptionPending(cx));
703
0
    *done = true;
704
0
    return true;
705
0
  }
706
0
707
0
  *done = false;
708
0
  return true;
709
0
}
710
711
size_t
712
DOMProxyHandler::objectMoved(JSObject* obj, JSObject* old) const
713
0
{
714
0
  mozilla::storage::StatementParams* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::storage::StatementParams>(obj);
715
0
  if (self) {
716
0
    UpdateWrapper(self, self, obj, old);
717
0
  }
718
0
719
0
  return 0;
720
0
}
721
722
static const DOMJSClass sClass = {
723
  PROXY_CLASS_DEF("MozStorageStatementParams",
724
                  JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1)),
725
  { prototypes::id::MozStorageStatementParams, 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 },
726
  IsBaseOf<nsISupports, mozilla::storage::StatementParams >::value,
727
  sNativePropertyHooks,
728
  FindAssociatedGlobalForNative<mozilla::storage::StatementParams>::Get,
729
  GetProtoObjectHandle,
730
  GetCCParticipant<mozilla::storage::StatementParams>::Get()
731
};
732
733
bool
734
Wrap(JSContext* aCx, mozilla::storage::StatementParams* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
735
0
{
736
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::storage::StatementParams>::value,
737
0
                "Shouldn't have wrappercached things that are not refcounted.");
738
0
  MOZ_ASSERT(static_cast<mozilla::storage::StatementParams*>(aObject) ==
739
0
             reinterpret_cast<mozilla::storage::StatementParams*>(aObject),
740
0
             "Multiple inheritance for mozilla::storage::StatementParams is broken.");
741
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
742
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
743
0
  MOZ_ASSERT(!aCache->GetWrapper(),
744
0
             "You should probably not be using Wrap() directly; use "
745
0
             "GetOrCreateDOMReflector instead");
746
0
747
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
748
0
             "nsISupports must be on our primary inheritance chain");
749
0
750
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
751
0
  if (!global) {
752
0
    return false;
753
0
  }
754
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
755
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
756
0
757
0
  // That might have ended up wrapping us already, due to the wonders
758
0
  // of XBL.  Check for that, and bail out as needed.
759
0
  aReflector.set(aCache->GetWrapper());
760
0
  if (aReflector) {
761
#ifdef DEBUG
762
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
763
#endif // DEBUG
764
    return true;
765
0
  }
766
0
767
0
  JSAutoRealm ar(aCx, global);
768
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
769
0
  if (!canonicalProto) {
770
0
    return false;
771
0
  }
772
0
  JS::Rooted<JSObject*> proto(aCx);
773
0
  if (aGivenProto) {
774
0
    proto = aGivenProto;
775
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
776
0
    // coming in, we changed compartments to that of "parent" so may need
777
0
    // to wrap the proto here.
778
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
779
0
      if (!JS_WrapObject(aCx, &proto)) {
780
0
        return false;
781
0
      }
782
0
    }
783
0
  } else {
784
0
    proto = canonicalProto;
785
0
  }
786
0
787
0
  BindingJSObjectCreator<mozilla::storage::StatementParams> creator(aCx);
788
0
  creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
789
0
                            proto, aObject, JS::UndefinedHandleValue, aReflector);
790
0
  if (!aReflector) {
791
0
    return false;
792
0
  }
793
0
794
0
  aCache->SetWrapper(aReflector);
795
0
  creator.InitializationSucceeded();
796
0
797
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
798
0
             aCache->GetWrapperPreserveColor() == aReflector);
799
0
  // If proto != canonicalProto, we have to preserve our wrapper;
800
0
  // otherwise we won't be able to properly recreate it later, since
801
0
  // we won't know what proto to use.  Note that we don't check
802
0
  // aGivenProto here, since it's entirely possible (and even
803
0
  // somewhat common) to have a non-null aGivenProto which is the
804
0
  // same as canonicalProto.
805
0
  if (proto != canonicalProto) {
806
0
    PreserveWrapper(aObject);
807
0
  }
808
0
809
0
  return true;
810
0
}
811
812
static bool
813
ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
814
0
{
815
0
  return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
816
0
}
817
818
static bool
819
EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
820
0
{
821
0
  return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
822
0
}
823
824
const NativePropertyHooks sNativePropertyHooks[] = { {
825
  ResolveOwnProperty,
826
  EnumerateOwnProperties,
827
  nullptr,
828
  { sNativeProperties.Upcast(), nullptr },
829
  prototypes::id::MozStorageStatementParams,
830
  constructors::id::MozStorageStatementParams,
831
  nullptr,
832
  &DefaultXrayExpandoObjectClass
833
} };
834
835
void
836
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
837
0
{
838
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
839
0
  if (!parentProto) {
840
0
    return;
841
0
  }
842
0
843
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
844
0
  if (!constructorProto) {
845
0
    return;
846
0
  }
847
0
848
0
  static bool sIdsInited = false;
849
0
  if (!sIdsInited && NS_IsMainThread()) {
850
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
851
0
      return;
852
0
    }
853
0
    sIdsInited = true;
854
0
  }
855
0
856
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MozStorageStatementParams);
857
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MozStorageStatementParams);
858
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
859
0
                              &sPrototypeClass.mBase, protoCache,
860
0
                              nullptr,
861
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
862
0
                              interfaceCache,
863
0
                              sNativeProperties.Upcast(),
864
0
                              nullptr,
865
0
                              "MozStorageStatementParams", aDefineOnGlobal,
866
0
                              nullptr,
867
0
                              false);
868
0
}
869
870
JSObject*
871
GetConstructorObject(JSContext* aCx)
872
0
{
873
0
  return GetConstructorObjectHandle(aCx);
874
0
}
875
876
} // namespace MozStorageStatementParams_Binding
877
878
879
880
} // namespace dom
881
} // namespace mozilla