Coverage Report

Created: 2018-09-25 14:53

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