Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/DocumentTimelineBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM DocumentTimeline.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AnimationTimelineBinding.h"
4
#include "AtomList.h"
5
#include "DocumentTimelineBinding.h"
6
#include "WrapperFactory.h"
7
#include "mozilla/FloatingPoint.h"
8
#include "mozilla/OwningNonNull.h"
9
#include "mozilla/dom/BindingUtils.h"
10
#include "mozilla/dom/DOMJSClass.h"
11
#include "mozilla/dom/DocumentTimeline.h"
12
#include "mozilla/dom/NonRefcountedDOMObject.h"
13
#include "mozilla/dom/PrimitiveConversions.h"
14
#include "mozilla/dom/ScriptSettings.h"
15
#include "mozilla/dom/SimpleGlobalObject.h"
16
#include "mozilla/dom/XrayExpandoClass.h"
17
#include "nsDocument.h"
18
19
namespace mozilla {
20
namespace dom {
21
22
namespace binding_detail {}; // Just to make sure it's known as a namespace
23
using namespace mozilla::dom::binding_detail;
24
25
26
27
DocumentTimelineOptions::DocumentTimelineOptions()
28
0
{
29
0
  // Safe to pass a null context if we pass a null value
30
0
  Init(nullptr, JS::NullHandleValue);
31
0
}
32
33
34
35
bool
36
DocumentTimelineOptions::InitIds(JSContext* cx, DocumentTimelineOptionsAtoms* atomsCache)
37
0
{
38
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
39
0
40
0
  // Initialize these in reverse order so that any failure leaves the first one
41
0
  // uninitialized.
42
0
  if (!atomsCache->originTime_id.init(cx, "originTime")) {
43
0
    return false;
44
0
  }
45
0
  return true;
46
0
}
47
48
bool
49
DocumentTimelineOptions::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
50
0
{
51
0
  // Passing a null JSContext is OK only if we're initing from null,
52
0
  // Since in that case we will not have to do any property gets
53
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
54
0
  // checkers by static analysis tools
55
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
56
0
  DocumentTimelineOptionsAtoms* atomsCache = nullptr;
57
0
  if (cx) {
58
0
    atomsCache = GetAtomCache<DocumentTimelineOptionsAtoms>(cx);
59
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
60
0
      return false;
61
0
    }
62
0
  }
63
0
64
0
  if (!IsConvertibleToDictionary(val)) {
65
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
66
0
  }
67
0
68
0
  bool isNull = val.isNullOrUndefined();
69
0
  // We only need these if !isNull, in which case we have |cx|.
70
0
  Maybe<JS::Rooted<JSObject *> > object;
71
0
  Maybe<JS::Rooted<JS::Value> > temp;
72
0
  if (!isNull) {
73
0
    MOZ_ASSERT(cx);
74
0
    object.emplace(cx, &val.toObject());
75
0
    temp.emplace(cx);
76
0
  }
77
0
  if (!isNull) {
78
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->originTime_id, temp.ptr())) {
79
0
      return false;
80
0
    }
81
0
  }
82
0
  if (!isNull && !temp->isUndefined()) {
83
0
    if (!ValueToPrimitive<double, eDefault>(cx, temp.ref(), &mOriginTime)) {
84
0
      return false;
85
0
    } else if (!mozilla::IsFinite(mOriginTime)) {
86
0
      ThrowErrorMessage(cx, MSG_NOT_FINITE, "'originTime' member of DocumentTimelineOptions");
87
0
      return false;
88
0
    }
89
0
  } else {
90
0
    mOriginTime = 0.0;
91
0
  }
92
0
  mIsAnyMemberPresent = true;
93
0
  return true;
94
0
}
95
96
bool
97
DocumentTimelineOptions::Init(const nsAString& aJSON)
98
0
{
99
0
  AutoJSAPI jsapi;
100
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
101
0
  if (!cleanGlobal) {
102
0
    return false;
103
0
  }
104
0
  if (!jsapi.Init(cleanGlobal)) {
105
0
    return false;
106
0
  }
107
0
  JSContext* cx = jsapi.cx();
108
0
  JS::Rooted<JS::Value> json(cx);
109
0
  bool ok = ParseJSON(cx, aJSON, &json);
110
0
  NS_ENSURE_TRUE(ok, false);
111
0
  return Init(cx, json);
112
0
}
113
114
bool
115
DocumentTimelineOptions::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
116
0
{
117
0
  DocumentTimelineOptionsAtoms* atomsCache = GetAtomCache<DocumentTimelineOptionsAtoms>(cx);
118
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
119
0
    return false;
120
0
  }
