Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/ClipboardEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM ClipboardEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "ClipboardEventBinding.h"
5
#include "EventBinding.h"
6
#include "WrapperFactory.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/dom/BindingUtils.h"
9
#include "mozilla/dom/ClipboardEvent.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/DataTransfer.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/SimpleGlobalObject.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
27
ClipboardEventInit::ClipboardEventInit()
28
  : EventInit(FastDictionaryInitializer())
29
0
{
30
0
  // Safe to pass a null context if we pass a null value
31
0
  Init(nullptr, JS::NullHandleValue);
32
0
}
33
34
35
36
bool
37
ClipboardEventInit::InitIds(JSContext* cx, ClipboardEventInitAtoms* atomsCache)
38
0
{
39
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
40
0
41
0
  // Initialize these in reverse order so that any failure leaves the first one
42
0
  // uninitialized.
43
0
  if (!atomsCache->dataType_id.init(cx, "dataType") ||
44
0
      !atomsCache->data_id.init(cx, "data")) {
45
0
    return false;
46
0
  }
47
0
  return true;
48
0
}
49
50
bool
51
ClipboardEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
52
0
{
53
0
  // Passing a null JSContext is OK only if we're initing from null,
54
0
  // Since in that case we will not have to do any property gets
55
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
56
0
  // checkers by static analysis tools
57
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
58
0
  ClipboardEventInitAtoms* atomsCache = nullptr;
59
0
  if (cx) {
60
0
    atomsCache = GetAtomCache<ClipboardEventInitAtoms>(cx);
61
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
62
0
      return false;
63
0
    }
64
0
  }
65
0
66
0
  // Per spec, we init the parent's members first
67
0
  if (!EventInit::Init(cx, val)) {
68
0
    return false;
69
0
  }
70
0
71
0
  bool isNull = val.isNullOrUndefined();
72
0
  // We only need these if !isNull, in which case we have |cx|.
73
0
  Maybe<JS::Rooted<JSObject *> > object;
74
0
  Maybe<JS::Rooted<JS::Value> > temp;
75
0
  if (!isNull) {
76
0
    MOZ_ASSERT(cx);
77
0
    object.emplace(cx, &val.toObject());
78
0
    temp.emplace(cx);
79
0
  }
80
0
  if (!isNull) {
81
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->data_id, temp.ptr())) {
82
0
      return false;
83
0
    }
84
0
  }
85
0
  if (!isNull && !temp->isUndefined()) {
86
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mData)) {
87
0
      return false;
88
0
    }
89
0
  } else {
90
0
    static const char16_t data[] = { 0 };
91
0
    mData.Rebind(data, ArrayLength(data) - 1);
92
0
  }
93
0
  mIsAnyMemberPresent = true;
94
0
95
0
  if (!isNull) {
96
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->dataType_id, temp.ptr())) {
97
0
      return false;
98
0
    }
99
0
  }
100
0
  if (!isNull && !temp->isUndefined()) {
101
0
    if (!ConvertJSValueToString(cx, temp.ref(), eStringify, eStringify, mDataType)) {
102
0
      return false;
103
0
    }
104
0
  } else {
105
0
    static const char16_t data[] = { 0 };
106
0
    mDataType.Rebind(data, ArrayLength(data) - 1);
107
0
  }
108
0
  mIsAnyMemberPresent = true;
109
0
  return true;
110
0
}
111
112
bool
113
ClipboardEventInit::Init(const nsAString& aJSON)
114
0
{
115
0
  AutoJSAPI jsapi;
116
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
117
0
  if (!cleanGlobal) {
118
0
    return false;
119
0
  }
120
0
  if (!jsapi.Init(cleanGlobal)) {
121
0
    return false;
122
0
  }
123
0
  JSContext* cx = jsapi.cx();
124
0
  JS::Rooted<JS::Value> json(cx);
125
0
  bool ok = ParseJSON(cx, aJSON, &json);
126
0
  NS_ENSURE_TRUE(ok, false);
127
0
  return Init(cx, json);
128
0
}
129
130
bool
131
ClipboardEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
132
0
{
133
0
  ClipboardEventInitAtoms* atomsCache = GetAtomCache<ClipboardEventInitAtoms>(cx);
134
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
135
0
    return false;
136
0
  }
137
0
138
0
  // Per spec, we define the parent's members first
139
0
  if (!EventInit::ToObjectInternal(cx, rval)) {
140
0
    return false;
141
0
  }
