Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MIDIInputBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MIDIInput.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "EventHandlerBinding.h"
4
#include "MIDIInputBinding.h"
5
#include "MIDIPortBinding.h"
6
#include "WrapperFactory.h"
7
#include "mozilla/OwningNonNull.h"
8
#include "mozilla/Preferences.h"
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/MIDIInput.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/Nullable.h"
14
#include "mozilla/dom/XrayExpandoClass.h"
15
16
namespace mozilla {
17
namespace dom {
18
19
namespace binding_detail {}; // Just to make sure it's known as a namespace
20
using namespace mozilla::dom::binding_detail;
21
22
23
namespace MIDIInput_Binding {
24
25
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<MIDIPort_Binding::NativeType>::value,
26
              "Can't inherit from an interface with a different ownership model.");
27
28
MOZ_CAN_RUN_SCRIPT static bool
29
get_onmidimessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIInput* self, JSJitGetterCallArgs args)
30
0
{
31
0
  AUTO_PROFILER_LABEL_FAST("get MIDIInput.onmidimessage", DOM, cx);
32
0
33
0
  RefPtr<EventHandlerNonNull> result(self->GetOnmidimessage());
34
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
35
0
  if (result) {
36
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
37
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
38
0
      return false;
39
0
    }
40
0
    return true;
41
0
  } else {
42
0
    args.rval().setNull();
43
0
    return true;
44
0
  }
45
0
}
46
47
MOZ_CAN_RUN_SCRIPT static bool
48
set_onmidimessage(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIInput* self, JSJitSetterCallArgs args)
49
0
{
50
0
  AUTO_PROFILER_LABEL_FAST("set MIDIInput.onmidimessage", DOM, cx);
51
0
52
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
53
0
  if (args[0].isObject()) {
54
0
    { // scope for tempRoot and tempGlobalRoot if needed
55
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
56
0
    }
57
0
  } else {
58
0
    arg0 = nullptr;
59
0
  }
60
0
  self->SetOnmidimessage(Constify(arg0));
61
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
62
0
63
0
  return true;
64
0
}
65
66
static const JSJitInfo onmidimessage_getterinfo = {
67
  { (JSJitGetterOp)get_onmidimessage },
68
  { prototypes::id::MIDIInput },
69
  { PrototypeTraits<prototypes::id::MIDIInput>::Depth },
70
  JSJitInfo::Getter,
71
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
72
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
73
  false,  /* isInfallible. False in setters. */
74
  false,  /* isMovable.  Not relevant for setters. */
75
  false, /* isEliminatable.  Not relevant for setters. */
76
  false, /* isAlwaysInSlot.  Only relevant for getters. */
77
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
78
  false,  /* isTypedMethod.  Only relevant for methods. */
79
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
80
};
81
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
82
static_assert(0 < 1, "There is no slot for us");
83
static const JSJitInfo onmidimessage_setterinfo = {
84
  { (JSJitGetterOp)set_onmidimessage },
85
  { prototypes::id::MIDIInput },
86
  { PrototypeTraits<prototypes::id::MIDIInput>::Depth },
87
  JSJitInfo::Setter,
88
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
89
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
90
  false,  /* isInfallible. False in setters. */
91
  false,  /* isMovable.  Not relevant for setters. */
92
  false, /* isEliminatable.  Not relevant for setters. */
93
  false, /* isAlwaysInSlot.  Only relevant for getters. */
94
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
95
  false,  /* isTypedMethod.  Only relevant for methods. */
96
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
97
};
98
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
99
static_assert(0 < 1, "There is no slot for us");
100
101
static bool
102
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
103
0
{
104
0
  mozilla::dom::MIDIInput* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MIDIInput>(obj);
105
0
  // We don't want to preserve if we don't have a wrapper, and we
106
0
  // obviously can't preserve if we're not initialized.
107
0
  if (self && self->GetWrapperPreserveColor()) {
108
0
    PreserveWrapper(self);
109
0
  }
110
0
  return true;
111
0
}
112
113
static void
114
_finalize(js::FreeOp* fop, JSObject* obj)
115
0
{
116
0
  mozilla::dom::MIDIInput* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MIDIInput>(obj);
117
0
  if (self) {
118
0
    ClearWrapper(self, self, obj);
119
0
    AddForDeferredFinalization<mozilla::dom::MIDIInput>(self);
120
0
  }
121
0
}
122
123
static size_t
124
_objectMoved(JSObject* obj, JSObject* old)
125
0
{
126
0
  mozilla::dom::MIDIInput* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MIDIInput>(obj);
127
0
  if (self) {
128
0
    UpdateWrapper(self, self, obj, old);
129
0
  }
130
0
131
0
  return 0;
132
0
}
133
134
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
135
#if defined(__clang__)
136
#pragma clang diagnostic push
137
#pragma clang diagnostic ignored "-Wmissing-braces"
138
#endif
139
static const JSPropertySpec sAttributes_specs[] = {
140
  { "onmidimessage", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onmidimessage_getterinfo, GenericSetter<NormalThisPolicy>, &onmidimessage_setterinfo },
141
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
142
};
143
#if defined(__clang__)
144
#pragma clang diagnostic pop
145
#endif
146
147
// Can't be const because the pref-enabled boolean needs to be writable
148
static PrefableDisablers sAttributes_disablers0 = {
149
  true, true, 0, nullptr
150
};
151
152
static const Prefable<const JSPropertySpec> sAttributes[] = {
153
  { &sAttributes_disablers0, &sAttributes_specs[0] },
154
  { nullptr, nullptr }
155
};
156
157
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
158
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
159
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
160
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
161
162
163
static uint16_t sNativeProperties_sortedPropertyIndices[1];
164
static PropertyInfo sNativeProperties_propertyInfos[1];
165
166
static const NativePropertiesN<1> sNativeProperties = {
167
  false, 0,
168
  false, 0,
169
  false, 0,
170
  true,  0 /* sAttributes */,
171
  false, 0,
172
  false, 0,
173
  false, 0,
174
  -1,
175
  1,
176
  sNativeProperties_sortedPropertyIndices,
177
  {
178
    { sAttributes, &sNativeProperties_propertyInfos[0] }
179
  }
180
};
181
static_assert(1 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
182
    "We have a property info count that is oversized");
