Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/CommandEventBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM CommandEvent.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "CommandEventBinding.h"
4
#include "EventBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/CommandEvent.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/NonRefcountedDOMObject.h"
11
#include "mozilla/dom/Nullable.h"
12
#include "mozilla/dom/PrimitiveConversions.h"
13
#include "mozilla/dom/XrayExpandoClass.h"
14
15
namespace mozilla {
16
namespace dom {
17
18
namespace binding_detail {}; // Just to make sure it's known as a namespace
19
using namespace mozilla::dom::binding_detail;
20
21
22
namespace CommandEvent_Binding {
23
24
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<Event_Binding::NativeType>::value,
25
              "Can't inherit from an interface with a different ownership model.");
26
27
MOZ_CAN_RUN_SCRIPT static bool
28
get_command(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CommandEvent* self, JSJitGetterCallArgs args)
29
0
{
30
0
  AUTO_PROFILER_LABEL_FAST("get CommandEvent.command", DOM, cx);
31
0
32
0
  DOMString result;
33
0
  self->GetCommand(result);
34
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
35
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
36
0
    return false;
37
0
  }
38
0
  return true;
39
0
}
40
41
static const JSJitInfo command_getterinfo = {
42
  { (JSJitGetterOp)get_command },
43
  { prototypes::id::CommandEvent },
44
  { PrototypeTraits<prototypes::id::CommandEvent>::Depth },
45
  JSJitInfo::Getter,
46
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
47
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
48
  false,  /* isInfallible. False in setters. */
49
  false,  /* isMovable.  Not relevant for setters. */
50
  false, /* isEliminatable.  Not relevant for setters. */
51
  false, /* isAlwaysInSlot.  Only relevant for getters. */
52
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
53
  false,  /* isTypedMethod.  Only relevant for methods. */
54
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
55
};
56
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
57
static_assert(0 < 1, "There is no slot for us");
58
59
MOZ_CAN_RUN_SCRIPT static bool
60
get_isTrusted(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::CommandEvent* self, JSJitGetterCallArgs args)
61
0
{
62
0
  AUTO_PROFILER_LABEL_FAST("get CommandEvent.isTrusted", DOM, cx);
63
0
64
0
  bool result(self->IsTrusted());
65
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
66
0
  args.rval().setBoolean(result);
67
0
  return true;
68
0
}
69
70
static const JSJitInfo isTrusted_getterinfo = {
71
  { (JSJitGetterOp)get_isTrusted },
72
  { prototypes::id::CommandEvent },
73
  { PrototypeTraits<prototypes::id::CommandEvent>::Depth },
74
  JSJitInfo::Getter,
75
  JSJitInfo::AliasDOMSets, /* aliasSet.  Not relevant for setters. */
76
  JSVAL_TYPE_BOOLEAN,  /* returnType.  Not relevant for setters. */
77
  true,  /* isInfallible. False in setters. */
78
  true,  /* isMovable.  Not relevant for setters. */
79
  true, /* isEliminatable.  Not relevant for setters. */
80
  false, /* isAlwaysInSlot.  Only relevant for getters. */
81
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
82
  false,  /* isTypedMethod.  Only relevant for methods. */
83
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
84
};
85
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
86
static_assert(0 < 1, "There is no slot for us");
87
88
static bool
89
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
90
0
{
91
0
  mozilla::dom::CommandEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CommandEvent>(obj);
92
0
  // We don't want to preserve if we don't have a wrapper, and we
93
0
  // obviously can't preserve if we're not initialized.
94
0
  if (self && self->GetWrapperPreserveColor()) {
95
0
    PreserveWrapper(self);
96
0
  }
97
0
  return true;
98
0
}
99
100
static void
101
_finalize(js::FreeOp* fop, JSObject* obj)
102
0
{
103
0
  mozilla::dom::CommandEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CommandEvent>(obj);
104
0
  if (self) {
105
0
    ClearWrapper(self, self, obj);
106
0
    AddForDeferredFinalization<mozilla::dom::CommandEvent>(self);
107
0
  }
108
0
}
109
110
static size_t
111
_objectMoved(JSObject* obj, JSObject* old)
112
0
{
113
0
  mozilla::dom::CommandEvent* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::CommandEvent>(obj);
114
0
  if (self) {
115
0
    UpdateWrapper(self, self, obj, old);
116
0
  }
117
0
118
0
  return 0;
119
0
}
120
121
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
122
#if defined(__clang__)
123
#pragma clang diagnostic push
124
#pragma clang diagnostic ignored "-Wmissing-braces"
125
#endif
126
static const JSPropertySpec sAttributes_specs[] = {
127
  { "command", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &command_getterinfo, nullptr, nullptr },
128
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
129
};
130
#if defined(__clang__)
131
#pragma clang diagnostic pop
132
#endif
133
134
135
static const Prefable<const JSPropertySpec> sAttributes[] = {
136
  { nullptr, &sAttributes_specs[0] },
137
  { nullptr, nullptr }
138
};
139
140
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
141
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
142
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
143
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
144
145
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
146
#if defined(__clang__)
147
#pragma clang diagnostic push
148
#pragma clang diagnostic ignored "-Wmissing-braces"
149
#endif
150
static const JSPropertySpec sUnforgeableAttributes_specs[] = {
151
  { "isTrusted", JSPROP_ENUMERATE | JSPROP_PERMANENT, GenericGetter<NormalThisPolicy, ThrowExceptions>, &isTrusted_getterinfo, nullptr, nullptr },
152
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
153
};
154
#if defined(__clang__)
155
#pragma clang diagnostic pop
156
#endif
157
158
159
static const Prefable<const JSPropertySpec> sUnforgeableAttributes[] = {
160
  { nullptr, &sUnforgeableAttributes_specs[0] },
161
  { nullptr, nullptr }
162
};
163
164
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
165
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
166
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
167
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
168
169
170
static uint16_t sNativeProperties_sortedPropertyIndices[2];
171
static PropertyInfo sNativeProperties_propertyInfos[2];
172
173
static const NativePropertiesN<2> sNativeProperties = {
174
  false, 0,
175
  false, 0,
176
  false, 0,
177
  true,  0 /* sAttributes */,
178
  false, 0,
179
  true,  1 /* sUnforgeableAttributes */,
180
  false, 0,
181
  -1,
182
  2,
183
  sNativeProperties_sortedPropertyIndices,
184
  {
185
    { sAttributes, &sNativeProperties_propertyInfos[0] },
186
    { sUnforgeableAttributes, &sNativeProperties_propertyInfos[1] }
187
  }
188
};
189
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
190
    "We have a property info count that is oversized");