142
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
143
0
144
0
  do {
145
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
146
0
    JS::Rooted<JS::Value> temp(cx);
147
0
    nsString const & currentValue = mData;
148
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
149
0
      return false;
150
0
    }
151
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->data_id, temp, JSPROP_ENUMERATE)) {
152
0
      return false;
153
0
    }
154
0
    break;
155
0
  } while(false);
156
0
157
0
  do {
158
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
159
0
    JS::Rooted<JS::Value> temp(cx);
160
0
    nsString const & currentValue = mDataType;
161
0
    if (!xpc::NonVoidStringToJsval(cx, currentValue, &temp)) {
162
0
      return false;
163
0
    }
164
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->dataType_id, temp, JSPROP_ENUMERATE)) {
165
0
      return false;
166
0
    }
167
0
    break;
168
0
  } while(false);
169
0
170
0
  return true;
171
0
}
172
173
bool
174
ClipboardEventInit::ToJSON(nsAString& aJSON) const
175
0
{
176
0
  AutoJSAPI jsapi;
177
0
  jsapi.Init();
178
0
  JSContext *cx = jsapi.cx();
179
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
180
0
  // because we'll only be creating objects, in ways that have no
181
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
182
0
  // which likewise guarantees no side-effects for the sorts of
183
0
  // things we will pass it.
184
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
185
0
  JS::Rooted<JS::Value> val(cx);
186
0
  if (!ToObjectInternal(cx, &val)) {
187
0
    return false;
188
0
  }
189
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
190
0
  return StringifyToJSON(cx, obj, aJSON);
191
0
}
192
193
void
194
ClipboardEventInit::TraceDictionary(JSTracer* trc)
195
0
{
196
0
  EventInit::TraceDictionary(trc);
197
0
}
198
199
ClipboardEventInit&
200
ClipboardEventInit::operator=(const ClipboardEventInit& aOther)
201
0
{
202
0
  EventInit::operator=(aOther);
203
0
  mData = aOther.mData;
204
0
  mDataType = aOther.mDataType;
205
0
  return *this;
206
0
}
207
208
namespace binding_detail {
209
} // namespace binding_detail
210
211
212
namespace ClipboardEvent_Binding {
213
214
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value,
215
              "Can't inherit from an interface with a different ownership model.");
216
217
MOZ_CAN_RUN_SCRIPT static bool
218
get_clipboardData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ClipboardEvent* self, JSJitGetterCallArgs args)
219
0
{
220
0
  AUTO_PROFILER_LABEL_FAST("get ClipboardEvent.clipboardData", DOM, cx);
221
0
222
0
  auto result(StrongOrRawPtr<mozilla::dom::DataTransfer>(self->GetClipboardData()));
223
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
224
0
  if (!result) {
225
0
    args.rval().setNull();
226
0
    return true;
227
0
  }
228
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
229
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
230
0
    return false;
231
0
  }
232
0
  return true;