183
184
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
185
  {
186
    "Function",
187
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
188
    &sBoringInterfaceObjectClassClassOps,
189
    JS_NULL_CLASS_SPEC,
190
    JS_NULL_CLASS_EXT,
191
    &sInterfaceObjectClassObjectOps
192
  },
193
  eInterface,
194
  true,
195
  prototypes::id::MIDIInput,
196
  PrototypeTraits<prototypes::id::MIDIInput>::Depth,
197
  sNativePropertyHooks,
198
  "function MIDIInput() {\n    [native code]\n}",
199
  MIDIPort_Binding::GetConstructorObject
200
};
201
202
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
203
  {
204
    "MIDIInputPrototype",
205
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
206
    JS_NULL_CLASS_OPS,
207
    JS_NULL_CLASS_SPEC,
208
    JS_NULL_CLASS_EXT,
209
    JS_NULL_OBJECT_OPS
210
  },
211
  eInterfacePrototype,
212
  false,
213
  prototypes::id::MIDIInput,
214
  PrototypeTraits<prototypes::id::MIDIInput>::Depth,
215
  sNativePropertyHooks,
216
  "[object MIDIInputPrototype]",
217
  MIDIPort_Binding::GetProtoObject
218
};
219
220
bool
221
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
222
0
{
223
0
  static bool sPrefValue;
224
0
  static bool sPrefCacheSetUp = false;
225
0
  if (!sPrefCacheSetUp) {
226
0
    sPrefCacheSetUp = true;
227
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.webmidi.enabled");
228
0
  }
229
0
230
0
  return sPrefValue &&
231
0
         mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(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
  { "MIDIInput",
255
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
256
    &sClassOps,
257
    JS_NULL_CLASS_SPEC,
258
    &sClassExtension,
259
    JS_NULL_OBJECT_OPS
260
  },
261
  { prototypes::id::EventTarget, prototypes::id::MIDIPort, prototypes::id::MIDIInput, 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::MIDIInput >::value,
263
  sNativePropertyHooks,
264
  FindAssociatedGlobalForNative<mozilla::dom::MIDIInput>::Get,
265
  GetProtoObjectHandle,
266
  GetCCParticipant<mozilla::dom::MIDIInput>::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::MIDIInput* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
281
0
{
282
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MIDIInput>::value,
283
0
                "Shouldn't have wrappercached things that are not refcounted.");
284
0
  MOZ_ASSERT(static_cast<mozilla::dom::MIDIInput*>(aObject) ==
285
0
             reinterpret_cast<mozilla::dom::MIDIInput*>(aObject),
286
0
             "Multiple inheritance for mozilla::dom::MIDIInput is broken.");
287
0
  MOZ_ASSERT(static_cast<mozilla::dom::MIDIPort*>(aObject) ==
288
0
             reinterpret_cast<mozilla::dom::MIDIPort*>(aObject),
289
0
             "Multiple inheritance for mozilla::dom::MIDIPort is broken.");
290
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
291
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
292
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
293
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
294
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
295
0
  MOZ_ASSERT(!aCache->GetWrapper(),
296
0
             "You should probably not be using Wrap() directly; use "
297
0
             "GetOrCreateDOMReflector instead");
298
0
299
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
300
0
             "nsISupports must be on our primary inheritance chain");
301
0
302
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
303
0
  if (!global) {
304
0
    return false;
305
0
  }
306
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
307
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
308
0
309
0
  // That might have ended up wrapping us already, due to the wonders
310
0
  // of XBL.  Check for that, and bail out as needed.
311
0
  aReflector.set(aCache->GetWrapper());
312
0
  if (aReflector) {
313
#ifdef DEBUG
314
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
315
#endif // DEBUG
316
    return true;
317
0
  }
318
0
319
0
  JSAutoRealm ar(aCx, global);
320
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
321
0
  if (!canonicalProto) {
322
0
    return false;
323
0
  }
324
0
  JS::Rooted<JSObject*> proto(aCx);
325
0
  if (aGivenProto) {
326
0
    proto = aGivenProto;
327
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
328
0
    // coming in, we changed compartments to that of "parent" so may need
329
0
    // to wrap the proto here.
330
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
331
0
      if (!JS_WrapObject(aCx, &proto)) {
332
0
        return false;
333
0
      }
334
0
    }
335
0
  } else {
336
0
    proto = canonicalProto;
337
0
  }
338
0
339
0
  BindingJSObjectCreator<mozilla::dom::MIDIInput> creator(aCx);
340
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
341
0
  if (!aReflector) {
342
0
    return false;
343
0
  }
344
0
345
0
  aCache->SetWrapper(aReflector);
346
0
  creator.InitializationSucceeded();
347
0
348
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
349
0
             aCache->GetWrapperPreserveColor() == aReflector);
