Coverage Report

Created: 2018-09-25 14:53

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