233
0
}
234
235
static const JSJitInfo clipboardData_getterinfo = {
236
  { (JSJitGetterOp)get_clipboardData },
237
  { prototypes::id::ClipboardEvent },
238
  { PrototypeTraits<prototypes::id::ClipboardEvent>::Depth },
239
  JSJitInfo::Getter,
240
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
241
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
242
  false,  /* isInfallible. False in setters. */
243
  false,  /* isMovable.  Not relevant for setters. */
244
  false, /* isEliminatable.  Not relevant for setters. */
245
  false, /* isAlwaysInSlot.  Only relevant for getters. */
246
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
247
  false,  /* isTypedMethod.  Only relevant for methods. */
248
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
249
};
250
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
251
static_assert(0 < 1, "There is no slot for us");
252
253
MOZ_CAN_RUN_SCRIPT static bool
254
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::ClipboardEvent* self, JSJitGetterCallArgs args)
255
0
{
256
0
  AUTO_PROFILER_LABEL_FAST("get ClipboardEvent.isTrusted", DOM, cx);
257
0
258
0
  bool result(self->IsTrusted());
259
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
260
0
  args.rval().setBoolean(result);
261
0
  return true;
262
0
}
263
264
static const JSJitInfo isTrusted_getterinfo = {
265
  { (JSJitGetterOp)get_isTrusted },
266
  { prototypes::id::ClipboardEvent },
267
  { PrototypeTraits<prototypes::id::ClipboardEvent>::Depth },
268
  JSJitInfo::Getter,
269
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
270
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
271
  true,  /* isInfallible. False in setters. */
272
  true,  /* isMovable.  Not relevant for setters. */
273
  true, /* 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::ClipboardEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ClipboardEvent>(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::ClipboardEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ClipboardEvent>(obj);
298
0
  if (self) {
299
0
    ClearWrapper(self, self, obj);
300
0
    AddForDeferredFinalization<mozilla::dom::ClipboardEvent>(self);
301
0
  }
302
0
}
303
304
static size_t
305
_objectMoved(JSObject* obj, JSObject* old)
306
0
{
307
0
  mozilla::dom::ClipboardEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::ClipboardEvent>(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 JSPropertySpec sAttributes_specs[] = {
321
  { "clipboardData", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &clipboardData_getterinfo, nullptr, nullptr },
322
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
323
};
324
#if defined(__clang__)
325
#pragma clang diagnostic pop
326
#endif
327
328
329
static const Prefable<const JSPropertySpec> sAttributes[] = {
330
  { nullptr, &sAttributes_specs[0] },
331
  { nullptr, nullptr }
332
};
333
334
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
335
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
336
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
337
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
338
339
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
340
#if defined(__clang__)
341
#pragma clang diagnostic push
342
#pragma clang diagnostic ignored "-Wmissing-braces"
343
#endif
344
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
345
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
346
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
347
};
348
#if defined(__clang__)
349
#pragma clang diagnostic pop
350
#endif
351
352
353
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
354
  { nullptr, &sUnforgeableAttributes_specs[0] },
355
  { nullptr, nullptr }
356
};
357
358
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
359
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
360
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
361
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
362
363
364
static uint16_t sNativeProperties_sortedPropertyIndices[2];
365
static PropertyInfo sNativeProperties_propertyInfos[2];
366
367
static const NativePropertiesN<2> sNativeProperties = {
368
  false, 0,
369
  false, 0,
370
  false, 0,
371
  true,  0 /* sAttributes */,
372
  false, 0,
373
  true,  1 /* sUnforgeableAttributes */,
374
  false, 0,
375
  -1,
376
  2,
377
  sNativeProperties_sortedPropertyIndices,
378
  {
379
    { sAttributes, &sNativeProperties_propertyInfos[0] },
380
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
381
  }
382
};
383
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
384
    "We have a property info count that is oversized");
385
386
static bool
387
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
388
0
{
389
0
  AUTO_PROFILER_LABEL_FAST("ClipboardEvent constructor", DOM, cx);
390
0
391
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
392
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
393
0
  if (!args.isConstructing()) {
394
0
    // XXXbz wish I could get the name from the callee instead of
395
0
    // Adding more relocations
396
0
    return ThrowConstructorWithoutNew(cx, "ClipboardEvent");
397
0
  }
398
0
399
0
  JS::Rooted<JSObject*> desiredProto(cx);
400
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
401
0
    return false;
402
0
  }
403
0
404
0
  if (MOZ_UNLIKELY(args.length() < 1)) {
405
0
    return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "ClipboardEvent");
406
0
  }
407
0
  GlobalObject global(cx, obj);
408
0
  if (global.Failed()) {
409
0
    return false;
410
0
  }
411
0
412
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
413
0
  binding_detail::FakeString arg0;
414
0
  if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
415
0
    return false;
416
0
  }
417
0
  binding_detail::FastClipboardEventInit arg1;
418
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of ClipboardEvent.constructor", false)) {
419
0
    return false;
420
0
  }
421
0
  Maybe<JSAutoRealm> ar;
422
0
  if (objIsXray) {
423
0
    obj = js::CheckedUnwrap(obj);
424
0
    if (!obj) {
425
0
      return false;
426
0
    }
427
0
    ar.emplace(cx, obj);
428
0
    if (!JS_WrapObject(cx, &desiredProto)) {
429
0
      return false;
430
0
    }
431
0
  }
432
0
  FastErrorResult rv;
433
0
  auto result(StrongOrRawPtr<mozilla::dom::ClipboardEvent>(mozilla::dom::ClipboardEvent::Constructor(global, NonNullHelper(Constify(arg0)), Constify(arg1), rv)));
434
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
435
0
    return false;
436
0
  }
437
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
438
0
  static_assert(!IsPointer<decltype(result)>::value,
439
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
440
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
441
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
442
0
    return false;
443
0
  }
444
0
  return true;
