Coverage Report

Created: 2018-09-25 14:53

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