Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/DataTransferItemBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM DataTransferItem.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "DataTransferItemBinding.h"
4
#include "WrapperFactory.h"
5
#include "mozilla/OwningNonNull.h"
6
#include "mozilla/Preferences.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/DataTransferItem.h"
10
#include "mozilla/dom/File.h"
11
#include "mozilla/dom/FileSystemEntry.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/dom/XrayExpandoClass.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
namespace binding_detail {}; // Just to make sure it's known as a namespace
20
using namespace mozilla::dom::binding_detail;
21
22
23
void
24
FunctionStringCallback::Call(JSContext* cx, JS::Handle<JS::Value> aThisVal, const nsAString& data, ErrorResult& aRv)
25
0
{
26
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
27
0
  JS::AutoValueVector argv(cx);
28
0
  if (!argv.resize(1)) {
29
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
30
0
    return;
31
0
  }
32
0
  unsigned argc = 1;
33
0
34
0
  do {
35
0
    nsString mutableStr(data);
36
0
    if (!xpc::NonVoidStringToJsval(cx, mutableStr, argv[0])) {
37
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
38
0
      return;
39
0
    }
40
0
    break;
41
0
  } while (false);
42
0
43
0
  JS::Rooted<JS::Value> callable(cx, JS::ObjectValue(*mCallback));
44
0
  if (!JS::Call(cx, aThisVal, callable,
45
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
46
0
    aRv.NoteJSContextException(cx);
47
0
    return;
48
0
  }
49
0
}
50
51
52
53
namespace binding_detail {
54
} // namespace binding_detail
55
56
57
namespace DataTransferItem_Binding {
58
59
MOZ_CAN_RUN_SCRIPT static bool
60
get_kind(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DataTransferItem* self, JSJitGetterCallArgs args)
61
0
{
62
0
  AUTO_PROFILER_LABEL_FAST("get DataTransferItem.kind", DOM, cx);
63
0
64
0
  DOMString result;
65
0
  self->GetKind(result);
66
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
67
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
68
0
    return false;
69
0
  }
70
0
  return true;
71
0
}
72
73
static const JSJitInfo kind_getterinfo = {
74
  { (JSJitGetterOp)get_kind },
75
  { prototypes::id::DataTransferItem },
76
  { PrototypeTraits<prototypes::id::DataTransferItem>::Depth },
77
  JSJitInfo::Getter,
78
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
79
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
80
  false,  /* isInfallible. False in setters. */
81
  false,  /* isMovable.  Not relevant for setters. */
82
  false, /* isEliminatable.  Not relevant for setters. */
83
  false, /* isAlwaysInSlot.  Only relevant for getters. */
84
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
85
  false,  /* isTypedMethod.  Only relevant for methods. */
86
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
87
};
88
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
89
static_assert(0 < 1, "There is no slot for us");
90
91
MOZ_CAN_RUN_SCRIPT static bool
92
get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DataTransferItem* self, JSJitGetterCallArgs args)
93
0
{
94
0
  AUTO_PROFILER_LABEL_FAST("get DataTransferItem.type", DOM, cx);
95
0
96
0
  DOMString result;
97
0
  self->GetType(result);
98
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
99
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
100
0
    return false;
101
0
  }
102
0
  return true;
103
0
}
104
105
static const JSJitInfo type_getterinfo = {
106
  { (JSJitGetterOp)get_type },
107
  { prototypes::id::DataTransferItem },
108
  { PrototypeTraits<prototypes::id::DataTransferItem>::Depth },
109
  JSJitInfo::Getter,
110
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
111
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
112
  false,  /* isInfallible. False in setters. */
113
  false,  /* isMovable.  Not relevant for setters. */
114
  false, /* isEliminatable.  Not relevant for setters. */
115
  false, /* isAlwaysInSlot.  Only relevant for getters. */
116
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
117
  false,  /* isTypedMethod.  Only relevant for methods. */
118
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
119
};
120
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
121
static_assert(0 < 1, "There is no slot for us");
122
123
MOZ_CAN_RUN_SCRIPT static bool
124
getAsString(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DataTransferItem* self, const JSJitMethodCallArgs& args)
125
0
{
126
0
  AUTO_PROFILER_LABEL_FAST("DataTransferItem.getAsString", DOM, cx);
127
0
128
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
129
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "DataTransferItem.getAsString");
130
0
  }
131
0
  RootedCallback<RefPtr<binding_detail::FastFunctionStringCallback>> arg0(cx);
