Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/FocusEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM FocusEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "FocusEventBinding.h"
5
#include "UIEventBinding.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/EventTarget.h"
11
#include "mozilla/dom/FocusEvent.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/XrayExpandoClass.h"
17
18
namespace mozilla {
19
namespace dom {
20
21
namespace binding_detail {}; // Just to make sure it's known as a namespace
22
using namespace mozilla::dom::binding_detail;
23
24
25
26
FocusEventInit::FocusEventInit()
27
  : UIEventInit(FastDictionaryInitializer())
28
0
{
29
0
  // Safe to pass a null context if we pass a null value
30
0
  Init(nullptr, JS::NullHandleValue);
31
0
}
32
33
34
35
bool
36
FocusEventInit::InitIds(JSContext* cx, FocusEventInitAtoms* atomsCache)
37
0
{
38
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
39
0
40
0
  // Initialize these in reverse order so that any failure leaves the first one
41
0
  // uninitialized.
42
0
  if (!atomsCache->relatedTarget_id.init(cx, "relatedTarget")) {
43
0
    return false;
44
0
  }
45
0
  return true;
46
0
}
47
48
bool
49
FocusEventInit::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
50
0
{
51
0
  // Passing a null JSContext is OK only if we're initing from null,
52
0
  // Since in that case we will not have to do any property gets
53
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
54
0
  // checkers by static analysis tools
55
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
56
0
  FocusEventInitAtoms* atomsCache = nullptr;
57
0
  if (cx) {
58
0
    atomsCache = GetAtomCache<FocusEventInitAtoms>(cx);
59
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
60
0
      return false;
61
0
    }
62
0
  }
63
0
64
0
  // Per spec, we init the parent's members first
65
0
  if (!UIEventInit::Init(cx, val)) {
66
0
    return false;
67
0
  }
68
0
69
0
  bool isNull = val.isNullOrUndefined();
70
0
  // We only need these if !isNull, in which case we have |cx|.
71
0
  Maybe<JS::Rooted<JSObject *> > object;
72
0
  Maybe<JS::Rooted<JS::Value> > temp;
73
0
  if (!isNull) {
74
0
    MOZ_ASSERT(cx);
75
0
    object.emplace(cx, &val.toObject());
76
0
    temp.emplace(cx);
77
0
  }
78
0
  if (!isNull) {
79
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->relatedTarget_id, temp.ptr())) {
80
0
      return false;
81
0
    }
82
0
  }
83
0
  if (!isNull && !temp->isUndefined()) {
84
0
    if (temp.ref().isObject()) {
85
0
      static_assert(IsRefcounted<mozilla::dom::EventTarget>::value, "We can only store refcounted classes.");{
86
0
        nsresult rv = UnwrapObject<prototypes::id::EventTarget, mozilla::dom::EventTarget>(temp.ptr(), mRelatedTarget);
87
0
        if (NS_FAILED(rv)) {
88
0
          ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "'relatedTarget' member of FocusEventInit", "EventTarget");
89
0
          return false;
90
0
        }
91
0
      }
92
0
    } else if (temp.ref().isNullOrUndefined()) {
93
0
      mRelatedTarget = nullptr;
94
0
    } else {
95
0
      ThrowErrorMessage(cx, MSG_NOT_OBJECT, "'relatedTarget' member of FocusEventInit");
96
0
      return false;
97
0
    }
98
0
  } else {
99
0
    mRelatedTarget = nullptr;
100
0
  }
101
0
  mIsAnyMemberPresent = true;
102
0
  return true;
103
0
}
104
105
bool
106
FocusEventInit::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
107
0
{
108
0
  FocusEventInitAtoms* atomsCache = GetAtomCache<FocusEventInitAtoms>(cx);
109
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
110
0
    return false;
111
0
  }
112
0
113
0
  // Per spec, we define the parent's members first
114
0
  if (!UIEventInit::ToObjectInternal(cx, rval)) {
115
0
    return false;
116
0
  }
117
0
  JS::Rooted<JSObject*> obj(cx, &rval.toObject());