350
0
  // If proto != canonicalProto, we have to preserve our wrapper;
351
0
  // otherwise we won't be able to properly recreate it later, since
352
0
  // we won't know what proto to use.  Note that we don't check
353
0
  // aGivenProto here, since it's entirely possible (and even
354
0
  // somewhat common) to have a non-null aGivenProto which is the
355
0
  // same as canonicalProto.
356
0
  if (proto != canonicalProto) {
357
0
    PreserveWrapper(aObject);
358
0
  }
359
0
360
0
  return true;
361
0
}
362
363
const NativePropertyHooks sNativePropertyHooks[] = { {
364
  nullptr,
365
  nullptr,
366
  nullptr,
367
  { sNativeProperties.Upcast(), nullptr },
368
  prototypes::id::MIDIInput,
369
  constructors::id::MIDIInput,
370
  MIDIPort_Binding::sNativePropertyHooks,
371
  &DefaultXrayExpandoObjectClass
372
} };
373
374
void
375
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
376
0
{
377
0
  JS::Handle<JSObject*> parentProto(MIDIPort_Binding::GetProtoObjectHandle(aCx));
378
0
  if (!parentProto) {
379
0
    return;
380
0
  }
381
0
382
0
  JS::Handle<JSObject*> constructorProto(MIDIPort_Binding::GetConstructorObjectHandle(aCx));
383
0
  if (!constructorProto) {
384
0
    return;
385
0
  }
386
0
387
0
  static bool sIdsInited = false;
388
0
  if (!sIdsInited && NS_IsMainThread()) {
389
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
390
0
      return;
391
0
    }
392
0
    sIdsInited = true;
393
0
  }
394
0
395
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MIDIInput);
396
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MIDIInput);
397
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
398
0
                              &sPrototypeClass.mBase, protoCache,
399
0
                              nullptr,
400
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
401
0
                              interfaceCache,
402
0
                              sNativeProperties.Upcast(),
403
0
                              nullptr,
404
0
                              "MIDIInput", aDefineOnGlobal,
405
0
                              nullptr,
406
0
                              false);
407
0
}
408
409
JSObject*
410
GetConstructorObject(JSContext* aCx)
411
0
{
412
0
  return GetConstructorObjectHandle(aCx);
413
0
}
414
415
} // namespace MIDIInput_Binding
416
417
418
419
} // namespace dom
420
} // namespace mozilla