Coverage Report

Created: 2018-09-25 14:53

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