Coverage Report

Created: 2018-09-25 14:53

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