132
0
  if (args[0].isObject()) {
133
0
    if (JS::IsCallable(&args[0].toObject())) {
134
0
    { // scope for tempRoot and tempGlobalRoot if needed
135
0
      arg0 = new binding_detail::FastFunctionStringCallback(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
136
0
    }
137
0
    } else {
138
0
      ThrowErrorMessage(cx, MSG_NOT_CALLABLE, "Argument 1 of DataTransferItem.getAsString");
139
0
      return false;
140
0
    }
141
0
  } else if (args[0].isNullOrUndefined()) {
142
0
    arg0 = nullptr;
143
0
  } else {
144
0
    ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of DataTransferItem.getAsString");
145
0
    return false;
146
0
  }
147
0
  FastErrorResult rv;
148
0
  NonNull<nsIPrincipal> subjectPrincipal;
149
0
  {
150
0
    JS::Realm* realm = js::GetContextRealm(cx);
151
0
    MOZ_ASSERT(realm);
152
0
    JSPrincipals* principals = JS::GetRealmPrincipals(realm);
153
0
    nsIPrincipal* principal = nsJSPrincipals::get(principals);
154
0
155
0
    subjectPrincipal = principal;
156
0
  }
157
0
  self->GetAsString(Constify(arg0), subjectPrincipal, rv);
158
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
159
0
    return false;
160
0
  }
161
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
162
0
  args.rval().setUndefined();
163
0
  return true;
164
0
}
165
166
static const JSJitInfo getAsString_methodinfo = {
167
  { (JSJitGetterOp)getAsString },
168
  { prototypes::id::DataTransferItem },
169
  { PrototypeTraits<prototypes::id::DataTransferItem>::Depth },
170
  JSJitInfo::Method,
171
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
172
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
173
  false,  /* isInfallible. False in setters. */
174
  false,  /* isMovable.  Not relevant for setters. */
175
  false, /* isEliminatable.  Not relevant for setters. */
176
  false, /* isAlwaysInSlot.  Only relevant for getters. */
177
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
178
  false,  /* isTypedMethod.  Only relevant for methods. */
179
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
180
};
181
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
182
static_assert(0 < 1, "There is no slot for us");
183
184
MOZ_CAN_RUN_SCRIPT static bool
185
getAsFile(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DataTransferItem* self, const JSJitMethodCallArgs& args)
186
0
{
187
0
  AUTO_PROFILER_LABEL_FAST("DataTransferItem.getAsFile", DOM, cx);
188
0
189
0
  FastErrorResult rv;
190
0
  NonNull<nsIPrincipal> subjectPrincipal;
191
0
  {
192
0
    JS::Realm* realm = js::GetContextRealm(cx);
193
0
    MOZ_ASSERT(realm);
194
0
    JSPrincipals* principals = JS::GetRealmPrincipals(realm);
195
0
    nsIPrincipal* principal = nsJSPrincipals::get(principals);
196
0
197
0
    subjectPrincipal = principal;
198
0
  }
199
0
  auto result(StrongOrRawPtr<mozilla::dom::File>(self->GetAsFile(subjectPrincipal, rv)));
200
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
201
0
    return false;
202
0
  }
203
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
204
0
  if (!result) {
205
0
    args.rval().setNull();
206
0
    return true;
207
0
  }
208
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
209
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
210
0
    return false;
211
0
  }
212
0
  return true;
213
0
}
214
215
static const JSJitInfo getAsFile_methodinfo = {
216
  { (JSJitGetterOp)getAsFile },
217
  { prototypes::id::DataTransferItem },
218
  { PrototypeTraits<prototypes::id::DataTransferItem>::Depth },
219
  JSJitInfo::Method,
220
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
221
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
222
  false,  /* isInfallible. False in setters. */
223
  false,  /* isMovable.  Not relevant for setters. */
224
  false, /* isEliminatable.  Not relevant for setters. */
225
  false, /* isAlwaysInSlot.  Only relevant for getters. */
226
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
227
  false,  /* isTypedMethod.  Only relevant for methods. */
228
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
229
};
230
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
231
static_assert(0 < 1, "There is no slot for us");
232
233
MOZ_CAN_RUN_SCRIPT static bool
234
webkitGetAsEntry(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::DataTransferItem* self, const JSJitMethodCallArgs& args)
235
0
{
236
0
  AUTO_PROFILER_LABEL_FAST("DataTransferItem.webkitGetAsEntry", DOM, cx);
237
0
238
0
  FastErrorResult rv;
239
0
  NonNull<nsIPrincipal> subjectPrincipal;
240
0
  {
241
0
    JS::Realm* realm = js::GetContextRealm(cx);
242
0
    MOZ_ASSERT(realm);
243
0
    JSPrincipals* principals = JS::GetRealmPrincipals(realm);
244
0
    nsIPrincipal* principal = nsJSPrincipals::get(principals);
245
0
246
0
    subjectPrincipal = principal;
247
0
  }
248
0
  auto result(StrongOrRawPtr<mozilla::dom::FileSystemEntry>(self->GetAsEntry(subjectPrincipal, rv)));
249
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
250
0
    return false;
251
0
  }
