Coverage Report

Created: 2018-09-25 14:53

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