191
192
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
193
  {
194
    "Function",
195
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
196
    &sBoringInterfaceObjectClassClassOps,
197
    JS_NULL_CLASS_SPEC,
198
    JS_NULL_CLASS_EXT,
199
    &sInterfaceObjectClassObjectOps
200
  },
201
  eInterface,
202
  true,
203
  prototypes::id::CommandEvent,
204
  PrototypeTraits<prototypes::id::CommandEvent>::Depth,
205
  sNativePropertyHooks,
206
  "function CommandEvent() {\n    [native code]\n}",
207
  Event_Binding::GetConstructorObject
208
};
209
210
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
211
  {
212
    "CommandEventPrototype",
213
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE + 1 /* slot for the JSObject holding the unforgeable properties */),
214
    JS_NULL_CLASS_OPS,
215
    JS_NULL_CLASS_SPEC,
216
    JS_NULL_CLASS_EXT,
217
    JS_NULL_OBJECT_OPS
218
  },
219
  eInterfacePrototype,
220
  false,
221
  prototypes::id::CommandEvent,
222
  PrototypeTraits<prototypes::id::CommandEvent>::Depth,
223
  sNativePropertyHooks,
224
  "[object CommandEventPrototype]",
225
  Event_Binding::GetProtoObject
226
};
227
228
bool
229
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
230
0
{
231
0
  return IsChromeOrXBL(aCx, aObj);
232
0
}
233
234
static const js::ClassOps sClassOps = {
235
  _addProperty, /* addProperty */
236
  nullptr,               /* delProperty */
237
  nullptr,               /* enumerate */
238
  nullptr, /* newEnumerate */
239
  nullptr, /* resolve */
240
  nullptr, /* mayResolve */
241
  _finalize, /* finalize */
242
  nullptr, /* call */
243
  nullptr,               /* hasInstance */
244
  nullptr,               /* construct */
245
  nullptr, /* trace */
246
};
247
248
static const js::ClassExtension sClassExtension = {
249
  nullptr, /* weakmapKeyDelegateOp */
250
  _objectMoved /* objectMovedOp */
251
};
252
253
static const DOMJSClass sClass = {
254
  { "CommandEvent",
255
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1) | JSCLASS_SKIP_NURSERY_FINALIZE,
256
    &sClassOps,
257
    JS_NULL_CLASS_SPEC,
258
    &sClassExtension,
259
    JS_NULL_OBJECT_OPS
260
  },
