Coverage Report

Created: 2018-09-25 14:53

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