Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/IDBCursorBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM IDBCursor.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "IDBCursorBinding.h"
4
#include "WrapperFactory.h"
5
#include "jsapi.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/IDBCursor.h"
10
#include "mozilla/dom/IDBIndex.h"
11
#include "mozilla/dom/IDBObjectStore.h"
12
#include "mozilla/dom/IDBRequest.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/UnionConversions.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
namespace binding_detail {}; // Just to make sure it's known as a namespace
22
using namespace mozilla::dom::binding_detail;
23
24
25
namespace IDBCursorDirectionValues {
26
extern const EnumEntry strings[5] = {
27
  {"next", 4},
28
  {"nextunique", 10},
29
  {"prev", 4},
30
  {"prevunique", 10},
31
  { nullptr, 0 }
32
};
33
} // namespace IDBCursorDirectionValues
34
35
bool
36
ToJSValue(JSContext* aCx, IDBCursorDirection aArgument, JS::MutableHandle<JS::Value> aValue)
37
0
{
38
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(IDBCursorDirectionValues::strings));
39
0
  JSString* resultStr =
40
0
    JS_NewStringCopyN(aCx, IDBCursorDirectionValues::strings[uint32_t(aArgument)].value,
41
0
                      IDBCursorDirectionValues::strings[uint32_t(aArgument)].length);
42
0
  if (!resultStr) {
43
0
    return false;
44
0
  }
45
0
  aValue.setString(resultStr);
46
0
  return true;
47
0
}
48
49
50
void
51
ImplCycleCollectionTraverse(nsCycleCollectionTraversalCallback& aCallback, OwningIDBObjectStoreOrIDBIndex& aUnion, const char* aName, uint32_t aFlags)
52
0
{
53
0
  if (aUnion.IsIDBObjectStore()) {
54
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsIDBObjectStore(), "mIDBObjectStore", aFlags);
55
0
  } else if (aUnion.IsIDBIndex()) {
56
0
    ImplCycleCollectionTraverse(aCallback, aUnion.GetAsIDBIndex(), "mIDBIndex", aFlags);
57
0
  }
