Coverage Report

Created: 2018-09-25 14:53

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