Coverage Report

Created: 2018-09-25 14:53

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