58
0
}
59
60
61
void
62
ImplCycleCollectionUnlink(OwningIDBObjectStoreOrIDBIndex& aUnion)
63
0
{
64
0
  aUnion.Uninit();
65
0
}
66
67
68
bool
69
IDBObjectStoreOrIDBIndex::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
70
0
{
71
0
  switch (mType) {
72
0
    case eUninitialized: {
73
0
      return false;
74
0
      break;
75
0
    }
76
0
    case eIDBObjectStore: {
77
0
      if (!GetOrCreateDOMReflector(cx, mValue.mIDBObjectStore.Value(), rval)) {
78
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
79
0
        return false;
80
0
      }
81
0
      return true;
82
0
      break;
83
0
    }
84
0
    case eIDBIndex: {
85
0
      if (!GetOrCreateDOMReflector(cx, mValue.mIDBIndex.Value(), rval)) {
86
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
87
0
        return false;
88
0
      }
89
0
      return true;
90
0
      break;
91
0
    }
92
0
    default: {
93
0
      return false;
94
0
      break;
95
0
    }
96
0
  }
97
0
98
0
  return false;
99
0
}
100
101
102
OwningNonNull<mozilla::dom::IDBObjectStore>&
103
OwningIDBObjectStoreOrIDBIndex::RawSetAsIDBObjectStore()
104
0
{
105
0
  if (mType == eIDBObjectStore) {
106
0
    return mValue.mIDBObjectStore.Value();
107
0
  }
108
0
  MOZ_ASSERT(mType == eUninitialized);
109
0
  mType = eIDBObjectStore;
110
0
  return mValue.mIDBObjectStore.SetValue();
111
0
}
112
113
OwningNonNull<mozilla::dom::IDBObjectStore>&
114
OwningIDBObjectStoreOrIDBIndex::SetAsIDBObjectStore()
115
0
{
116
0
  if (mType == eIDBObjectStore) {
117
0
    return mValue.mIDBObjectStore.Value();
118
0
  }
119
0
  Uninit();
120
0
  mType = eIDBObjectStore;
121
0
  return mValue.mIDBObjectStore.SetValue();
122
0
}
123
124
bool
125
OwningIDBObjectStoreOrIDBIndex::TrySetToIDBObjectStore(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
126
0
{
127
0
  tryNext = false;
128
0
  { // scope for memberSlot
129
0
    OwningNonNull<mozilla::dom::IDBObjectStore>& memberSlot = RawSetAsIDBObjectStore();
130
0
    static_assert(IsRefcounted<mozilla::dom::IDBObjectStore>::value, "We can only store refcounted classes.");{
131
0
      nsresult rv = UnwrapObject<prototypes::id::IDBObjectStore, mozilla::dom::IDBObjectStore>(value, memberSlot);
132
0
      if (NS_FAILED(rv)) {
133
0
        DestroyIDBObjectStore();
134
0
        tryNext = true;
135
0
        return true;
136
0
      }
137
0
    }
138
0
  }
139
0
  return true;
140
0
}
141
142
void
143
OwningIDBObjectStoreOrIDBIndex::DestroyIDBObjectStore()
144
0
{
145
0
  MOZ_ASSERT(IsIDBObjectStore(), "Wrong type!");
146
0
  mValue.mIDBObjectStore.Destroy();
147
0
  mType = eUninitialized;
148
0
}
149
150
151
152
153
OwningNonNull<mozilla::dom::IDBIndex>&
154
OwningIDBObjectStoreOrIDBIndex::RawSetAsIDBIndex()
155
0
{
156
0
  if (mType == eIDBIndex) {
157
0
    return mValue.mIDBIndex.Value();
158
0
  }
159
0
  MOZ_ASSERT(mType == eUninitialized);
160
0
  mType = eIDBIndex;
161
0
  return mValue.mIDBIndex.SetValue();
162
0
}
163
164
OwningNonNull<mozilla::dom::IDBIndex>&
165
OwningIDBObjectStoreOrIDBIndex::SetAsIDBIndex()
166
0
{
167
0
  if (mType == eIDBIndex) {
168
0
    return mValue.mIDBIndex.Value();
169
0
  }
170
0
  Uninit();
171
0
  mType = eIDBIndex;
172
0
  return mValue.mIDBIndex.SetValue();
173
0
}
174
175
bool
176
OwningIDBObjectStoreOrIDBIndex::TrySetToIDBIndex(JSContext* cx, JS::Handle<JS::Value> value, bool& tryNext, bool passedToJSImpl)
177
0
{
178
0
  tryNext = false;
179
0
  { // scope for memberSlot
180
0
    OwningNonNull<mozilla::dom::IDBIndex>& memberSlot = RawSetAsIDBIndex();
181
0
    static_assert(IsRefcounted<mozilla::dom::IDBIndex>::value, "We can only store refcounted classes.");{
182
0
      nsresult rv = UnwrapObject<prototypes::id::IDBIndex, mozilla::dom::IDBIndex>(value, memberSlot);
183
0
      if (NS_FAILED(rv)) {
184
0
        DestroyIDBIndex();
185
0
        tryNext = true;
186
0
        return true;
187
0
      }
188
0
    }
189
0
  }
190
0
  return true;
191
0
}
192
193
void
194
OwningIDBObjectStoreOrIDBIndex::DestroyIDBIndex()
195
0
{
196
0
  MOZ_ASSERT(IsIDBIndex(), "Wrong type!");
197
0
  mValue.mIDBIndex.Destroy();
198
0
  mType = eUninitialized;
199
0
}
200
201
202
203
204
void
205
OwningIDBObjectStoreOrIDBIndex::Uninit()
206
{
207
  switch (mType) {
208
    case eUninitialized: {
209
      break;
210
    }
211
    case eIDBObjectStore: {
212
      DestroyIDBObjectStore();
213
      break;
214
    }
215
    case eIDBIndex: {
216
      DestroyIDBIndex();
217
      break;
218
    }
219
  }
220
}
221
222
bool
223
OwningIDBObjectStoreOrIDBIndex::ToJSVal(JSContext* cx, JS::Handle<JSObject*> scopeObj, JS::MutableHandle<JS::Value> rval) const
224
0
{
225
0
  switch (mType) {
226
0
    case eUninitialized: {
227
0
      return false;
228
0
      break;
229
0
    }
230
0
    case eIDBObjectStore: {
231
0
      if (!GetOrCreateDOMReflector(cx, mValue.mIDBObjectStore.Value(), rval)) {
232
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
233
0
        return false;
234
0
      }
235
0
      return true;
236
0
      break;
237
0
    }
238
0
    case eIDBIndex: {
239
0
      if (!GetOrCreateDOMReflector(cx, mValue.mIDBIndex.Value(), rval)) {
240
0
        MOZ_ASSERT(JS_IsExceptionPending(cx));
241
0
        return false;
242
0
      }
243
0
      return true;
244
0
      break;
245
0
    }
246
0
    default: {
247
0
      return false;
248
0
      break;
249
0
    }
250
0
  }
251
0
252
0
  return false;
253
0
}
254
255
void
256
OwningIDBObjectStoreOrIDBIndex::TraceUnion(JSTracer* trc)
257
0
{
258
0
}
259
260
OwningIDBObjectStoreOrIDBIndex&
261
OwningIDBObjectStoreOrIDBIndex::operator=(const OwningIDBObjectStoreOrIDBIndex& aOther)
262
0
{
263
0
  switch (aOther.mType) {
264
0
    case eUninitialized: {
265
0
      MOZ_ASSERT(mType == eUninitialized,
266
0
                 "We need to destroy ourselves?");
267
0
      break;
268
0
    }
269
0
    case eIDBObjectStore: {
270
0
      SetAsIDBObjectStore() = aOther.GetAsIDBObjectStore();
271
0
      break;
272
0
    }
273
0
    case eIDBIndex: {
274
0
      SetAsIDBIndex() = aOther.GetAsIDBIndex();
275
0
      break;
276
0
    }
277
0
  }
278
0
  return *this;
279
0
}
280
281
282
namespace IDBCursor_Binding {
283
284
MOZ_CAN_RUN_SCRIPT static bool
285
get_source(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, JSJitGetterCallArgs args)
286
0
{
287
0
  AUTO_PROFILER_LABEL_FAST("get IDBCursor.source", DOM, cx);
288
0
289
0
  OwningIDBObjectStoreOrIDBIndex result;
290
0
  self->GetSource(result);
291
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
292
0
  if (!result.ToJSVal(cx, obj, args.rval())) {
293
0
    return false;
294
0
  }
295
0
  return true;
296
0
}
297
298
static const JSJitInfo source_getterinfo = {
299
  { (JSJitGetterOp)get_source },
300
  { prototypes::id::IDBCursor },
301
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
302
  JSJitInfo::Getter,
303
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
304
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
305
  false,  /* isInfallible. False in setters. */
306
  false,  /* isMovable.  Not relevant for setters. */
307
  false, /* isEliminatable.  Not relevant for setters. */
308
  false, /* isAlwaysInSlot.  Only relevant for getters. */
309
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
310
  false,  /* isTypedMethod.  Only relevant for methods. */
311
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
312
};
313
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
314
static_assert(0 < 1, "There is no slot for us");
315
316
MOZ_CAN_RUN_SCRIPT static bool
317
get_direction(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, JSJitGetterCallArgs args)
318
0
{
319
0
  AUTO_PROFILER_LABEL_FAST("get IDBCursor.direction", DOM, cx);
320
0
321
0
  IDBCursorDirection result(self->GetDirection());
322
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
323
0
  if (!ToJSValue(cx, result, args.rval())) {
324
0
    return false;
325
0
  }
326
0
  return true;
327
0
}
328
329
static const JSJitInfo direction_getterinfo = {
330
  { (JSJitGetterOp)get_direction },
331
  { prototypes::id::IDBCursor },
332
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
333
  JSJitInfo::Getter,
334
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
335
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
336
  false,  /* isInfallible. False in setters. */
337
  false,  /* isMovable.  Not relevant for setters. */
338
  false, /* isEliminatable.  Not relevant for setters. */
339
  false, /* isAlwaysInSlot.  Only relevant for getters. */
340
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
341
  false,  /* isTypedMethod.  Only relevant for methods. */
342
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
343
};
344
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
345
static_assert(0 < 1, "There is no slot for us");
346
347
MOZ_CAN_RUN_SCRIPT static bool
348
get_key(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, JSJitGetterCallArgs args)
349
0
{
350
0
  AUTO_PROFILER_LABEL_FAST("get IDBCursor.key", DOM, cx);
351
0
352
0
  FastErrorResult rv;
353
0
  JS::Rooted<JS::Value> result(cx);
354
0
  self->GetKey(cx, &result, rv);
355
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
356
0
    return false;
357
0
  }
358
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
359
0
  JS::ExposeValueToActiveJS(result);
360
0
  args.rval().set(result);
361
0
  if (!MaybeWrapValue(cx, args.rval())) {
362
0
    return false;
363
0
  }
364
0
  return true;
365
0
}
366
367
static const JSJitInfo key_getterinfo = {
368
  { (JSJitGetterOp)get_key },
369
  { prototypes::id::IDBCursor },
370
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
371
  JSJitInfo::Getter,
372
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
373
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
374
  false,  /* isInfallible. False in setters. */
375
  false,  /* isMovable.  Not relevant for setters. */
376
  false, /* isEliminatable.  Not relevant for setters. */
377
  false, /* isAlwaysInSlot.  Only relevant for getters. */
378
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
379
  false,  /* isTypedMethod.  Only relevant for methods. */
380
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
381
};
382
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
383
static_assert(0 < 1, "There is no slot for us");
384
385
MOZ_CAN_RUN_SCRIPT static bool
386
get_primaryKey(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, JSJitGetterCallArgs args)
387
0
{
388
0
  AUTO_PROFILER_LABEL_FAST("get IDBCursor.primaryKey", DOM, cx);
389
0
390
0
  FastErrorResult rv;
391
0
  JS::Rooted<JS::Value> result(cx);
392
0
  self->GetPrimaryKey(cx, &result, rv);
393
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
394
0
    return false;
395
0
  }
396
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
397
0
  JS::ExposeValueToActiveJS(result);
398
0
  args.rval().set(result);
399
0
  if (!MaybeWrapValue(cx, args.rval())) {
400
0
    return false;
401
0
  }
402
0
  return true;
403
0
}
404
405
static const JSJitInfo primaryKey_getterinfo = {
406
  { (JSJitGetterOp)get_primaryKey },
407
  { prototypes::id::IDBCursor },
408
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
409
  JSJitInfo::Getter,
410
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
411
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
412
  false,  /* isInfallible. False in setters. */
413
  false,  /* isMovable.  Not relevant for setters. */
414
  false, /* isEliminatable.  Not relevant for setters. */
415
  false, /* isAlwaysInSlot.  Only relevant for getters. */
416
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
417
  false,  /* isTypedMethod.  Only relevant for methods. */
418
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
419
};
420
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
421
static_assert(0 < 1, "There is no slot for us");
422
423
MOZ_CAN_RUN_SCRIPT static bool
424
update(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, const JSJitMethodCallArgs& args)
425
0
{
426
0
  AUTO_PROFILER_LABEL_FAST("IDBCursor.update", DOM, cx);
427
0
428
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
429
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBCursor.update");
430
0
  }