121
0
122
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
123
0
  if (!obj) {
124
0
    return false;
125
0
  }
126
0
  rval.set(JS::ObjectValue(*obj));
127
0
128
0
  do {
129
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
130
0
    JS::Rooted<JS::Value> temp(cx);
131
0
    double const & currentValue = mOriginTime;
132
0
    temp.set(JS_NumberValue(double(currentValue)));
133
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->originTime_id, temp, JSPROP_ENUMERATE)) {
134
0
      return false;
135
0
    }
136
0
    break;
137
0
  } while(false);
138
0
139
0
  return true;
140
0
}
141
142
bool
143
DocumentTimelineOptions::ToJSON(nsAString& aJSON) const
144
0
{
145
0
  AutoJSAPI jsapi;
146
0
  jsapi.Init();
147
0
  JSContext *cx = jsapi.cx();
148
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
149
0
  // because we'll only be creating objects, in ways that have no
150
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
151
0
  // which likewise guarantees no side-effects for the sorts of
152
0
  // things we will pass it.
153
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
154
0
  JS::Rooted<JS::Value> val(cx);
155
0
  if (!ToObjectInternal(cx, &val)) {
156
0
    return false;
157
0
  }
158
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
159
0
  return StringifyToJSON(cx, obj, aJSON);
160
0
}
161
162
void
163
DocumentTimelineOptions::TraceDictionary(JSTracer* trc)
164
0
{
165
0
}
166
167
DocumentTimelineOptions&
168
DocumentTimelineOptions::operator=(const DocumentTimelineOptions& aOther)
169
0
{
170
0
  DictionaryBase::operator=(aOther);
171
0
  mOriginTime = aOther.mOriginTime;
172
0
  return *this;
173
0
}
174
175
namespace binding_detail {
176
} // namespace binding_detail
177
178
179
namespace DocumentTimeline_Binding {
180
181
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<AnimationTimeline_Binding::NativeType>::value,
182
              "Can't inherit from an interface with a different ownership model.");
183
184
static bool
185
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
186
0
{
187
0
  mozilla::dom::DocumentTimeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DocumentTimeline>(obj);
188
0
  // We don't want to preserve if we don't have a wrapper, and we
189
0
  // obviously can't preserve if we're not initialized.
190
0
  if (self && self->GetWrapperPreserveColor()) {
191
0
    PreserveWrapper(self);
192
0
  }
193
0
  return true;
194
0
}
195
196
static void
197
_finalize(js::FreeOp* fop, JSObject* obj)
198
0
{
199
0
  mozilla::dom::DocumentTimeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DocumentTimeline>(obj);
200
0
  if (self) {
201
0
    ClearWrapper(self, self, obj);
202
0
    AddForDeferredFinalization<mozilla::dom::DocumentTimeline>(self);
203
0
  }
204
0
}
205
206
static size_t
207
_objectMoved(JSObject* obj, JSObject* old)
208
0
{
209
0
  mozilla::dom::DocumentTimeline* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::DocumentTimeline>(obj);
210
0
  if (self) {
211
0
    UpdateWrapper(self, self, obj, old);
212
0
  }
213
0
214
0
  return 0;
215
0
}
216
217
static bool
218
_constructor(JSContext* cx, unsigned argc, JS::Value* vp)
219
0
{
220
0
  AUTO_PROFILER_LABEL_FAST("DocumentTimeline constructor", DOM, cx);
221
0
222
0
  JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
223
0
  JS::Rooted<JSObject*> obj(cx, &args.callee());
224
0
  if (!args.isConstructing()) {
225
0
    // XXXbz wish I could get the name from the callee instead of
226
0
    // Adding more relocations
227
0
    return ThrowConstructorWithoutNew(cx, "DocumentTimeline");
228
0
  }
229
0
230
0
  JS::Rooted<JSObject*> desiredProto(cx);
231
0
  if (!GetDesiredProto(cx, args, &desiredProto)) {
232
0
    return false;
233
0
  }
234
0
235
0
  GlobalObject global(cx, obj);
236
0
  if (global.Failed()) {
237
0
    return false;
238
0
  }
239
0
240
0
  bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
241
0
  binding_detail::FastDocumentTimelineOptions arg0;
242
0
  if (!arg0.Init(cx, (args.hasDefined(0)) ? args[0] : JS::NullHandleValue,  "Argument 1 of DocumentTimeline.constructor", false)) {
243
0
    return false;
244
0
  }
245
0
  Maybe<JSAutoRealm> ar;
246
0
  if (objIsXray) {
247
0
    obj = js::CheckedUnwrap(obj);
248
0
    if (!obj) {
249
0
      return false;
250
0
    }
251
0
    ar.emplace(cx, obj);
252
0
    if (!JS_WrapObject(cx, &desiredProto)) {
253
0
      return false;
254
0
    }
255
0
  }
256
0
  FastErrorResult rv;
257
0
  auto result(StrongOrRawPtr<mozilla::dom::DocumentTimeline>(mozilla::dom::DocumentTimeline::Constructor(global, Constify(arg0), rv)));
258
0
  if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
259
0
    return false;
260
0
  }