261
  { prototypes::id::Event, prototypes::id::CommandEvent, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
262
  IsBaseOf<nsISupports, mozilla::dom::CommandEvent >::value,
263
  sNativePropertyHooks,
264
  FindAssociatedGlobalForNative<mozilla::dom::CommandEvent>::Get,
265
  GetProtoObjectHandle,
266
  GetCCParticipant<mozilla::dom::CommandEvent>::Get()
267
};
268
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
269
              "Must have the right minimal number of reserved slots.");
270
static_assert(1 >= 1,
271
              "Must have enough reserved slots.");
272
273
const JSClass*
274
GetJSClass()
275
0
{
276
0
  return sClass.ToJSClass();
277
0
}
278
279
bool
280
Wrap(JSContext* aCx, mozilla::dom::CommandEvent* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
281
0
{
282
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::CommandEvent>::value,
283
0
                "Shouldn't have wrappercached things that are not refcounted.");
284
0
  MOZ_ASSERT(static_cast<mozilla::dom::CommandEvent*>(aObject) ==
285
0
             reinterpret_cast<mozilla::dom::CommandEvent*>(aObject),
286
0
             "Multiple inheritance for mozilla::dom::CommandEvent is broken.");
287
0
  MOZ_ASSERT(static_cast<mozilla::dom::Event*>(aObject) ==
288
0
             reinterpret_cast<mozilla::dom::Event*>(aObject),
289
0
             "Multiple inheritance for mozilla::dom::Event is broken.");
290
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
291
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
292
0
  MOZ_ASSERT(!aCache->GetWrapper(),
293
0
             "You should probably not be using Wrap() directly; use "
294
0
             "GetOrCreateDOMReflector instead");
295
0
296
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
297
0
             "nsISupports must be on our primary inheritance chain");
298
0
299
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
300
0
  if (!global) {
301
0
    return false;
302
0
  }
303
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
304
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
305
0
306
0
  // That might have ended up wrapping us already, due to the wonders
307
0
  // of XBL.  Check for that, and bail out as needed.
308
0
  aReflector.set(aCache->GetWrapper());
309
0
  if (aReflector) {
310
#ifdef DEBUG
311
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
312
#endif // DEBUG
313
    return true;
314
0
  }
315
0
316
0
  JSAutoRealm ar(aCx, global);
317
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
318
0
  if (!canonicalProto) {
319
0
    return false;
320
0
  }
321
0
  JS::Rooted<JSObject*> proto(aCx);
322
0
  if (aGivenProto) {
323
0
    proto = aGivenProto;
324
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
325
0
    // coming in, we changed compartments to that of "parent" so may need
326
0
    // to wrap the proto here.
327
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
328
0
      if (!JS_WrapObject(aCx, &proto)) {
329
0
        return false;
330
0
      }
331
0
    }
332
0
  } else {
333
0
    proto = canonicalProto;
334
0
  }
335
0
336
0
  BindingJSObjectCreator<mozilla::dom::CommandEvent> creator(aCx);
337
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
338
0
  if (!aReflector) {
339
0
    return false;
340
0
  }
341
0
342
0
  aCache->SetWrapper(aReflector);
343
0
344
0
  // Important: do unforgeable property setup after we have handed
345
0
  // over ownership of the C++ object to obj as needed, so that if
346
0
  // we fail and it ends up GCed it won't have problems in the