431
0
  JS::Rooted<JS::Value> arg0(cx);
432
0
  arg0 = args[0];
433
0
  FastErrorResult rv;
434
0
  auto result(StrongOrRawPtr<mozilla::dom::IDBRequest>(self->Update(cx, arg0, rv)));
435
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
436
0
    return false;
437
0
  }
438
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
439
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
440
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
441
0
    return false;
442
0
  }
443
0
  return true;
444
0
}
445
446
static const JSJitInfo update_methodinfo = {
447
  { (JSJitGetterOp)update },
448
  { prototypes::id::IDBCursor },
449
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
450
  JSJitInfo::Method,
451
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
452
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
453
  false,  /* isInfallible. False in setters. */
454
  false,  /* isMovable.  Not relevant for setters. */
455
  false, /* isEliminatable.  Not relevant for setters. */
456
  false, /* isAlwaysInSlot.  Only relevant for getters. */
457
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
458
  false,  /* isTypedMethod.  Only relevant for methods. */
459
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
460
};
461
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
462
static_assert(0 < 1, "There is no slot for us");
463
464
MOZ_CAN_RUN_SCRIPT static bool
465
advance(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, const JSJitMethodCallArgs& args)
466
0
{
467
0
  AUTO_PROFILER_LABEL_FAST("IDBCursor.advance", DOM, cx);
468
0
469
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
470
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBCursor.advance");
471
0
  }
472
0
  uint32_t arg0;
473
0
  if (!ValueToPrimitive<uint32_t, eEnforceRange>(cx, args[0], &arg0)) {
474
0
    return false;
475
0
  }
476
0
  FastErrorResult rv;
477
0
  self->Advance(arg0, rv);
478
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
479
0
    return false;
480
0
  }