118
0
119
0
  do {
120
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
121
0
    JS::Rooted<JS::Value> temp(cx);
122
0
    RefPtr<mozilla::dom::EventTarget> const & currentValue = mRelatedTarget;
123
0
    if (!currentValue) {
124
0
      temp.setNull();
125
0
      if (!JS_DefinePropertyById(cx, obj, atomsCache->relatedTarget_id, temp, JSPROP_ENUMERATE)) {
126
0
        return false;
127
0
      }
128
0
      break;
129
0
    }
130
0
    if (!GetOrCreateDOMReflector(cx, currentValue, &temp)) {
131
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
132
0
      return false;
133
0
    }
134
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->relatedTarget_id, temp, JSPROP_ENUMERATE)) {
135
0
      return false;
136
0
    }
137
0
    break;
138
0
  } while(false);
139
0
140
0
  return true;
141
0
}
142
143
void
144
FocusEventInit::TraceDictionary(JSTracer* trc)
145
0
{
146
0
  UIEventInit::TraceDictionary(trc);
147
0
}
148
149
150
151
FocusEventInit&
152
FocusEventInit::operator=(const FocusEventInit& aOther)
153
0
{
154
0
  UIEventInit::operator=(aOther);
155
0
  mRelatedTarget = aOther.mRelatedTarget;
156
0
  return *this;
157
0
}
158
159
namespace binding_detail {
160
} // namespace binding_detail
161
162
163
namespace FocusEvent_Binding {
164
165
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<UIEvent_Binding::NativeType>::value,
166
              "Can't inherit from an interface with a different ownership model.");
167
168
MOZ_CAN_RUN_SCRIPT static bool
169
get_relatedTarget(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FocusEvent* self, JSJitGetterCallArgs args)
170
0
{
171
0
  AUTO_PROFILER_LABEL_FAST("get FocusEvent.relatedTarget", DOM, cx);
172
0
173
0
  auto result(StrongOrRawPtr<mozilla::dom::EventTarget>(self->GetRelatedTarget()));
174
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
175
0
  if (!result) {
176
0
    args.rval().setNull();
177
0
    return true;
178
0
  }
179
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
180
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
181
0
    return false;
182
0
  }
183
0
  return true;
