Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/MIDIPortBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM MIDIPort.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "EventHandlerBinding.h"
4
#include "EventTargetBinding.h"
5
#include "MIDIPortBinding.h"
6
#include "WrapperFactory.h"
7
#include "jsapi.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/Preferences.h"
10
#include "mozilla/dom/BindingUtils.h"
11
#include "mozilla/dom/DOMJSClass.h"
12
#include "mozilla/dom/MIDIPort.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/Nullable.h"
15
#include "mozilla/dom/Promise.h"
16
#include "mozilla/dom/ToJSValue.h"
17
#include "mozilla/dom/XrayExpandoClass.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
namespace MIDIPortTypeValues {
27
extern const EnumEntry strings[3] = {
28
  {"input", 5},
29
  {"output", 6},
30
  { nullptr, 0 }
31
};
32
} // namespace MIDIPortTypeValues
33
34
bool
35
ToJSValue(JSContext* aCx, MIDIPortType aArgument, JS::MutableHandle<JS::Value> aValue)
36
0
{
37
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MIDIPortTypeValues::strings));
38
0
  JSString* resultStr =
39
0
    JS_NewStringCopyN(aCx, MIDIPortTypeValues::strings[uint32_t(aArgument)].value,
40
0
                      MIDIPortTypeValues::strings[uint32_t(aArgument)].length);
41
0
  if (!resultStr) {
42
0
    return false;
43
0
  }
44
0
  aValue.setString(resultStr);
45
0
  return true;
46
0
}
47
48
49
namespace MIDIPortDeviceStateValues {
50
extern const EnumEntry strings[3] = {
51
  {"disconnected", 12},
52
  {"connected", 9},
53
  { nullptr, 0 }
54
};
55
} // namespace MIDIPortDeviceStateValues
56
57
bool
58
ToJSValue(JSContext* aCx, MIDIPortDeviceState aArgument, JS::MutableHandle<JS::Value> aValue)
59
0
{
60
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MIDIPortDeviceStateValues::strings));
61
0
  JSString* resultStr =
62
0
    JS_NewStringCopyN(aCx, MIDIPortDeviceStateValues::strings[uint32_t(aArgument)].value,
63
0
                      MIDIPortDeviceStateValues::strings[uint32_t(aArgument)].length);
64
0
  if (!resultStr) {
65
0
    return false;
66
0
  }
67
0
  aValue.setString(resultStr);
68
0
  return true;
69
0
}
70
71
72
namespace MIDIPortConnectionStateValues {
73
extern const EnumEntry strings[4] = {
74
  {"open", 4},
75
  {"closed", 6},
76
  {"pending", 7},
77
  { nullptr, 0 }
78
};
79
} // namespace MIDIPortConnectionStateValues
80
81
bool
82
ToJSValue(JSContext* aCx, MIDIPortConnectionState aArgument, JS::MutableHandle<JS::Value> aValue)
83
0
{
84
0
  MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MIDIPortConnectionStateValues::strings));
85
0
  JSString* resultStr =
86
0
    JS_NewStringCopyN(aCx, MIDIPortConnectionStateValues::strings[uint32_t(aArgument)].value,
87
0
                      MIDIPortConnectionStateValues::strings[uint32_t(aArgument)].length);
88
0
  if (!resultStr) {
89
0
    return false;
90
0
  }
91
0
  aValue.setString(resultStr);
92
0
  return true;
93
0
}
94
95
96
namespace MIDIPort_Binding {
97
98
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
99
              "Can't inherit from an interface with a different ownership model.");