481
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
482
0
  args.rval().setUndefined();
483
0
  return true;
484
0
}
485
486
static const JSJitInfo advance_methodinfo = {
487
  { (JSJitGetterOp)advance },
488
  { prototypes::id::IDBCursor },
489
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
490
  JSJitInfo::Method,
491
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
492
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
493
  false,  /* isInfallible. False in setters. */
494
  false,  /* isMovable.  Not relevant for setters. */
495
  false, /* isEliminatable.  Not relevant for setters. */
496
  false, /* isAlwaysInSlot.  Only relevant for getters. */
497
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
498
  false,  /* isTypedMethod.  Only relevant for methods. */
499
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
500
};
501
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
502
static_assert(0 < 1, "There is no slot for us");
503
504
MOZ_CAN_RUN_SCRIPT static bool
505
_continue_(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, const JSJitMethodCallArgs& args)
506
0
{
507
0
  AUTO_PROFILER_LABEL_FAST("IDBCursor.continue", DOM, cx);
508
0
509
0
  JS::Rooted<JS::Value> arg0(cx);
510
0
  if (args.hasDefined(0)) {
511
0
    arg0 = args[0];
512
0
  } else {
513
0
    arg0 = JS::UndefinedValue();
514
0
  }
515
0
  FastErrorResult rv;
516
0
  self->Continue(cx, arg0, rv);
517
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
518
0
    return false;
519
0
  }
520
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
521
0
  args.rval().setUndefined();
522
0
  return true;
523
0
}
524
525
static const JSJitInfo continue_methodinfo = {
526
  { (JSJitGetterOp)_continue_ },
527
  { prototypes::id::IDBCursor },
528
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
529
  JSJitInfo::Method,
530
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
531
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
532
  false,  /* isInfallible. False in setters. */
533
  false,  /* isMovable.  Not relevant for setters. */
534
  false, /* isEliminatable.  Not relevant for setters. */
535
  false, /* isAlwaysInSlot.  Only relevant for getters. */
536
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
537
  false,  /* isTypedMethod.  Only relevant for methods. */
538
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
539
};
540
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
541
static_assert(0 < 1, "There is no slot for us");
542
543
MOZ_CAN_RUN_SCRIPT static bool
544
continuePrimaryKey(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, const JSJitMethodCallArgs& args)
545
0
{
546
0
  AUTO_PROFILER_LABEL_FAST("IDBCursor.continuePrimaryKey", DOM, cx);
547
0
548
0
  if (MOZ_UNLIKELY(args.length() < 2)) {
549
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "IDBCursor.continuePrimaryKey");
550
0
  }
551
0
  JS::Rooted<JS::Value> arg0(cx);
552
0
  arg0 = args[0];
553
0
  JS::Rooted<JS::Value> arg1(cx);
554
0
  arg1 = args[1];
555
0
  FastErrorResult rv;
556
0
  self->ContinuePrimaryKey(cx, arg0, arg1, rv);
557
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
558
0
    return false;
559
0
  }
560
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
561
0
  args.rval().setUndefined();
562
0
  return true;
563
0
}
564
565
static const JSJitInfo continuePrimaryKey_methodinfo = {
566
  { (JSJitGetterOp)continuePrimaryKey },
567
  { prototypes::id::IDBCursor },
568
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
569
  JSJitInfo::Method,
570
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
571
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
572
  false,  /* isInfallible. False in setters. */
573
  false,  /* isMovable.  Not relevant for setters. */
574
  false, /* isEliminatable.  Not relevant for setters. */
575
  false, /* isAlwaysInSlot.  Only relevant for getters. */
576
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
577
  false,  /* isTypedMethod.  Only relevant for methods. */
578
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
579
};
580
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
581
static_assert(0 < 1, "There is no slot for us");
582
583
MOZ_CAN_RUN_SCRIPT static bool
584
_delete_(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, const JSJitMethodCallArgs& args)
585
0
{
586
0
  AUTO_PROFILER_LABEL_FAST("IDBCursor.delete", DOM, cx);
587
0
588
0
  FastErrorResult rv;
589
0
  auto result(StrongOrRawPtr<mozilla::dom::IDBRequest>(self->Delete(cx, rv)));
590
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
591
0
    return false;
592
0
  }
593
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
594
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
595
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
596
0
    return false;
597
0
  }
598
0
  return true;