445
0
}
446
447
static const js::ClassOps sInterfaceObjectClassOps = {
448
    nullptr,               /* addProperty */
449
    nullptr,               /* delProperty */
450
    nullptr,               /* enumerate */
451
    nullptr,               /* newEnumerate */
452
    nullptr,               /* resolve */
453
    nullptr,               /* mayResolve */
454
    nullptr,               /* finalize */
455
    _constructor, /* call */
456
    nullptr,               /* hasInstance */
457
    _constructor, /* construct */
458
    nullptr,               /* trace */
459
};
460
461
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
462
  {
463
    "Function",
464
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
465
    &sInterfaceObjectClassOps,
466
    JS_NULL_CLASS_SPEC,
467
    JS_NULL_CLASS_EXT,
468
    &sInterfaceObjectClassObjectOps
469
  },
470
  eInterface,
471
  true,
472
  prototypes::id::ClipboardEvent,
473
  PrototypeTraits<prototypes::id::ClipboardEvent>::Depth,
474
  sNativePropertyHooks,
475
  "function ClipboardEvent() {\n    [native code]\n}",
476
  Event_Binding::GetConstructorObject
477
};
478
479
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
480
  {
481
    "ClipboardEventPrototype",
482
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
483
    JS_NULL_CLASS_OPS,
484
    JS_NULL_CLASS_SPEC,
485
    JS_NULL_CLASS_EXT,
486
    JS_NULL_OBJECT_OPS
487
  },
488
  eInterfacePrototype,
489
  false,
490
  prototypes::id::ClipboardEvent,
491
  PrototypeTraits<prototypes::id::ClipboardEvent>::Depth,
492
  sNativePropertyHooks,
493
  "[object ClipboardEventPrototype]",
494
  Event_Binding::GetProtoObject
495
};
496
497
static const js::ClassOps sClassOps = {
498
  _addProperty, /* addProperty */
499
  nullptr,               /* delProperty */
500
  nullptr,               /* enumerate */
501
  nullptr, /* newEnumerate */
502
  nullptr, /* resolve */
503
  nullptr, /* mayResolve */
504
  _finalize, /* finalize */
505
  nullptr, /* call */
506
  nullptr,               /* hasInstance */
507
  nullptr,               /* construct */
508
  nullptr, /* trace */
509
};
510
511
static const js::ClassExtension sClassExtension = {
512
  nullptr, /* weakmapKeyDelegateOp */
513
  _objectMoved /* objectMovedOp */
514
};
515
516
static const DOMJSClass sClass = {
517
  { "ClipboardEvent",
518
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
519
    &sClassOps,
520
    JS_NULL_CLASS_SPEC,
521
    &sClassExtension,
522
    JS_NULL_OBJECT_OPS
523
  },
524
  { prototypes::id::Event, prototypes::id::ClipboardEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
525
  IsBaseOf<nsISupports, mozilla::dom::ClipboardEvent >::value,
526
  sNativePropertyHooks,
527
  FindAssociatedGlobalForNative<mozilla::dom::ClipboardEvent>::Get,
528
  GetProtoObjectHandle,
529
  GetCCParticipant<mozilla::dom::ClipboardEvent>::Get()
530
};
531
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
532
              "Must have the right minimal number of reserved slots.");
533
static_assert(1 >= 1,
534
              "Must have enough reserved slots.");
535
536
const JSClass*
537
GetJSClass()
538
0
{
539
0
  return sClass.ToJSClass();
540
0
}
541
542
bool
543
Wrap(JSContext* aCx, mozilla::dom::ClipboardEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
544
0
{
545
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::ClipboardEvent>::value,
546
0
                "Shouldn't have wrappercached things that are not refcounted.");
547
0
  MOZ_ASSERT(static_cast<mozilla::dom::ClipboardEvent*>(aObject) ==
548
0
             reinterpret_cast<mozilla::dom::ClipboardEvent*>(aObject),
549
0
             "Multiple inheritance for mozilla::dom::ClipboardEvent is broken.");
550
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
551
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
552
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
553
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
554
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
555
0
  MOZ_ASSERT(!aCache->GetWrapper(),
556
0
             "You should probably not be using Wrap() directly; use "
557
0
             "GetOrCreateDOMReflector instead");
558
0
559
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
560
0
             "nsISupports must be on our primary inheritance chain");
561
0
562
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
563
0
  if (!global) {
564
0
    return false;
565
0
  }
566
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
567
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
568
0
569
0
  // That might have ended up wrapping us already, due to the wonders
570
0
  // of XBL.  Check for that, and bail out as needed.
571
0
  aReflector.set(aCache->GetWrapper());