100
101
MOZ_CAN_RUN_SCRIPT static bool
102
get_id(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
103
0
{
104
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.id", DOM, cx);
105
0
106
0
  DOMString result;
107
0
  self->GetId(result);
108
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
109
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
110
0
    return false;
111
0
  }
112
0
  return true;
113
0
}
114
115
static const JSJitInfo id_getterinfo = {
116
  { (JSJitGetterOp)get_id },
117
  { prototypes::id::MIDIPort },
118
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
119
  JSJitInfo::Getter,
120
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
121
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
122
  false,  /* isInfallible. False in setters. */
123
  false,  /* isMovable.  Not relevant for setters. */
124
  false, /* isEliminatable.  Not relevant for setters. */
125
  false, /* isAlwaysInSlot.  Only relevant for getters. */
126
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
127
  false,  /* isTypedMethod.  Only relevant for methods. */
128
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
129
};
130
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
131
static_assert(0 < 1, "There is no slot for us");
132
133
MOZ_CAN_RUN_SCRIPT static bool
134
get_manufacturer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
135
0
{
136
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.manufacturer", DOM, cx);
137
0
138
0
  DOMString result;
139
0
  self->GetManufacturer(result);
140
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
141
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
142
0
    return false;
143
0
  }
144
0
  return true;
145
0
}
146
147
static const JSJitInfo manufacturer_getterinfo = {
148
  { (JSJitGetterOp)get_manufacturer },
149
  { prototypes::id::MIDIPort },
150
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
151
  JSJitInfo::Getter,
152
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
153
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
154
  false,  /* isInfallible. False in setters. */
155
  false,  /* isMovable.  Not relevant for setters. */
156
  false, /* isEliminatable.  Not relevant for setters. */
157
  false, /* isAlwaysInSlot.  Only relevant for getters. */
158
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
159
  false,  /* isTypedMethod.  Only relevant for methods. */
160
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
161
};
162
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
163
static_assert(0 < 1, "There is no slot for us");
164
165
MOZ_CAN_RUN_SCRIPT static bool
166
get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
167
0
{
168
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.name", DOM, cx);
169
0
170
0
  DOMString result;
171
0
  self->GetName(result);
172
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
173
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
174
0
    return false;
175
0
  }
176
0
  return true;