261
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
262
0
  static_assert(!IsPointer<decltype(result)>::value,
263
0
                "NewObject implies that we need to keep the object alive with a strong reference.");
264
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
265
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
266
0
    return false;
267
0
  }
268
0
  return true;
269
0
}
270
271
static const js::ClassOps sInterfaceObjectClassOps = {
272
    nullptr,               /* addProperty */
273
    nullptr,               /* delProperty */
274
    nullptr,               /* enumerate */
275
    nullptr,               /* newEnumerate */
276
    nullptr,               /* resolve */
277
    nullptr,               /* mayResolve */
278
    nullptr,               /* finalize */
279
    _constructor, /* call */
280
    nullptr,               /* hasInstance */
281
    _constructor, /* construct */
282
    nullptr,               /* trace */
283
};
284
285
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
286
  {
287
    "Function",
288
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
289
    &sInterfaceObjectClassOps,
290
    JS_NULL_CLASS_SPEC,
291
    JS_NULL_CLASS_EXT,
292
    &sInterfaceObjectClassObjectOps
293
  },
294
  eInterface,
295
  true,
296
  prototypes::id::DocumentTimeline,
297
  PrototypeTraits<prototypes::id::DocumentTimeline>::Depth,
298
  sNativePropertyHooks,
299
  "function DocumentTimeline() {\n    [native code]\n}",
300
  AnimationTimeline_Binding::GetConstructorObject
301
};
302
303
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
304
  {
305
    "DocumentTimelinePrototype",
306
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
307
    JS_NULL_CLASS_OPS,
308
    JS_NULL_CLASS_SPEC,
309
    JS_NULL_CLASS_EXT,
310
    JS_NULL_OBJECT_OPS
311
  },
312
  eInterfacePrototype,
313
  false,
314
  prototypes::id::DocumentTimeline,
315
  PrototypeTraits<prototypes::id::DocumentTimeline>::Depth,
316
  sNativePropertyHooks,
317
  "[object DocumentTimelinePrototype]",
318
  AnimationTimeline_Binding::GetProtoObject
319
};
320
321
bool
322
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
323
0
{
324
0
  return nsDocument::AreWebAnimationsTimelinesEnabled(aCx, aObj);
325
0
}
326
327
static const js::ClassOps sClassOps = {
328
  _addProperty, /* addProperty */
329
  nullptr,               /* delProperty */
330
  nullptr,               /* enumerate */
331
  nullptr, /* newEnumerate */
332
  nullptr, /* resolve */
333
  nullptr, /* mayResolve */
334
  _finalize, /* finalize */
335
  nullptr, /* call */
336
  nullptr,               /* hasInstance */
337
  nullptr,               /* construct */
338
  nullptr, /* trace */
339
};
340
341
static const js::ClassExtension sClassExtension = {
342
  nullptr, /* weakmapKeyDelegateOp */
343
  _objectMoved /* objectMovedOp */
344
};
345
346
static const DOMJSClass sClass = {
347
  { "DocumentTimeline",
348
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
349
    &sClassOps,
350
    JS_NULL_CLASS_SPEC,
351
    &sClassExtension,
352
    JS_NULL_OBJECT_OPS
353
  },
354
  { prototypes::id::AnimationTimeline, prototypes::id::DocumentTimeline, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
355
  IsBaseOf<nsISupports, mozilla::dom::DocumentTimeline >::value,
356
  sNativePropertyHooks,
357
  FindAssociatedGlobalForNative<mozilla::dom::DocumentTimeline>::Get,
358
  GetProtoObjectHandle,
359
  GetCCParticipant<mozilla::dom::DocumentTimeline>::Get()
360
};
361
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
362
              "Must have the right minimal number of reserved slots.");
363
static_assert(1 >= 1,
364
              "Must have enough reserved slots.");