572
0
  if (aReflector) {
573
#ifdef DEBUG
574
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
575
#endif // DEBUG
576
    return true;
577
0
  }
578
0
579
0
  JSAutoRealm ar(aCx, global);
580
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
581
0
  if (!canonicalProto) {
582
0
    return false;
583
0
  }
584
0
  JS::Rooted<JSObject*> proto(aCx);
585
0
  if (aGivenProto) {
586
0
    proto = aGivenProto;
587
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
588
0
    // coming in, we changed compartments to that of "parent" so may need
589
0
    // to wrap the proto here.
590
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
591
0
      if (!JS_WrapObject(aCx, &proto)) {
592
0
        return false;
593
0
      }
594
0
    }
595
0
  } else {
596
0
    proto = canonicalProto;
597
0
  }
598
0
599
0
  BindingJSObjectCreator<mozilla::dom::ClipboardEvent> creator(aCx);
600
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
601
0
  if (!aReflector) {
602
0
    return false;
603
0
  }
604
0
605
0
  aCache->SetWrapper(aReflector);
606
0
607
0
  // Important: do unforgeable property setup after we have handed
608
0
  // over ownership of the C++ object to obj as needed, so that if
609
0
  // we fail and it ends up GCed it won't have problems in the
610
0
  // finalizer trying to drop its ownership of the C++ object.
611
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
612
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
613
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
614
0
    aCache->ReleaseWrapper(aObject);
615
0
    aCache->ClearWrapper();
616
0
    return false;
617
0
  }
618
0
  creator.InitializationSucceeded();
619
0
620
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
621
0
             aCache->GetWrapperPreserveColor() == aReflector);
622
0
  // If proto != canonicalProto, we have to preserve our wrapper;
623
0
  // otherwise we won't be able to properly recreate it later, since
624
0
  // we won't know what proto to use.  Note that we don't check
625
0
  // aGivenProto here, since it's entirely possible (and even
626
0
  // somewhat common) to have a non-null aGivenProto which is the
627
0
  // same as canonicalProto.
628
0
  if (proto != canonicalProto) {
629
0
    PreserveWrapper(aObject);
630
0
  }
631
0
632
0
  return true;
633
0
}
634
635
const NativePropertyHooks sNativePropertyHooks[] = { {
636
  nullptr,
637
  nullptr,
638
  nullptr,
639
  { sNativeProperties.Upcast(), nullptr },
640
  prototypes::id::ClipboardEvent,
641
  constructors::id::ClipboardEvent,
642
  Event_Binding::sNativePropertyHooks,
643
  &DefaultXrayExpandoObjectClass
644
} };
645
646
void
647
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
648
0
{
649
0
  JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx));
650
0
  if (!parentProto) {
651
0
    return;
652
0
  }
653
0
654
0
  JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx));
655
0
  if (!constructorProto) {
656
0
    return;
657
0
  }
658
0
659
0
  static bool sIdsInited = false;
660
0
  if (!sIdsInited && NS_IsMainThread()) {
661
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
662
0
      return;
663
0
    }
664
0
    sIdsInited = true;
665
0
  }
666
0
667
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::ClipboardEvent);
668
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::ClipboardEvent);
669
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
670
0
                              &sPrototypeClass.mBase, protoCache,
671
0
                              nullptr,
672
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
673
0
                              interfaceCache,
674
0
                              sNativeProperties.Upcast(),
675
0
                              nullptr,
676
0
                              "ClipboardEvent", aDefineOnGlobal,
677
0
                              nullptr,
678
0
                              false);
679
0
680
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
681
0
  {
682
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
683
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
684
0
    if (!unforgeableHolder) {
685
0
      *protoCache = nullptr;
686
0
      if (interfaceCache) {
687
0
        *interfaceCache = nullptr;
688
0
      }
689
0
      return;
690
0
    }
691
0
  }
692
0
693
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
694
0
    *protoCache = nullptr;
695
0
    if (interfaceCache) {
696
0
      *interfaceCache = nullptr;
697
0
    }
698
0
    return;
699
0
  }
700
0
701
0
  if (*protoCache) {
702
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
703
0
                        JS::ObjectValue(*unforgeableHolder));
704
0
  }
705
0
}
706
707
JSObject*
708
GetConstructorObject(JSContext* aCx)
709
0
{
710
0
  return GetConstructorObjectHandle(aCx);
711
0
}
712
713
} // namespace ClipboardEvent_Binding
714
715
716
717
} // namespace dom
718
} // namespace mozilla