Coverage Report

Created: 2018-09-25 14:53

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