177
0
}
178
179
static const JSJitInfo name_getterinfo = {
180
  { (JSJitGetterOp)get_name },
181
  { prototypes::id::MIDIPort },
182
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
183
  JSJitInfo::Getter,
184
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
185
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
186
  false,  /* isInfallible. False in setters. */
187
  false,  /* isMovable.  Not relevant for setters. */
188
  false, /* isEliminatable.  Not relevant for setters. */
189
  false, /* isAlwaysInSlot.  Only relevant for getters. */
190
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
191
  false,  /* isTypedMethod.  Only relevant for methods. */
192
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
193
};
194
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
195
static_assert(0 < 1, "There is no slot for us");
196
197
MOZ_CAN_RUN_SCRIPT static bool
198
get_version(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
199
0
{
200
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.version", DOM, cx);
201
0
202
0
  DOMString result;
203
0
  self->GetVersion(result);
204
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
205
0
  if (!xpc::StringToJsval(cx, result, args.rval())) {
206
0
    return false;
207
0
  }
208
0
  return true;
209
0
}
210
211
static const JSJitInfo version_getterinfo = {
212
  { (JSJitGetterOp)get_version },
213
  { prototypes::id::MIDIPort },
214
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
215
  JSJitInfo::Getter,
216
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
217
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
218
  false,  /* isInfallible. False in setters. */
219
  false,  /* isMovable.  Not relevant for setters. */
220
  false, /* isEliminatable.  Not relevant for setters. */
221
  false, /* isAlwaysInSlot.  Only relevant for getters. */
222
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
223
  false,  /* isTypedMethod.  Only relevant for methods. */
224
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
225
};
226
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
227
static_assert(0 < 1, "There is no slot for us");
228
229
MOZ_CAN_RUN_SCRIPT static bool
230
get_type(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
231
0
{
232
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.type", DOM, cx);
233
0
234
0
  MIDIPortType result(self->Type());
235
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
236
0
  if (!ToJSValue(cx, result, args.rval())) {
237
0
    return false;
238
0
  }
239
0
  return true;
240
0
}
241
242
static const JSJitInfo type_getterinfo = {
243
  { (JSJitGetterOp)get_type },
244
  { prototypes::id::MIDIPort },
245
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
246
  JSJitInfo::Getter,
247
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
248
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
249
  false,  /* isInfallible. False in setters. */
250
  false,  /* isMovable.  Not relevant for setters. */
251
  false, /* isEliminatable.  Not relevant for setters. */
252
  false, /* isAlwaysInSlot.  Only relevant for getters. */
253
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
254
  false,  /* isTypedMethod.  Only relevant for methods. */
255
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
256
};
257
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
258
static_assert(0 < 1, "There is no slot for us");
259
260
MOZ_CAN_RUN_SCRIPT static bool
261
get_state(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
262
0
{
263
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.state", DOM, cx);
264
0
265
0
  MIDIPortDeviceState result(self->State());
266
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
267
0
  if (!ToJSValue(cx, result, args.rval())) {
268
0
    return false;
269
0
  }
270
0
  return true;
271
0
}
272
273
static const JSJitInfo state_getterinfo = {
274
  { (JSJitGetterOp)get_state },
275
  { prototypes::id::MIDIPort },
276
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
277
  JSJitInfo::Getter,
278
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
279
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
280
  false,  /* isInfallible. False in setters. */
281
  false,  /* isMovable.  Not relevant for setters. */
282
  false, /* isEliminatable.  Not relevant for setters. */
283
  false, /* isAlwaysInSlot.  Only relevant for getters. */
284
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
285
  false,  /* isTypedMethod.  Only relevant for methods. */
286
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
287
};
288
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
289
static_assert(0 < 1, "There is no slot for us");
290
291
MOZ_CAN_RUN_SCRIPT static bool
292
get_connection(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
293
0
{
294
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.connection", DOM, cx);
295
0
296
0
  MIDIPortConnectionState result(self->Connection());
297
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
298
0
  if (!ToJSValue(cx, result, args.rval())) {
299
0
    return false;
300
0
  }
301
0
  return true;
302
0
}
303
304
static const JSJitInfo connection_getterinfo = {
305
  { (JSJitGetterOp)get_connection },
306
  { prototypes::id::MIDIPort },
307
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
308
  JSJitInfo::Getter,
309
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
310
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
311
  false,  /* isInfallible. False in setters. */
312
  false,  /* isMovable.  Not relevant for setters. */
313
  false, /* isEliminatable.  Not relevant for setters. */
314
  false, /* isAlwaysInSlot.  Only relevant for getters. */
315
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
316
  false,  /* isTypedMethod.  Only relevant for methods. */
317
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
318
};
319
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
320
static_assert(0 < 1, "There is no slot for us");
321
322
MOZ_CAN_RUN_SCRIPT static bool
323
get_onstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitGetterCallArgs args)
324
0
{
325
0
  AUTO_PROFILER_LABEL_FAST("get MIDIPort.onstatechange", DOM, cx);
326
0
327
0
  RefPtr<EventHandlerNonNull> result(self->GetOnstatechange());
328
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
329
0
  if (result) {
330
0
    args.rval().setObjectOrNull(GetCallbackFromCallbackObject(cx, result));
331
0
    if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
332
0
      return false;
333
0
    }
334
0
    return true;
335
0
  } else {
336
0
    args.rval().setNull();
337
0
    return true;
338
0
  }
339
0
}
340
341
MOZ_CAN_RUN_SCRIPT static bool
342
set_onstatechange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, JSJitSetterCallArgs args)
343
0
{
344
0
  AUTO_PROFILER_LABEL_FAST("set MIDIPort.onstatechange", DOM, cx);
345
0
346
0
  RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
347
0
  if (args[0].isObject()) {
348
0
    { // scope for tempRoot and tempGlobalRoot if needed
349
0
      arg0 = new binding_detail::FastEventHandlerNonNull(&args[0].toObject(), JS::CurrentGlobalOrNull(cx));
350
0
    }
351
0
  } else {
352
0
    arg0 = nullptr;
353
0
  }
354
0
  self->SetOnstatechange(Constify(arg0));
355
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
356
0
357
0
  return true;
358
0
}
359
360
static const JSJitInfo onstatechange_getterinfo = {
361
  { (JSJitGetterOp)get_onstatechange },
362
  { prototypes::id::MIDIPort },
363
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
364
  JSJitInfo::Getter,
365
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
366
  JSVAL_TYPE_UNKNOWN,  /* returnType.  Not relevant for setters. */
367
  false,  /* isInfallible. False in setters. */
368
  false,  /* isMovable.  Not relevant for setters. */
369
  false, /* isEliminatable.  Not relevant for setters. */
370
  false, /* isAlwaysInSlot.  Only relevant for getters. */
371
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
372
  false,  /* isTypedMethod.  Only relevant for methods. */
373
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
374
};
375
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
376
static_assert(0 < 1, "There is no slot for us");
377
static const JSJitInfo onstatechange_setterinfo = {
378
  { (JSJitGetterOp)set_onstatechange },
379
  { prototypes::id::MIDIPort },
380
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
381
  JSJitInfo::Setter,
382
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
383
  JSVAL_TYPE_UNDEFINED,  /* returnType.  Not relevant for setters. */
384
  false,  /* isInfallible. False in setters. */
385
  false,  /* isMovable.  Not relevant for setters. */
386
  false, /* isEliminatable.  Not relevant for setters. */
387
  false, /* isAlwaysInSlot.  Only relevant for getters. */
388
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
389
  false,  /* isTypedMethod.  Only relevant for methods. */
390
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
391
};
392
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
393
static_assert(0 < 1, "There is no slot for us");
394
395
MOZ_CAN_RUN_SCRIPT static bool
396
open(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, const JSJitMethodCallArgs& args)
397
0
{
398
0
  AUTO_PROFILER_LABEL_FAST("MIDIPort.open", DOM, cx);
399
0
400
0
  auto result(StrongOrRawPtr<Promise>(self->Open()));
401
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
402
0
  if (!ToJSValue(cx, result, args.rval())) {
403
0
    return false;
404
0
  }
405
0
  return true;
406
0
}
407
408
MOZ_CAN_RUN_SCRIPT static bool
409
open_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, const JSJitMethodCallArgs& args)
410
0
{
411
0
  bool ok = open(cx, obj, self, args);
412
0
  if (ok) {
413
0
    return true;
414
0
  }
415
0
  return ConvertExceptionToPromise(cx, args.rval());
416
0
}
417
418
static const JSJitInfo open_methodinfo = {
419
  { (JSJitGetterOp)open_promiseWrapper },
420
  { prototypes::id::MIDIPort },
421
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
422
  JSJitInfo::Method,
423
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
424
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
425
  false,  /* isInfallible. False in setters. */
426
  false,  /* isMovable.  Not relevant for setters. */
427
  false, /* isEliminatable.  Not relevant for setters. */
428
  false, /* isAlwaysInSlot.  Only relevant for getters. */
429
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
430
  false,  /* isTypedMethod.  Only relevant for methods. */
431
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
432
};
433
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
434
static_assert(0 < 1, "There is no slot for us");
435
436
MOZ_CAN_RUN_SCRIPT static bool
437
close(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, const JSJitMethodCallArgs& args)
438
0
{
439
0
  AUTO_PROFILER_LABEL_FAST("MIDIPort.close", DOM, cx);
440
0
441
0
  auto result(StrongOrRawPtr<Promise>(self->Close()));
442
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
443
0
  if (!ToJSValue(cx, result, args.rval())) {
444
0
    return false;
445
0
  }
446
0
  return true;
447
0
}
448
449
MOZ_CAN_RUN_SCRIPT static bool
450
close_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MIDIPort* self, const JSJitMethodCallArgs& args)
451
0
{
452
0
  bool ok = close(cx, obj, self, args);
453
0
  if (ok) {
454
0
    return true;
455
0
  }
456
0
  return ConvertExceptionToPromise(cx, args.rval());
457
0
}
458
459
static const JSJitInfo close_methodinfo = {
460
  { (JSJitGetterOp)close_promiseWrapper },
461
  { prototypes::id::MIDIPort },
462
  { PrototypeTraits<prototypes::id::MIDIPort>::Depth },
463
  JSJitInfo::Method,
464
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
465
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
466
  false,  /* isInfallible. False in setters. */
467
  false,  /* isMovable.  Not relevant for setters. */
468
  false, /* isEliminatable.  Not relevant for setters. */
469
  false, /* isAlwaysInSlot.  Only relevant for getters. */
470
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
471
  false,  /* isTypedMethod.  Only relevant for methods. */
472
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
473
};
474
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
475
static_assert(0 < 1, "There is no slot for us");
476
477
static bool
478
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
479
0
{
480
0
  mozilla::dom::MIDIPort* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MIDIPort>(obj);
481
0
  // We don't want to preserve if we don't have a wrapper, and we
482
0
  // obviously can't preserve if we're not initialized.
483
0
  if (self && self->GetWrapperPreserveColor()) {
484
0
    PreserveWrapper(self);
485
0
  }
486
0
  return true;
487
0
}
488
489
static void
490
_finalize(js::FreeOp* fop, JSObject* obj)
491
0
{
492
0
  mozilla::dom::MIDIPort* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MIDIPort>(obj);
493
0
  if (self) {
494
0
    ClearWrapper(self, self, obj);
495
0
    AddForDeferredFinalization<mozilla::dom::MIDIPort>(self);
496
0
  }
497
0
}
498
499
static size_t
500
_objectMoved(JSObject* obj, JSObject* old)
501
0
{
502
0
  mozilla::dom::MIDIPort* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MIDIPort>(obj);
503
0
  if (self) {
504
0
    UpdateWrapper(self, self, obj, old);
505
0
  }
506
0
507
0
  return 0;
508
0
}
509
510
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
511
#if defined(__clang__)
512
#pragma clang diagnostic push
513
#pragma clang diagnostic ignored "-Wmissing-braces"
514
#endif
515
static const JSFunctionSpec sMethods_specs[] = {
516
  JS_FNSPEC("open", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&open_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
517
  JS_FNSPEC("close", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&close_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
518
  JS_FS_END
519
};
520
#if defined(__clang__)
521
#pragma clang diagnostic pop
522
#endif
523
524
// Can't be const because the pref-enabled boolean needs to be writable
525
static PrefableDisablers sMethods_disablers0 = {
526
  true, true, 0, nullptr
527
};
528
529
static const Prefable<const JSFunctionSpec> sMethods[] = {
530
  { &sMethods_disablers0, &sMethods_specs[0] },
531
  { nullptr, nullptr }
532
};
533
534
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
535
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
536
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
537
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
538
539
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
540
#if defined(__clang__)
541
#pragma clang diagnostic push
542
#pragma clang diagnostic ignored "-Wmissing-braces"
543
#endif
544
static const JSPropertySpec sAttributes_specs[] = {
545
  { "id", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &id_getterinfo, nullptr, nullptr },
546
  { "manufacturer", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &manufacturer_getterinfo, nullptr, nullptr },
547
  { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr },
548
  { "version", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &version_getterinfo, nullptr, nullptr },
549
  { "type", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &type_getterinfo, nullptr, nullptr },
550
  { "state", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &state_getterinfo, nullptr, nullptr },
551
  { "connection", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &connection_getterinfo, nullptr, nullptr },
552
  { "onstatechange", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &onstatechange_getterinfo, GenericSetter<NormalThisPolicy>, &onstatechange_setterinfo },
553
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
554
};
555
#if defined(__clang__)
556
#pragma clang diagnostic pop
557
#endif
558
559
// Can't be const because the pref-enabled boolean needs to be writable
560
static PrefableDisablers sAttributes_disablers0 = {
561
  true, true, 0, nullptr
562
};
563
564
static const Prefable<const JSPropertySpec> sAttributes[] = {
565
  { &sAttributes_disablers0, &sAttributes_specs[0] },
566
  { nullptr, nullptr }
567
};
568
569
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
570
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
571
static_assert(8 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
572
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
573
574
575
static uint16_t sNativeProperties_sortedPropertyIndices[10];
576
static PropertyInfo sNativeProperties_propertyInfos[10];
577
578
static const NativePropertiesN<2> sNativeProperties = {
579
  false, 0,
580
  false, 0,
581
  true,  0 /* sMethods */,
582
  true,  1 /* sAttributes */,
583
  false, 0,
584
  false, 0,
585
  false, 0,
586
  -1,
587
  10,
588
  sNativeProperties_sortedPropertyIndices,
589
  {
590
    { sMethods, &sNativeProperties_propertyInfos[0] },
591
    { sAttributes, &sNativeProperties_propertyInfos[2] }
592
  }
593
};
594
static_assert(10 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
595
    "We have a property info count that is oversized");
596
597
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
598
  {
599
    "Function",
600
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
601
    &sBoringInterfaceObjectClassClassOps,
602
    JS_NULL_CLASS_SPEC,
603
    JS_NULL_CLASS_EXT,
604
    &sInterfaceObjectClassObjectOps
605
  },
606
  eInterface,
607
  true,
608
  prototypes::id::MIDIPort,
609
  PrototypeTraits<prototypes::id::MIDIPort>::Depth,
610
  sNativePropertyHooks,
611
  "function MIDIPort() {\n    [native code]\n}",
612
  EventTarget_Binding::GetConstructorObject
613
};
614
615
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
616
  {
617
    "MIDIPortPrototype",
618
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
619
    JS_NULL_CLASS_OPS,
620
    JS_NULL_CLASS_SPEC,
621
    JS_NULL_CLASS_EXT,
622
    JS_NULL_OBJECT_OPS
623
  },
624
  eInterfacePrototype,
625
  false,
626
  prototypes::id::MIDIPort,
627
  PrototypeTraits<prototypes::id::MIDIPort>::Depth,
628
  sNativePropertyHooks,
629
  "[object MIDIPortPrototype]",
630
  EventTarget_Binding::GetProtoObject
631
};
632
633
bool
634
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
635
0
{
636
0
  static bool sPrefValue;
637
0
  static bool sPrefCacheSetUp = false;
638
0
  if (!sPrefCacheSetUp) {
639
0
    sPrefCacheSetUp = true;
640
0
    Preferences::AddBoolVarCache(&sPrefValue, "dom.webmidi.enabled");
641
0
  }
642
0
643
0
  return sPrefValue &&
644
0
         mozilla::dom::IsSecureContextOrObjectIsFromSecureContext(aCx, aObj);
645
0
}
646
647
static const js::ClassOps sClassOps = {
648
  _addProperty, /* addProperty */
649
  nullptr,               /* delProperty */
650
  nullptr,               /* enumerate */
651
  nullptr, /* newEnumerate */
652
  nullptr, /* resolve */
653
  nullptr, /* mayResolve */
654
  _finalize, /* finalize */
655
  nullptr, /* call */
656
  nullptr,               /* hasInstance */
657
  nullptr,               /* construct */
658
  nullptr, /* trace */
659
};
660
661
static const js::ClassExtension sClassExtension = {
662
  nullptr, /* weakmapKeyDelegateOp */
663
  _objectMoved /* objectMovedOp */
664
};
665
666
static const DOMJSClass sClass = {
667
  { "MIDIPort",
668
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
669
    &sClassOps,
670
    JS_NULL_CLASS_SPEC,
671
    &sClassExtension,
672
    JS_NULL_OBJECT_OPS
673
  },
674
  { prototypes::id::EventTarget, prototypes::id::MIDIPort, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
675
  IsBaseOf<nsISupports, mozilla::dom::MIDIPort >::value,
676
  sNativePropertyHooks,
677
  FindAssociatedGlobalForNative<mozilla::dom::MIDIPort>::Get,
678
  GetProtoObjectHandle,
679
  GetCCParticipant<mozilla::dom::MIDIPort>::Get()
680
};
681
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
682
              "Must have the right minimal number of reserved slots.");
683
static_assert(1 >= 1,
684
              "Must have enough reserved slots.");
685
686
const JSClass*
687
GetJSClass()
688
0
{
689
0
  return sClass.ToJSClass();
690
0
}
691
692
bool
693
Wrap(JSContext* aCx, mozilla::dom::MIDIPort* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
694
0
{
695
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::MIDIPort>::value,
696
0
                "Shouldn't have wrappercached things that are not refcounted.");
697
0
  MOZ_ASSERT(static_cast<mozilla::dom::MIDIPort*>(aObject) ==
698
0
             reinterpret_cast<mozilla::dom::MIDIPort*>(aObject),
699
0
             "Multiple inheritance for mozilla::dom::MIDIPort is broken.");
700
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
701
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
702
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
703
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
704
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
705
0
  MOZ_ASSERT(!aCache->GetWrapper(),
706
0
             "You should probably not be using Wrap() directly; use "
707
0
             "GetOrCreateDOMReflector instead");
708
0
709
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
710
0
             "nsISupports must be on our primary inheritance chain");
711
0
712
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
713
0
  if (!global) {
714
0
    return false;
715
0
  }
716
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
717
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
718
0
719
0
  // That might have ended up wrapping us already, due to the wonders
720
0
  // of XBL.  Check for that, and bail out as needed.
721
0
  aReflector.set(aCache->GetWrapper());
722
0
  if (aReflector) {
723
#ifdef DEBUG
724
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
725
#endif // DEBUG
726
    return true;
727
0
  }
728
0
729
0
  JSAutoRealm ar(aCx, global);
730
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
731
0
  if (!canonicalProto) {
732
0
    return false;
733
0
  }
734
0
  JS::Rooted<JSObject*> proto(aCx);
735
0
  if (aGivenProto) {
736
0
    proto = aGivenProto;
737
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
738
0
    // coming in, we changed compartments to that of "parent" so may need
739
0
    // to wrap the proto here.
740
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
741
0
      if (!JS_WrapObject(aCx, &proto)) {
742
0
        return false;
743
0
      }
744
0
    }
745
0
  } else {
746
0
    proto = canonicalProto;
747
0
  }