252
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
253
0
  if (!result) {
254
0
    args.rval().setNull();
255
0
    return true;
256
0
  }
257
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
258
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
259
0
    return false;
260
0
  }
261
0
  return true;
262
0
}
263
264
static const JSJitInfo webkitGetAsEntry_methodinfo = {
265
  { (JSJitGetterOp)webkitGetAsEntry },
266
  { prototypes::id::DataTransferItem },
267
  { PrototypeTraits<prototypes::id::DataTransferItem>::Depth },
268
  JSJitInfo::Method,
269
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
270
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
271
  false,  /* isInfallible. False in setters. */
272
  false,  /* isMovable.  Not relevant for setters. */
273
  false, /* isEliminatable.  Not relevant for setters. */
274
  false, /* isAlwaysInSlot.  Only relevant for getters. */
275
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
276
  false,  /* isTypedMethod.  Only relevant for methods. */
277
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
278
};
279
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
280
static_assert(0 < 1, "There is no slot for us");
281
282
static bool
283
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
284
0
{
285
0
  mozilla::dom::DataTransferItem* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DataTransferItem>(obj);
286
0
  // We don't want to preserve if we don't have a wrapper, and we
287
0
  // obviously can't preserve if we're not initialized.
288
0
  if (self && self->GetWrapperPreserveColor()) {
289
0
    PreserveWrapper(self);
290
0
  }
291
0
  return true;
292
0
}
293
294
static void
295
_finalize(js::FreeOp* fop, JSObject* obj)
296
0
{
297
0
  mozilla::dom::DataTransferItem* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DataTransferItem>(obj);
298
0
  if (self) {
299
0
    ClearWrapper(self, self, obj);
300
0
    AddForDeferredFinalization<mozilla::dom::DataTransferItem>(self);
301
0
  }
302
0
}
303
304
static size_t
305
_objectMoved(JSObject* obj, JSObject* old)
306
0
{
307
0
  mozilla::dom::DataTransferItem* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DataTransferItem>(obj);
308
0
  if (self) {
309
0
    UpdateWrapper(self, self, obj, old);
310
0
  }
311
0
312
0
  return 0;
313
0
}
314
315
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
316
#if defined(__clang__)
317
#pragma clang diagnostic push
318
#pragma clang diagnostic ignored "-Wmissing-braces"
319
#endif
320
static const JSFunctionSpec sMethods_specs[] = {
321
  JS_FNSPEC("getAsString", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getAsString_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
322
  JS_FNSPEC("getAsFile", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&getAsFile_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
323
  JS_FS_END,
324
  JS_FNSPEC("webkitGetAsEntry", (GenericMethod<NormalThisPolicy, ThrowExceptions>), reinterpret_cast<const JSJitInfo*>(&webkitGetAsEntry_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
325
  JS_FS_END
326
};
327
#if defined(__clang__)
328
#pragma clang diagnostic pop
329
#endif
330
331
// Can't be const because the pref-enabled boolean needs to be writable
332
static PrefableDisablers sMethods_disablers3 = {
333
  true, false, 0, nullptr
334
};
335
336
static const Prefable<const JSFunctionSpec> sMethods[] = {
337
  { nullptr, &sMethods_specs[0] },
338
  { &sMethods_disablers3, &sMethods_specs[3] },
339
  { nullptr, nullptr }
340
};
341
342
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
343
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
344
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
345
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
346
347
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
348
#if defined(__clang__)
349
#pragma clang diagnostic push
350
#pragma clang diagnostic ignored "-Wmissing-braces"
351
#endif
352
static const JSPropertySpec sAttributes_specs[] = {
353
  { "kind", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &kind_getterinfo, nullptr, nullptr },
354
  { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr },
355
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
356
};
357
#if defined(__clang__)
358
#pragma clang diagnostic pop
359
#endif
360
361
362
static const Prefable<const JSPropertySpec> sAttributes[] = {
363
  { nullptr, &sAttributes_specs[0] },
364
  { nullptr, nullptr }
365
};
366
367
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
368
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
369
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
370
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
371
372
373
static uint16_t sNativeProperties_sortedPropertyIndices[5];
374
static PropertyInfo sNativeProperties_propertyInfos[5];
375
376
static const NativePropertiesN<2> sNativeProperties = {
377
  false, 0,
378
  false, 0,
379
  true,  0 /* sMethods */,
380
  true,  1 /* sAttributes */,
381
  false, 0,
382
  false, 0,
383
  false, 0,
384
  -1,
385
  5,
386
  sNativeProperties_sortedPropertyIndices,
387
  {
388
    { sMethods, &sNativeProperties_propertyInfos[0] },
389
    { sAttributes, &sNativeProperties_propertyInfos[3] }
390
  }
391
};
392
static_assert(5 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
393
    "We have a property info count that is oversized");
394
395
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
396
  {
397
    "Function",
398
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
399
    &sBoringInterfaceObjectClassClassOps,
400
    JS_NULL_CLASS_SPEC,
401
    JS_NULL_CLASS_EXT,
402
    &sInterfaceObjectClassObjectOps
403
  },
404
  eInterface,
405
  true,
406
  prototypes::id::DataTransferItem,
407
  PrototypeTraits<prototypes::id::DataTransferItem>::Depth,
408
  sNativePropertyHooks,
409
  "function DataTransferItem() {\n    [native code]\n}",
410
  JS::GetRealmFunctionPrototype
411
};
412
413
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
414
  {
415
    "DataTransferItemPrototype",
416
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
417
    JS_NULL_CLASS_OPS,
418
    JS_NULL_CLASS_SPEC,
419
    JS_NULL_CLASS_EXT,
420
    JS_NULL_OBJECT_OPS
421
  },
422
  eInterfacePrototype,
423
  false,
424
  prototypes::id::DataTransferItem,
425
  PrototypeTraits<prototypes::id::DataTransferItem>::Depth,
426
  sNativePropertyHooks,
427
  "[object DataTransferItemPrototype]",
428
  JS::GetRealmObjectPrototype
429
};
430
431
static const js::ClassOps sClassOps = {
432
  _addProperty, /* addProperty */
433
  nullptr,               /* delProperty */
434
  nullptr,               /* enumerate */
435
  nullptr, /* newEnumerate */
436
  nullptr, /* resolve */
437
  nullptr, /* mayResolve */
438
  _finalize, /* finalize */
439
  nullptr, /* call */
440
  nullptr,               /* hasInstance */
441
  nullptr,               /* construct */
442
  nullptr, /* trace */
443
};
444
445
static const js::ClassExtension sClassExtension = {
446
  nullptr, /* weakmapKeyDelegateOp */
447
  _objectMoved /* objectMovedOp */
448
};
449
450
static const DOMJSClass sClass = {
451
  { "DataTransferItem",
452
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
453
    &sClassOps,
454
    JS_NULL_CLASS_SPEC,
455
    &sClassExtension,
456
    JS_NULL_OBJECT_OPS
457
  },
458
  { prototypes::id::DataTransferItem, 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 },
459
  IsBaseOf<nsISupports, mozilla::dom::DataTransferItem >::value,
460
  sNativePropertyHooks,
461
  FindAssociatedGlobalForNative<mozilla::dom::DataTransferItem>::Get,
462
  GetProtoObjectHandle,
463
  GetCCParticipant<mozilla::dom::DataTransferItem>::Get()
464
};
465
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
466
              "Must have the right minimal number of reserved slots.");
467
static_assert(1 >= 1,
468
              "Must have enough reserved slots.");
469
470
const JSClass*
471
GetJSClass()
472
0
{
473
0
  return sClass.ToJSClass();
474
0
}
475
476
bool
477
Wrap(JSContext* aCx, mozilla::dom::DataTransferItem* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
478
0
{
479
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DataTransferItem>::value,
480
0
                "Shouldn't have wrappercached things that are not refcounted.");
481
0
  MOZ_ASSERT(static_cast<mozilla::dom::DataTransferItem*>(aObject) ==
482
0
             reinterpret_cast<mozilla::dom::DataTransferItem*>(aObject),
483
0
             "Multiple inheritance for mozilla::dom::DataTransferItem is broken.");
484
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
485
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
486
0
  MOZ_ASSERT(!aCache->GetWrapper(),
487
0
             "You should probably not be using Wrap() directly; use "
488
0
             "GetOrCreateDOMReflector instead");
489
0
490
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
491
0
             "nsISupports must be on our primary inheritance chain");
492
0
493
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
494
0
  if (!global) {
495
0
    return false;
496
0
  }
497
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
498
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
499
0
500
0
  // That might have ended up wrapping us already, due to the wonders
501
0
  // of XBL.  Check for that, and bail out as needed.
502
0
  aReflector.set(aCache->GetWrapper());
503
0
  if (aReflector) {
504
#ifdef DEBUG
505
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
506
#endif // DEBUG
507
    return true;
508
0
  }
509
0
510
0
  JSAutoRealm ar(aCx, global);
511
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
512
0
  if (!canonicalProto) {
513
0
    return false;
514
0
  }
515
0
  JS::Rooted<JSObject*> proto(aCx);
516
0
  if (aGivenProto) {
517
0
    proto = aGivenProto;
518
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
519
0
    // coming in, we changed compartments to that of "parent" so may need
520
0
    // to wrap the proto here.
521
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
522
0
      if (!JS_WrapObject(aCx, &proto)) {
523
0
        return false;
524
0
      }
525
0
    }
526
0
  } else {
527
0
    proto = canonicalProto;
528
0
  }