184
0
}
185
186
static const JSJitInfo relatedTarget_getterinfo = {
187
  { (JSJitGetterOp)get_relatedTarget },
188
  { prototypes::id::FocusEvent },
189
  { PrototypeTraits<prototypes::id::FocusEvent>::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::FocusEvent* self, JSJitGetterCallArgs args)
206
0
{
207
0
  AUTO_PROFILER_LABEL_FAST("get FocusEvent.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::FocusEvent },
218
  { PrototypeTraits<prototypes::id::FocusEvent>::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::FocusEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FocusEvent>(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::FocusEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FocusEvent>(obj);
249
0
  if (self) {
250
0
    ClearWrapper(self, self, obj);
251
0
    AddForDeferredFinalization<mozilla::dom::FocusEvent>(self);
252
0
  }
253
0
}
254
255
static size_t
256
_objectMoved(JSObject* obj, JSObject* old)
257
0
{
258
0
  mozilla::dom::FocusEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FocusEvent>(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
  { "relatedTarget", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &relatedTarget_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("FocusEvent 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, "FocusEvent");
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, "FocusEvent");
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::FastFocusEventInit arg1;
369
0
  if (!arg1.Init(cx, (args.hasDefined(1)) ? args[1] : JS::NullHandleValue,  "Argument 2 of FocusEvent.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::FocusEvent>(mozilla::dom::FocusEvent::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::FocusEvent,
424
  PrototypeTraits<prototypes::id::FocusEvent>::Depth,
425
  sNativePropertyHooks,
426
  "function FocusEvent() {\n    [native code]\n}",
427
  UIEvent_Binding::GetConstructorObject
428
};
429
430
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
431
  {
432
    "FocusEventPrototype",
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::FocusEvent,
442
  PrototypeTraits<prototypes::id::FocusEvent>::Depth,
443
  sNativePropertyHooks,
444
  "[object FocusEventPrototype]",
445
  UIEvent_Binding::GetProtoObject
446
};
447
448
static const js::ClassOps sClassOps = {
449
  _addProperty, /* addProperty */
450
  nullptr,               /* delProperty */
451
  nullptr,               /* enumerate */
452
  nullptr, /* newEnumerate */
453
  nullptr, /* resolve */
454
  nullptr, /* mayResolve */
455
  _finalize, /* finalize */
456
  nullptr, /* call */
457
  nullptr,               /* hasInstance */
458
  nullptr,               /* construct */
459
  nullptr, /* trace */
460
};
461
462
static const js::ClassExtension sClassExtension = {
463
  nullptr, /* weakmapKeyDelegateOp */
464
  _objectMoved /* objectMovedOp */
465
};
466
467
static const DOMJSClass sClass = {
468
  { "FocusEvent",
469
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
470
    &sClassOps,
471
    JS_NULL_CLASS_SPEC,
472
    &sClassExtension,
473
    JS_NULL_OBJECT_OPS
474
  },
475
  { prototypes::id::Event, prototypes::id::UIEvent, prototypes::id::FocusEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
476
  IsBaseOf<nsISupports, mozilla::dom::FocusEvent >::value,
477
  sNativePropertyHooks,
478
  FindAssociatedGlobalForNative<mozilla::dom::FocusEvent>::Get,
479
  GetProtoObjectHandle,
480
  GetCCParticipant<mozilla::dom::FocusEvent>::Get()
481
};
482
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
483
              "Must have the right minimal number of reserved slots.");
484
static_assert(1 >= 1,
485
              "Must have enough reserved slots.");
486
487
const JSClass*
488
GetJSClass()
489
0
{
490
0
  return sClass.ToJSClass();
491
0
}
492
493
bool
494
Wrap(JSContext* aCx, mozilla::dom::FocusEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
495
0
{
496
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::FocusEvent>::value,
497
0
                "Shouldn't have wrappercached things that are not refcounted.");
498
0
  MOZ_ASSERT(static_cast<mozilla::dom::FocusEvent*>(aObject) ==
499
0
             reinterpret_cast<mozilla::dom::FocusEvent*>(aObject),
500
0
             "Multiple inheritance for mozilla::dom::FocusEvent is broken.");
501
0
  MOZ_ASSERT(static_cast<mozilla::dom::UIEvent*>(aObject) ==
502
0
             reinterpret_cast<mozilla::dom::UIEvent*>(aObject),
503
0
             "Multiple inheritance for mozilla::dom::UIEvent is broken.");
504
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
505
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
506
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
507
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
508
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
509
0
  MOZ_ASSERT(!aCache->GetWrapper(),
510
0
             "You should probably not be using Wrap() directly; use "
511
0
             "GetOrCreateDOMReflector instead");
512
0
513
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
514
0
             "nsISupports must be on our primary inheritance chain");
515
0
516
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
517
0
  if (!global) {
518
0
    return false;
519
0
  }
520
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
521
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
522
0
523
0
  // That might have ended up wrapping us already, due to the wonders
524
0
  // of XBL.  Check for that, and bail out as needed.
525
0
  aReflector.set(aCache->GetWrapper());
526
0
  if (aReflector) {
527
#ifdef DEBUG
528
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
529
#endif // DEBUG
530
    return true;
531
0
  }
532
0
533
0
  JSAutoRealm ar(aCx, global);
534
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
535
0
  if (!canonicalProto) {
536
0
    return false;
537
0
  }
538
0
  JS::Rooted<JSObject*> proto(aCx);
539
0
  if (aGivenProto) {
540
0
    proto = aGivenProto;
541
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
542
0
    // coming in, we changed compartments to that of "parent" so may need
543
0
    // to wrap the proto here.
544
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
545
0
      if (!JS_WrapObject(aCx, &proto)) {
546
0
        return false;
547
0
      }
548
0
    }
549
0
  } else {
550
0
    proto = canonicalProto;
551
0
  }
552
0
553
0
  BindingJSObjectCreator<mozilla::dom::FocusEvent> creator(aCx);
554
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
555
0
  if (!aReflector) {
556
0
    return false;
557
0
  }
558
0
559
0
  aCache->SetWrapper(aReflector);
560
0
561
0
  // Important: do unforgeable property setup after we have handed
562
0
  // over ownership of the C++ object to obj as needed, so that if
563
0
  // we fail and it ends up GCed it won't have problems in the
564
0
  // finalizer trying to drop its ownership of the C++ object.
565
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
566
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
567
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
568
0
    aCache->ReleaseWrapper(aObject);
569
0
    aCache->ClearWrapper();
570
0
    return false;
571
0
  }
572
0
  creator.InitializationSucceeded();
573
0
574
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
575
0
             aCache->GetWrapperPreserveColor() == aReflector);
576
0
  // If proto != canonicalProto, we have to preserve our wrapper;
577
0
  // otherwise we won't be able to properly recreate it later, since
578
0
  // we won't know what proto to use.  Note that we don't check
579
0
  // aGivenProto here, since it's entirely possible (and even
580
0
  // somewhat common) to have a non-null aGivenProto which is the
581
0
  // same as canonicalProto.
582
0
  if (proto != canonicalProto) {
583
0
    PreserveWrapper(aObject);
584
0
  }
585
0
586
0
  return true;
587
0
}
588
589
const NativePropertyHooks sNativePropertyHooks[] = { {
590
  nullptr,
591
  nullptr,
592
  nullptr,
593
  { sNativeProperties.Upcast(), nullptr },
594
  prototypes::id::FocusEvent,
595
  constructors::id::FocusEvent,
596
  UIEvent_Binding::sNativePropertyHooks,
597
  &DefaultXrayExpandoObjectClass
598
} };
599
600
void
601
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
602
0
{
603
0
  JS::Handle<JSObject*> parentProto(UIEvent_Binding::GetProtoObjectHandle(aCx));
604
0
  if (!parentProto) {
605
0
    return;
606
0
  }
607
0
608
0
  JS::Handle<JSObject*> constructorProto(UIEvent_Binding::GetConstructorObjectHandle(aCx));
609
0
  if (!constructorProto) {
610
0
    return;
611
0
  }
612
0
613
0
  static bool sIdsInited = false;
614
0
  if (!sIdsInited && NS_IsMainThread()) {
615
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
616
0
      return;
617
0
    }
618
0
    sIdsInited = true;
619
0
  }
620
0
621
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FocusEvent);
622
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FocusEvent);
623
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
624
0
                              &sPrototypeClass.mBase, protoCache,
625
0
                              nullptr,
626
0
                              constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr,
627
0
                              interfaceCache,
628
0
                              sNativeProperties.Upcast(),
629
0
                              nullptr,
630
0
                              "FocusEvent", aDefineOnGlobal,
631
0
                              nullptr,
632
0
                              false);
633
0
634
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
635
0
  {
636
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
637
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
638
0
    if (!unforgeableHolder) {
639
0
      *protoCache = nullptr;
640
0
      if (interfaceCache) {
641
0
        *interfaceCache = nullptr;
642
0
      }
643
0
      return;
644
0
    }
645
0
  }
646
0
647
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
648
0
    *protoCache = nullptr;
649
0
    if (interfaceCache) {
650
0
      *interfaceCache = nullptr;
651
0
    }
652
0
    return;
653
0
  }
654
0
655
0
  if (*protoCache) {
656
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
657
0
                        JS::ObjectValue(*unforgeableHolder));
658
0
  }
659
0
}
660
661
JSObject*
662
GetConstructorObject(JSContext* aCx)
663
0
{
664
0
  return GetConstructorObjectHandle(aCx);
665
0
}
666
667
} // namespace FocusEvent_Binding
668
669
670
671
} // namespace dom
672
} // namespace mozilla