347
0
  // finalizer trying to drop its ownership of the C++ object.
348
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx,
349
0
    &js::GetReservedSlot(canonicalProto, DOM_INTERFACE_PROTO_SLOTS_BASE).toObject());
350
0
  if (!JS_InitializePropertiesFromCompatibleNativeObject(aCx, aReflector, unforgeableHolder)) {
351
0
    aCache->ReleaseWrapper(aObject);
352
0
    aCache->ClearWrapper();
353
0
    return false;
354
0
  }
355
0
  creator.InitializationSucceeded();
356
0
357
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
358
0
             aCache->GetWrapperPreserveColor() == aReflector);
359
0
  // If proto != canonicalProto, we have to preserve our wrapper;
360
0
  // otherwise we won't be able to properly recreate it later, since
361
0
  // we won't know what proto to use.  Note that we don't check
362
0
  // aGivenProto here, since it's entirely possible (and even
363
0
  // somewhat common) to have a non-null aGivenProto which is the
364
0
  // same as canonicalProto.
365
0
  if (proto != canonicalProto) {
366
0
    PreserveWrapper(aObject);
367
0
  }
368
0
369
0
  return true;
370
0
}
371
372
const NativePropertyHooks sNativePropertyHooks[] = { {
373
  nullptr,
374
  nullptr,
375
  nullptr,
376
  { sNativeProperties.Upcast(), nullptr },
377
  prototypes::id::CommandEvent,
378
  constructors::id::CommandEvent,
379
  Event_Binding::sNativePropertyHooks,
380
  &DefaultXrayExpandoObjectClass
381
} };
382
383
void
384
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
385
0
{
386
0
  JS::Handle<JSObject*> parentProto(Event_Binding::GetProtoObjectHandle(aCx));
387
0
  if (!parentProto) {
388
0
    return;
389
0
  }
390
0
391
0
  JS::Handle<JSObject*> constructorProto(Event_Binding::GetConstructorObjectHandle(aCx));
392
0
  if (!constructorProto) {
393
0
    return;
394
0
  }
395
0
396
0
  static bool sIdsInited = false;
397
0
  if (!sIdsInited && NS_IsMainThread()) {
398
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
399
0
      return;
400
0
    }
401
0
    sIdsInited = true;
402
0
  }
403
0
404
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::CommandEvent);
405
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::CommandEvent);
406
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
407
0
                              &sPrototypeClass.mBase, protoCache,
408
0
                              nullptr,
409
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
410
0
                              interfaceCache,
411
0
                              sNativeProperties.Upcast(),
412
0
                              nullptr,
413
0
                              "CommandEvent", aDefineOnGlobal,
414
0
                              nullptr,
415
0
                              false);
416
0
417
0
  JS::Rooted<JSObject*> unforgeableHolder(aCx);
418
0
  {
419
0
    JS::Rooted<JSObject*> holderProto(aCx, *protoCache);
420
0
    unforgeableHolder = JS_NewObjectWithoutMetadata(aCx, sClass.ToJSClass(), holderProto);
421
0
    if (!unforgeableHolder) {
422
0
      *protoCache = nullptr;
423
0
      if (interfaceCache) {
424
0
        *interfaceCache = nullptr;
425
0
      }
426
0
      return;
427
0
    }
428
0
  }
429
0
430
0
  if (!DefineUnforgeableAttributes(aCx, unforgeableHolder, sUnforgeableAttributes)) {
431
0
    *protoCache = nullptr;
432
0
    if (interfaceCache) {
433
0
      *interfaceCache = nullptr;
434
0
    }
435
0
    return;
436
0
  }
437
0
438
0
  if (*protoCache) {
439
0
    js::SetReservedSlot(*protoCache, DOM_INTERFACE_PROTO_SLOTS_BASE,
440
0
                        JS::ObjectValue(*unforgeableHolder));
441
0
  }
442
0
}
443
444
JSObject*
445
GetConstructorObject(JSContext* aCx)
446
0
{
447
0
  return GetConstructorObjectHandle(aCx);
448
0
}
449
450
} // namespace CommandEvent_Binding
451
452
453
454
} // namespace dom
455
} // namespace mozilla