599
0
}
600
601
static const JSJitInfo delete_methodinfo = {
602
  { (JSJitGetterOp)_delete_ },
603
  { prototypes::id::IDBCursor },
604
  { PrototypeTraits<prototypes::id::IDBCursor>::Depth },
605
  JSJitInfo::Method,
606
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
607
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
608
  false,  /* isInfallible. False in setters. */
609
  false,  /* isMovable.  Not relevant for setters. */
610
  false, /* isEliminatable.  Not relevant for setters. */
611
  false, /* isAlwaysInSlot.  Only relevant for getters. */
612
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
613
  false,  /* isTypedMethod.  Only relevant for methods. */
614
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
615
};
616
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
617
static_assert(0 < 1, "There is no slot for us");
618
619
static bool
620
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
621
0
{
622
0
  mozilla::dom::IDBCursor* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBCursor>(obj);
623
0
  // We don't want to preserve if we don't have a wrapper, and we
624
0
  // obviously can't preserve if we're not initialized.
625
0
  if (self && self->GetWrapperPreserveColor()) {
626
0
    PreserveWrapper(self);
627
0
  }
628
0
  return true;
629
0
}
630
631
static void
632
_finalize(js::FreeOp* fop, JSObject* obj)
633
0
{
634
0
  mozilla::dom::IDBCursor* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBCursor>(obj);
635
0
  if (self) {
636
0
    ClearWrapper(self, self, obj);
637
0
    AddForDeferredFinalization<mozilla::dom::IDBCursor>(self);
638
0
  }
639
0
}
640
641
static size_t
642
_objectMoved(JSObject* obj, JSObject* old)
643
0
{
644
0
  mozilla::dom::IDBCursor* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBCursor>(obj);
645
0
  if (self) {
646
0
    UpdateWrapper(self, self, obj, old);
647
0
  }
648
0
649
0
  return 0;
650
0
}
651
652
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
653
#if defined(__clang__)
654
#pragma clang diagnostic push
655
#pragma clang diagnostic ignored "-Wmissing-braces"
656
#endif
657
static const JSFunctionSpec sMethods_specs[] = {
658
  JS_FNSPEC("update", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&update_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
659
  JS_FNSPEC("advance", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&advance_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
660
  JS_FNSPEC("continue", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&continue_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
661
  JS_FNSPEC("continuePrimaryKey", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&continuePrimaryKey_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
662
  JS_FNSPEC("delete", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&delete_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
663
  JS_FS_END
664
};
665
#if defined(__clang__)
666
#pragma clang diagnostic pop
667
#endif
668
669
670
static const Prefable<const JSFunctionSpec> sMethods[] = {
671
  { nullptr, &sMethods_specs[0] },
672
  { nullptr, nullptr }
673
};
674
675
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
676
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
677
static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
678
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
679
680
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
681
#if defined(__clang__)
682
#pragma clang diagnostic push
683
#pragma clang diagnostic ignored "-Wmissing-braces"
684
#endif
685
static const JSPropertySpec sAttributes_specs[] = {
686
  { "source", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &source_getterinfo, nullptr, nullptr },
687
  { "direction", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &direction_getterinfo, nullptr, nullptr },
688
  { "key", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &key_getterinfo, nullptr, nullptr },
689
  { "primaryKey", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &primaryKey_getterinfo, nullptr, nullptr },
690
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
691
};
692
#if defined(__clang__)
693
#pragma clang diagnostic pop
694
#endif
695
696
697
static const Prefable<const JSPropertySpec> sAttributes[] = {
698
  { nullptr, &sAttributes_specs[0] },
699
  { nullptr, nullptr }
700
};
701
702
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
703
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
704
static_assert(4 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
705
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
706
707
708
static uint16_t sNativeProperties_sortedPropertyIndices[9];
709
static PropertyInfo sNativeProperties_propertyInfos[9];
710
711
static const NativePropertiesN<2> sNativeProperties = {
712
  false, 0,
713
  false, 0,
714
  true,  0 /* sMethods */,
715
  true,  1 /* sAttributes */,
716
  false, 0,
717
  false, 0,
718
  false, 0,
719
  -1,
720
  9,
721
  sNativeProperties_sortedPropertyIndices,
722
  {
723
    { sMethods, &sNativeProperties_propertyInfos[0] },
724
    { sAttributes, &sNativeProperties_propertyInfos[5] }
725
  }
726
};
727
static_assert(9 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
728
    "We have a property info count that is oversized");
729
730
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
731
  {
732
    "Function",
733
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
734
    &sBoringInterfaceObjectClassClassOps,
735
    JS_NULL_CLASS_SPEC,
736
    JS_NULL_CLASS_EXT,
737
    &sInterfaceObjectClassObjectOps
738
  },
739
  eInterface,
740
  true,
741
  prototypes::id::IDBCursor,
742
  PrototypeTraits<prototypes::id::IDBCursor>::Depth,
743
  sNativePropertyHooks,
744
  "function IDBCursor() {\n    [native code]\n}",
745
  JS::GetRealmFunctionPrototype
746
};
747
748
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
749
  {
750
    "IDBCursorPrototype",
751
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
752
    JS_NULL_CLASS_OPS,
753
    JS_NULL_CLASS_SPEC,
754
    JS_NULL_CLASS_EXT,
755
    JS_NULL_OBJECT_OPS
756
  },
757
  eInterfacePrototype,
758
  false,
759
  prototypes::id::IDBCursor,
760
  PrototypeTraits<prototypes::id::IDBCursor>::Depth,
761
  sNativePropertyHooks,
762
  "[object IDBCursorPrototype]",
763
  JS::GetRealmObjectPrototype
764
};
765
766
static const js::ClassOps sClassOps = {
767
  _addProperty, /* addProperty */
768
  nullptr,               /* delProperty */
769
  nullptr,               /* enumerate */
770
  nullptr, /* newEnumerate */
771
  nullptr, /* resolve */
772
  nullptr, /* mayResolve */
773
  _finalize, /* finalize */
774
  nullptr, /* call */
775
  nullptr,               /* hasInstance */
776
  nullptr,               /* construct */
777
  nullptr, /* trace */
778
};
779
780
static const js::ClassExtension sClassExtension = {
781
  nullptr, /* weakmapKeyDelegateOp */
782
  _objectMoved /* objectMovedOp */
783
};
784
785
static const DOMJSClass sClass = {
786
  { "IDBCursor",
787
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
788
    &sClassOps,
789
    JS_NULL_CLASS_SPEC,
790
    &sClassExtension,
791
    JS_NULL_OBJECT_OPS
792
  },
793
  { prototypes::id::IDBCursor, 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 },
794
  IsBaseOf<nsISupports, mozilla::dom::IDBCursor >::value,
795
  sNativePropertyHooks,
796
  FindAssociatedGlobalForNative<mozilla::dom::IDBCursor>::Get,
797
  GetProtoObjectHandle,
798
  GetCCParticipant<mozilla::dom::IDBCursor>::Get()
799
};
800
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
801
              "Must have the right minimal number of reserved slots.");
802
static_assert(1 >= 1,
803
              "Must have enough reserved slots.");
804
805
const JSClass*
806
GetJSClass()
807
0
{
808
0
  return sClass.ToJSClass();
809
0
}
810
811
bool
812
Wrap(JSContext* aCx, mozilla::dom::IDBCursor* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
813
0
{
814
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::IDBCursor>::value,
815
0
                "Shouldn't have wrappercached things that are not refcounted.");
816
0
  MOZ_ASSERT(static_cast<mozilla::dom::IDBCursor*>(aObject) ==
817
0
             reinterpret_cast<mozilla::dom::IDBCursor*>(aObject),
818
0
             "Multiple inheritance for mozilla::dom::IDBCursor is broken.");
819
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
820
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
821
0
  MOZ_ASSERT(!aCache->GetWrapper(),
822
0
             "You should probably not be using Wrap() directly; use "
823
0
             "GetOrCreateDOMReflector instead");
824
0
825
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
826
0
             "nsISupports must be on our primary inheritance chain");
827
0
828
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
829
0
  if (!global) {
830
0
    return false;
831
0
  }
832
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
833
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
834
0
835
0
  // That might have ended up wrapping us already, due to the wonders
836
0
  // of XBL.  Check for that, and bail out as needed.
837
0
  aReflector.set(aCache->GetWrapper());
838
0
  if (aReflector) {
839
#ifdef DEBUG
840
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
841
#endif // DEBUG
842
    return true;
843
0
  }
844
0
845
0
  JSAutoRealm ar(aCx, global);
846
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
847
0
  if (!canonicalProto) {
848
0
    return false;
849
0
  }
850
0
  JS::Rooted<JSObject*> proto(aCx);
851
0
  if (aGivenProto) {
852
0
    proto = aGivenProto;
853
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
854
0
    // coming in, we changed compartments to that of "parent" so may need
855
0
    // to wrap the proto here.
856
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
857
0
      if (!JS_WrapObject(aCx, &proto)) {
858
0
        return false;
859
0
      }
860
0
    }
861
0
  } else {
862
0
    proto = canonicalProto;
863
0
  }
864
0
865
0
  BindingJSObjectCreator<mozilla::dom::IDBCursor> creator(aCx);
866
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
867
0
  if (!aReflector) {
868
0
    return false;
869
0
  }
870
0
871
0
  aCache->SetWrapper(aReflector);
872
0
  creator.InitializationSucceeded();
873
0
874
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
875
0
             aCache->GetWrapperPreserveColor() == aReflector);
876
0
  // If proto != canonicalProto, we have to preserve our wrapper;
877
0
  // otherwise we won't be able to properly recreate it later, since
878
0
  // we won't know what proto to use.  Note that we don't check
879
0
  // aGivenProto here, since it's entirely possible (and even
880
0
  // somewhat common) to have a non-null aGivenProto which is the
881
0
  // same as canonicalProto.
882
0
  if (proto != canonicalProto) {
883
0
    PreserveWrapper(aObject);
884
0
  }
885
0
886
0
  return true;
887
0
}
888
889
const NativePropertyHooks sNativePropertyHooks[] = { {
890
  nullptr,
891
  nullptr,
892
  nullptr,
893
  { sNativeProperties.Upcast(), nullptr },
894
  prototypes::id::IDBCursor,
895
  constructors::id::IDBCursor,
896
  nullptr,
897
  &DefaultXrayExpandoObjectClass
898
} };
899
900
void
901
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
902
0
{
903
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
904
0
  if (!parentProto) {
905
0
    return;
906
0
  }
907
0
908
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
909
0
  if (!constructorProto) {
910
0
    return;
911
0
  }
912
0
913
0
  static bool sIdsInited = false;
914
0
  if (!sIdsInited && NS_IsMainThread()) {
915
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
916
0
      return;
917
0
    }
918
0
    sIdsInited = true;
919
0
  }
