Coverage Report

Created: 2018-09-25 14:53

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