Coverage Report

Created: 2018-09-25 14:53

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