Coverage Report

Created: 2018-09-25 14:53

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