529
0
530
0
  BindingJSObjectCreator<mozilla::dom::DataTransferItem> creator(aCx);
531
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
532
0
  if (!aReflector) {
533
0
    return false;
534
0
  }
535
0
536
0
  aCache->SetWrapper(aReflector);
537
0
  creator.InitializationSucceeded();
538
0
539
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
540
0
             aCache->GetWrapperPreserveColor() == aReflector);
541
0
  // If proto != canonicalProto, we have to preserve our wrapper;
542
0
  // otherwise we won't be able to properly recreate it later, since
543
0
  // we won't know what proto to use.  Note that we don't check
544
0
  // aGivenProto here, since it's entirely possible (and even
545
0
  // somewhat common) to have a non-null aGivenProto which is the
546
0
  // same as canonicalProto.
547
0
  if (proto != canonicalProto) {
548
0
    PreserveWrapper(aObject);
549
0
  }
550
0
551
0
  return true;
552
0
}
553
554
const NativePropertyHooks sNativePropertyHooks[] = { {
555
  nullptr,
556
  nullptr,
557
  nullptr,
558
  { sNativeProperties.Upcast(), nullptr },
559
  prototypes::id::DataTransferItem,
560
  constructors::id::DataTransferItem,
561
  nullptr,
562
  &DefaultXrayExpandoObjectClass
563
} };
564
565
void
566
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
567
0
{
568
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
569
0
  if (!parentProto) {
570
0
    return;
571
0
  }
572
0
573
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
574
0
  if (!constructorProto) {
575
0
    return;
576
0
  }
577
0
578
0
  static bool sIdsInited = false;
579
0
  if (!sIdsInited && NS_IsMainThread()) {
580
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
581
0
      return;
582
0
    }
583
0
    sIdsInited = true;
584
0
  }
585
0
586
0
  static bool sPrefCachesInited = false;
587
0
  if (!sPrefCachesInited && NS_IsMainThread()) {
588
0
    sPrefCachesInited = true;
589
0
    Preferences::AddBoolVarCache(&sMethods[1].disablers->enabled, "dom.webkitBlink.filesystem.enabled");
590
0
  }
591
0
592
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DataTransferItem);
593
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DataTransferItem);
594
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
595
0
                              &sPrototypeClass.mBase, protoCache,
596
0
                              nullptr,
597
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
598
0
                              interfaceCache,
599
0
                              sNativeProperties.Upcast(),
600
0
                              nullptr,
601
0
                              "DataTransferItem", aDefineOnGlobal,
602
0
                              nullptr,
603
0
                              false);
604
0
}
605
606
JSObject*
607
GetConstructorObject(JSContext* aCx)
608
0
{
609
0
  return GetConstructorObjectHandle(aCx);
610
0
}
611
612
} // namespace DataTransferItem_Binding
613
614
615
616
} // namespace dom
617
} // namespace mozilla