748
0
749
0
  BindingJSObjectCreator<mozilla::dom::MIDIPort> creator(aCx);
750
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
751
0
  if (!aReflector) {
752
0
    return false;
753
0
  }
754
0
755
0
  aCache->SetWrapper(aReflector);
756
0
  creator.InitializationSucceeded();
757
0
758
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
759
0
             aCache->GetWrapperPreserveColor() == aReflector);
760
0
  // If proto != canonicalProto, we have to preserve our wrapper;
761
0
  // otherwise we won't be able to properly recreate it later, since
762
0
  // we won't know what proto to use.  Note that we don't check
763
0
  // aGivenProto here, since it's entirely possible (and even
764
0
  // somewhat common) to have a non-null aGivenProto which is the
765
0
  // same as canonicalProto.
766
0
  if (proto != canonicalProto) {
767
0
    PreserveWrapper(aObject);
768
0
  }
769
0
770
0
  return true;
771
0
}
772
773
const NativePropertyHooks sNativePropertyHooks[] = { {
774
  nullptr,
775
  nullptr,
776
  nullptr,
777
  { sNativeProperties.Upcast(), nullptr },
778
  prototypes::id::MIDIPort,
779
  constructors::id::MIDIPort,
780
  EventTarget_Binding::sNativePropertyHooks,
781
  &DefaultXrayExpandoObjectClass
782
} };
783
784
void
785
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
786
0
{
787
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
788
0
  if (!parentProto) {
789
0
    return;
790
0
  }
791
0
792
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
793
0
  if (!constructorProto) {
794
0
    return;
795
0
  }
796
0
797
0
  static bool sIdsInited = false;
798
0
  if (!sIdsInited && NS_IsMainThread()) {
799
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
800
0
      return;
801
0
    }
802
0
    sIdsInited = true;
803
0
  }
804
0
805
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MIDIPort);
806
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MIDIPort);
807
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
808
0
                              &sPrototypeClass.mBase, protoCache,
809
0
                              nullptr,
810
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
811
0
                              interfaceCache,
812
0
                              sNativeProperties.Upcast(),
813
0
                              nullptr,
814
0
                              "MIDIPort", aDefineOnGlobal,
815
0
                              nullptr,
816
0
                              false);
817
0
}
818
819
JSObject*
820
GetProtoObject(JSContext* aCx)
821
0
{
822
0
  return GetProtoObjectHandle(aCx);
823
0
}
824
825
JSObject*
826
GetConstructorObject(JSContext* aCx)
827
0
{
828
0
  return GetConstructorObjectHandle(aCx);
829
0
}
830
831
} // namespace MIDIPort_Binding
832
833
834
835
} // namespace dom
836
} // namespace mozilla