920
0
921
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::IDBCursor);
922
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::IDBCursor);
923
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
924
0
                              &sPrototypeClass.mBase, protoCache,
925
0
                              nullptr,
926
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
927
0
                              interfaceCache,
928
0
                              sNativeProperties.Upcast(),
929
0
                              nullptr,
930
0
                              "IDBCursor", aDefineOnGlobal,
931
0
                              nullptr,
932
0
                              false);
933
0
}
934
935
JSObject*
936
GetProtoObject(JSContext* aCx)
937
0
{
938
0
  return GetProtoObjectHandle(aCx);
939
0
}
940
941
JSObject*
942
GetConstructorObject(JSContext* aCx)
943
0
{
944
0
  return GetConstructorObjectHandle(aCx);
945
0
}
946
947
} // namespace IDBCursor_Binding
948
949
950
951
namespace IDBCursorWithValue_Binding {
952
953
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<IDBCursor_Binding::NativeType>::value,
954
              "Can't inherit from an interface with a different ownership model.");
955
956
MOZ_CAN_RUN_SCRIPT static bool
957
get_value(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::IDBCursor* self, JSJitGetterCallArgs args)
958
0
{
959
0
  AUTO_PROFILER_LABEL_FAST("get IDBCursorWithValue.value", DOM, cx);
960
0
961
0
  FastErrorResult rv;
962
0
  JS::Rooted<JS::Value> result(cx);
963
0
  self->GetValue(cx, &result, rv);
964
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
965
0
    return false;
966
0
  }
967
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
968
0
  JS::ExposeValueToActiveJS(result);
969
0
  args.rval().set(result);
970
0
  if (!MaybeWrapValue(cx, args.rval())) {
971
0
    return false;
972
0
  }
973
0
  return true;
