Coverage Report

Created: 2018-09-25 14:53

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