365
366
const JSClass*
367
GetJSClass()
368
0
{
369
0
  return sClass.ToJSClass();
370
0
}
371
372
bool
373
Wrap(JSContext* aCx, mozilla::dom::DocumentTimeline* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
374
0
{
375
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::DocumentTimeline>::value,
376
0
                "Shouldn't have wrappercached things that are not refcounted.");
377
0
  MOZ_ASSERT(static_cast<mozilla::dom::DocumentTimeline*>(aObject) ==
378
0
             reinterpret_cast<mozilla::dom::DocumentTimeline*>(aObject),
379
0
             "Multiple inheritance for mozilla::dom::DocumentTimeline is broken.");
380
0
  MOZ_ASSERT(static_cast<mozilla::dom::AnimationTimeline*>(aObject) ==
381
0
             reinterpret_cast<mozilla::dom::AnimationTimeline*>(aObject),
382
0
             "Multiple inheritance for mozilla::dom::AnimationTimeline is broken.");
383
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
384
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
385
0
  MOZ_ASSERT(!aCache->GetWrapper(),
386
0
             "You should probably not be using Wrap() directly; use "
387
0
             "GetOrCreateDOMReflector instead");
388
0
389
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
390
0
             "nsISupports must be on our primary inheritance chain");
391
0
392
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
393
0
  if (!global) {
394
0
    return false;
395
0
  }
396
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
397
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
398
0
399
0
  // That might have ended up wrapping us already, due to the wonders
400
0
  // of XBL.  Check for that, and bail out as needed.
401
0
  aReflector.set(aCache->GetWrapper());
402
0
  if (aReflector) {
403
#ifdef DEBUG
404
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
405
#endif // DEBUG
406
    return true;
407
0
  }
408
0
409
0
  JSAutoRealm ar(aCx, global);
410
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
411
0
  if (!canonicalProto) {
412
0
    return false;
413
0
  }
414
0
  JS::Rooted<JSObject*> proto(aCx);
415
0
  if (aGivenProto) {
416
0
    proto = aGivenProto;
417
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
418
0
    // coming in, we changed compartments to that of "parent" so may need
419
0
    // to wrap the proto here.
420
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
421
0
      if (!JS_WrapObject(aCx, &proto)) {
422
0
        return false;
423
0
      }
424
0
    }
425
0
  } else {
426
0
    proto = canonicalProto;
427
0
  }
428
0
429
0
  BindingJSObjectCreator<mozilla::dom::DocumentTimeline> creator(aCx);
430
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
431
0
  if (!aReflector) {
432
0
    return false;
433
0
  }
434
0
435
0
  aCache->SetWrapper(aReflector);
436
0
  creator.InitializationSucceeded();
437
0
438
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
439
0
             aCache->GetWrapperPreserveColor() == aReflector);
440
0
  // If proto != canonicalProto, we have to preserve our wrapper;
441
0
  // otherwise we won't be able to properly recreate it later, since
442
0
  // we won't know what proto to use.  Note that we don't check
443
0
  // aGivenProto here, since it's entirely possible (and even
444
0
  // somewhat common) to have a non-null aGivenProto which is the
445
0
  // same as canonicalProto.
446
0
  if (proto != canonicalProto) {
447
0
    PreserveWrapper(aObject);
448
0
  }
449
0
450
0
  return true;
451
0
}
452
453
const NativePropertyHooks sNativePropertyHooks[] = { {
454
  nullptr,
455
  nullptr,
456
  nullptr,
457
  { nullptr, nullptr },
458
  prototypes::id::DocumentTimeline,
459
  constructors::id::DocumentTimeline,
460
  AnimationTimeline_Binding::sNativePropertyHooks,
461
  &DefaultXrayExpandoObjectClass
462
} };
463
464
void
465
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
466
0
{
467
0
  JS::Handle<JSObject*> parentProto(AnimationTimeline_Binding::GetProtoObjectHandle(aCx));
468
0
  if (!parentProto) {
469
0
    return;
470
0
  }
471
0
472
0
  JS::Handle<JSObject*> constructorProto(AnimationTimeline_Binding::GetConstructorObjectHandle(aCx));
473
0
  if (!constructorProto) {
474
0
    return;
475
0
  }
476
0
477
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::DocumentTimeline);
478
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::DocumentTimeline);
479
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
480
0
                              &sPrototypeClass.mBase, protoCache,
481
0
                              nullptr,
482
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
483
0
                              interfaceCache,
484
0
                              nullptr,
485
0
                              nullptr,
486
0
                              "DocumentTimeline", aDefineOnGlobal,
487
0
                              nullptr,
488
0
                              false);
489
0
}
490
491
JSObject*
492
GetConstructorObject(JSContext* aCx)
493
0
{
494
0
  return GetConstructorObjectHandle(aCx);
495
0
}
496
497
} // namespace DocumentTimeline_Binding
498
499
500
501
} // namespace dom
502
} // namespace mozilla