Coverage Report

Created: 2018-09-25 14:53

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