Coverage Report

Created: 2018-09-25 14:53

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