974
0
}
975
976
static const JSJitInfo value_getterinfo = {
977
  { (JSJitGetterOp)get_value },
978
  { prototypes::id::IDBCursorWithValue },
979
  { PrototypeTraits<prototypes::id::IDBCursorWithValue>::Depth },
980
  JSJitInfo::Getter,
981
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
982
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
983
  false,  /* isInfallible. False in setters. */
984
  false,  /* isMovable.  Not relevant for setters. */
985
  false, /* isEliminatable.  Not relevant for setters. */
986
  false, /* isAlwaysInSlot.  Only relevant for getters. */
987
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
988
  false,  /* isTypedMethod.  Only relevant for methods. */
989
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
990
};
991
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
992
static_assert(0 < 1, "There is no slot for us");
993
994
static bool
995
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
996
0
{
997
0
  mozilla::dom::IDBCursor* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBCursor>(obj);
998
0
  // We don't want to preserve if we don't have a wrapper, and we
999
0
  // obviously can't preserve if we're not initialized.
1000
0
  if (self && self->GetWrapperPreserveColor()) {
1001
0
    PreserveWrapper(self);
1002
0
  }
1003
0
  return true;
1004
0
}
1005
1006
static void
1007
_finalize(js::FreeOp* fop, JSObject* obj)
1008
0
{
1009
0
  mozilla::dom::IDBCursor* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBCursor>(obj);
1010
0
  if (self) {
1011
0
    ClearWrapper(self, self, obj);
1012
0
    AddForDeferredFinalization<mozilla::dom::IDBCursor>(self);
1013
0
  }
1014
0
}
1015
1016
static size_t
1017
_objectMoved(JSObject* obj, JSObject* old)
1018
0
{
1019
0
  mozilla::dom::IDBCursor* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::IDBCursor>(obj);
1020
0
  if (self) {
1021
0
    UpdateWrapper(self, self, obj, old);
1022
0
  }
1023
0
1024
0
  return 0;
1025
0
}
1026
1027
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
1028
#if defined(__clang__)
1029
#pragma clang diagnostic push
1030
#pragma clang diagnostic ignored "-Wmissing-braces"
1031
#endif
1032
static const JSPropertySpec sAttributes_specs[] = {
1033
  { "value", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &value_getterinfo, nullptr, nullptr },
1034
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
1035
};
1036
#if defined(__clang__)
1037
#pragma clang diagnostic pop
1038
#endif
1039
1040
1041
static const Prefable<const JSPropertySpec> sAttributes[] = {
1042
  { nullptr, &sAttributes_specs[0] },
1043
  { nullptr, nullptr }
1044
};
1045
1046
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
1047
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
1048
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
1049
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
1050
1051
1052
static uint16_t sNativeProperties_sortedPropertyIndices[1];
1053
static PropertyInfo sNativeProperties_propertyInfos[1];
1054
1055
static const NativePropertiesN<1> sNativeProperties = {
1056
  false, 0,
1057
  false, 0,
1058
  false, 0,
1059
  true,  0 /* sAttributes */,
1060
  false, 0,
1061
  false, 0,
1062
  false, 0,
1063
  -1,
1064
  1,
1065
  sNativeProperties_sortedPropertyIndices,
1066
  {
1067
    { sAttributes, &sNativeProperties_propertyInfos[0] }
1068
  }
1069
};
1070
static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
1071
    "We have a property info count that is oversized");
1072
1073
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
1074
  {
1075
    "Function",
1076
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
1077
    &sBoringInterfaceObjectClassClassOps,
1078
    JS_NULL_CLASS_SPEC,
1079
    JS_NULL_CLASS_EXT,
1080
    &sInterfaceObjectClassObjectOps
1081
  },
1082
  eInterface,
1083
  true,
1084
  prototypes::id::IDBCursorWithValue,
1085
  PrototypeTraits<prototypes::id::IDBCursorWithValue>::Depth,
1086
  sNativePropertyHooks,
1087
  "function IDBCursorWithValue() {\n    [native code]\n}",
1088
  IDBCursor_Binding::GetConstructorObject
1089
};
1090
1091
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
1092
  {
1093
    "IDBCursorWithValuePrototype",
1094
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
1095
    JS_NULL_CLASS_OPS,
1096
    JS_NULL_CLASS_SPEC,
1097
    JS_NULL_CLASS_EXT,
1098
    JS_NULL_OBJECT_OPS
1099
  },
1100
  eInterfacePrototype,
1101
  false,
1102
  prototypes::id::IDBCursorWithValue,
1103
  PrototypeTraits<prototypes::id::IDBCursorWithValue>::Depth,
1104
  sNativePropertyHooks,
1105
  "[object IDBCursorWithValuePrototype]",
1106
  IDBCursor_Binding::GetProtoObject
1107
};
1108
1109
static const js::ClassOps sClassOps = {
1110
  _addProperty, /* addProperty */
1111
  nullptr,               /* delProperty */
1112
  nullptr,               /* enumerate */
1113
  nullptr, /* newEnumerate */
1114
  nullptr, /* resolve */
1115
  nullptr, /* mayResolve */
1116
  _finalize, /* finalize */
1117
  nullptr, /* call */
1118
  nullptr,               /* hasInstance */
1119
  nullptr,               /* construct */
1120
  nullptr, /* trace */
1121
};
1122
1123
static const js::ClassExtension sClassExtension = {
1124
  nullptr, /* weakmapKeyDelegateOp */
1125
  _objectMoved /* objectMovedOp */
1126
};
1127
1128
static const DOMJSClass sClass = {
1129
  { "IDBCursorWithValue",
1130
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1131
    &sClassOps,
1132
    JS_NULL_CLASS_SPEC,
1133
    &sClassExtension,
1134
    JS_NULL_OBJECT_OPS
1135
  },
1136
  { prototypes::id::IDBCursor, prototypes::id::IDBCursorWithValue, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1137
  IsBaseOf<nsISupports, mozilla::dom::IDBCursor >::value,
1138
  sNativePropertyHooks,
1139
  FindAssociatedGlobalForNative<mozilla::dom::IDBCursor>::Get,
1140
  GetProtoObjectHandle,
1141
  GetCCParticipant<mozilla::dom::IDBCursor>::Get()
1142
};
1143
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1144
              "Must have the right minimal number of reserved slots.");
1145
static_assert(1 >= 1,
1146
              "Must have enough reserved slots.");
1147
1148
const JSClass*
1149
GetJSClass()
1150
0
{
1151
0
  return sClass.ToJSClass();
1152
0
}
1153
1154
bool
1155
Wrap(JSContext* aCx, mozilla::dom::IDBCursor* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1156
0
{
1157
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::IDBCursor>::value,
1158
0
                "Shouldn't have wrappercached things that are not refcounted.");
1159
0
  MOZ_ASSERT(static_cast<mozilla::dom::IDBCursor*>(aObject) ==
1160
0
             reinterpret_cast<mozilla::dom::IDBCursor*>(aObject),
1161
0
             "Multiple inheritance for mozilla::dom::IDBCursor is broken.");
1162
0
  MOZ_ASSERT(static_cast<mozilla::dom::IDBCursor*>(aObject) ==
1163
0
             reinterpret_cast<mozilla::dom::IDBCursor*>(aObject),
1164
0
             "Multiple inheritance for mozilla::dom::IDBCursor is broken.");
1165
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1166
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1167
0
  MOZ_ASSERT(!aCache->GetWrapper(),
1168
0
             "You should probably not be using Wrap() directly; use "
1169
0
             "GetOrCreateDOMReflector instead");
1170
0
1171
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1172
0
             "nsISupports must be on our primary inheritance chain");
1173
0
1174
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1175
0
  if (!global) {
1176
0
    return false;
1177
0
  }
1178
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
1179
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
1180
0
1181
0
  // That might have ended up wrapping us already, due to the wonders
1182
0
  // of XBL.  Check for that, and bail out as needed.
1183
0
  aReflector.set(aCache->GetWrapper());
1184
0
  if (aReflector) {
1185
#ifdef DEBUG
1186
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1187
#endif // DEBUG
1188
    return true;
1189
0
  }
1190
0
1191
0
  JSAutoRealm ar(aCx, global);
1192
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1193
0
  if (!canonicalProto) {
1194
0
    return false;
1195
0
  }
1196
0
  JS::Rooted<JSObject*> proto(aCx);
1197
0
  if (aGivenProto) {
1198
0
    proto = aGivenProto;
1199
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
1200
0
    // coming in, we changed compartments to that of "parent" so may need
1201
0
    // to wrap the proto here.
1202
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1203
0
      if (!JS_WrapObject(aCx, &proto)) {
1204
0
        return false;
1205
0
      }
1206
0
    }
1207
0
  } else {
1208
0
    proto = canonicalProto;
1209
0
  }
1210
0
1211
0
  BindingJSObjectCreator<mozilla::dom::IDBCursor> creator(aCx);
1212
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1213
0
  if (!aReflector) {
1214
0
    return false;
1215
0
  }
1216
0
1217
0
  aCache->SetWrapper(aReflector);
1218
0
  creator.InitializationSucceeded();
1219
0
1220
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1221
0
             aCache->GetWrapperPreserveColor() == aReflector);
1222
0
  // If proto != canonicalProto, we have to preserve our wrapper;
1223
0
  // otherwise we won't be able to properly recreate it later, since
1224
0
  // we won't know what proto to use.  Note that we don't check
1225
0
  // aGivenProto here, since it's entirely possible (and even
1226
0
  // somewhat common) to have a non-null aGivenProto which is the
1227
0
  // same as canonicalProto.
1228
0
  if (proto != canonicalProto) {
1229
0
    PreserveWrapper(aObject);
1230
0
  }
1231
0
1232
0
  return true;
1233
0
}
1234
1235
const NativePropertyHooks sNativePropertyHooks[] = { {
1236
  nullptr,
1237
  nullptr,
1238
  nullptr,
1239
  { sNativeProperties.Upcast(), nullptr },
1240
  prototypes::id::IDBCursorWithValue,
1241
  constructors::id::IDBCursorWithValue,
1242
  IDBCursor_Binding::sNativePropertyHooks,
1243
  &DefaultXrayExpandoObjectClass
1244
} };
1245
1246
void
1247
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1248
0
{
1249
0
  JS::Handle<JSObject*> parentProto(IDBCursor_Binding::GetProtoObjectHandle(aCx));
1250
0
  if (!parentProto) {
1251
0
    return;
1252
0
  }
1253
0
1254
0
  JS::Handle<JSObject*> constructorProto(IDBCursor_Binding::GetConstructorObjectHandle(aCx));
1255
0
  if (!constructorProto) {
1256
0
    return;
1257
0
  }
1258
0
1259
0
  static bool sIdsInited = false;
1260
0
  if (!sIdsInited && NS_IsMainThread()) {
1261
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
1262
0
      return;
1263
0
    }
1264
0
    sIdsInited = true;
1265
0
  }
1266
0
1267
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::IDBCursorWithValue);
1268
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::IDBCursorWithValue);
1269
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1270
0
                              &sPrototypeClass.mBase, protoCache,
1271
0
                              nullptr,
1272
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1273
0
                              interfaceCache,
1274
0
                              sNativeProperties.Upcast(),
1275
0
                              nullptr,
1276
0
                              "IDBCursorWithValue", aDefineOnGlobal,
1277
0
                              nullptr,
1278
0
                              false);
1279
0
}
1280
1281
JSObject*
1282
GetConstructorObject(JSContext* aCx)
1283
0
{
1284
0
  return GetConstructorObjectHandle(aCx);
1285
0
}
1286
1287
} // namespace IDBCursorWithValue_Binding
1288
1289
1290
1291
} // namespace dom
1292
} // namespace mozilla