Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/WindowRootBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM WindowRoot.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "EventTargetBinding.h"
4
#include "WindowRootBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMJSClass.h"
9
#include "mozilla/dom/NonRefcountedDOMObject.h"
10
#include "mozilla/dom/XrayExpandoClass.h"
11
#include "nsContentUtils.h"
12
#include "nsWindowRoot.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 WindowRoot_Binding {
22
23
static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTarget_Binding::NativeType>::value,
24
              "Can't inherit from an interface with a different ownership model.");
25
26
static bool
27
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
28
0
{
29
0
  nsWindowRoot* self = UnwrapPossiblyNotInitializedDOMObject<nsWindowRoot>(obj);
30
0
  // We don't want to preserve if we don't have a wrapper, and we
31
0
  // obviously can't preserve if we're not initialized.
32
0
  if (self && self->GetWrapperPreserveColor()) {
33
0
    PreserveWrapper(self);
34
0
  }
35
0
  return true;
36
0
}
37
38
static void
39
_finalize(js::FreeOp* fop, JSObject* obj)
40
0
{
41
0
  nsWindowRoot* self = UnwrapPossiblyNotInitializedDOMObject<nsWindowRoot>(obj);
42
0
  if (self) {
43
0
    ClearWrapper(self, self, obj);
44
0
    AddForDeferredFinalization<nsWindowRoot>(self);
45
0
  }
46
0
}
47
48
static size_t
49
_objectMoved(JSObject* obj, JSObject* old)
50
0
{
51
0
  nsWindowRoot* self = UnwrapPossiblyNotInitializedDOMObject<nsWindowRoot>(obj);
52
0
  if (self) {
53
0
    UpdateWrapper(self, self, obj, old);
54
0
  }
55
0
56
0
  return 0;
57
0
}
58
59
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
60
  {
61
    "Function",
62
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
63
    &sBoringInterfaceObjectClassClassOps,
64
    JS_NULL_CLASS_SPEC,
65
    JS_NULL_CLASS_EXT,
66
    &sInterfaceObjectClassObjectOps
67
  },
68
  eInterface,
69
  true,
70
  prototypes::id::WindowRoot,
71
  PrototypeTraits<prototypes::id::WindowRoot>::Depth,
72
  sNativePropertyHooks,
73
  "function WindowRoot() {\n    [native code]\n}",
74
  EventTarget_Binding::GetConstructorObject
75
};
76
77
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
78
  {
79
    "WindowRootPrototype",
80
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
81
    JS_NULL_CLASS_OPS,
82
    JS_NULL_CLASS_SPEC,
83
    JS_NULL_CLASS_EXT,
84
    JS_NULL_OBJECT_OPS
85
  },
86
  eInterfacePrototype,
87
  false,
88
  prototypes::id::WindowRoot,
89
  PrototypeTraits<prototypes::id::WindowRoot>::Depth,
90
  sNativePropertyHooks,
91
  "[object WindowRootPrototype]",
92
  EventTarget_Binding::GetProtoObject
93
};
94
95
bool
96
ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
97
0
{
98
0
  return nsContentUtils::ThreadsafeIsSystemCaller(aCx);
99
0
}
100
101
static const js::ClassOps sClassOps = {
102
  _addProperty, /* addProperty */
103
  nullptr,               /* delProperty */
104
  nullptr,               /* enumerate */
105
  nullptr, /* newEnumerate */
106
  nullptr, /* resolve */
107
  nullptr, /* mayResolve */
108
  _finalize, /* finalize */
109
  nullptr, /* call */
110
  nullptr,               /* hasInstance */
111
  nullptr,               /* construct */
112
  nullptr, /* trace */
113
};
114
115
static const js::ClassExtension sClassExtension = {
116
  nullptr, /* weakmapKeyDelegateOp */
117
  _objectMoved /* objectMovedOp */
118
};
119
120
static const DOMJSClass sClass = {
121
  { "WindowRoot",
122
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
123
    &sClassOps,
124
    JS_NULL_CLASS_SPEC,
125
    &sClassExtension,
126
    JS_NULL_OBJECT_OPS
127
  },
128
  { prototypes::id::EventTarget, prototypes::id::WindowRoot, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
129
  IsBaseOf<nsISupports, nsWindowRoot >::value,
130
  sNativePropertyHooks,
131
  FindAssociatedGlobalForNative<nsWindowRoot>::Get,
132
  GetProtoObjectHandle,
133
  GetCCParticipant<nsWindowRoot>::Get()
134
};
135
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
136
              "Must have the right minimal number of reserved slots.");
137
static_assert(1 >= 1,
138
              "Must have enough reserved slots.");
139
140
const JSClass*
141
GetJSClass()
142
0
{
143
0
  return sClass.ToJSClass();
144
0
}
145
146
bool
147
Wrap(JSContext* aCx, nsWindowRoot* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
148
0
{
149
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, nsWindowRoot>::value,
150
0
                "Shouldn't have wrappercached things that are not refcounted.");
151
0
  MOZ_ASSERT(static_cast<nsWindowRoot*>(aObject) ==
152
0
             reinterpret_cast<nsWindowRoot*>(aObject),
153
0
             "Multiple inheritance for nsWindowRoot is broken.");
154
0
  MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
155
0
             reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
156
0
             "Multiple inheritance for mozilla::dom::EventTarget is broken.");
157
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
158
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
159
0
  MOZ_ASSERT(!aCache->GetWrapper(),
160
0
             "You should probably not be using Wrap() directly; use "
161
0
             "GetOrCreateDOMReflector instead");
162
0
163
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
164
0
             "nsISupports must be on our primary inheritance chain");
165
0
166
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
167
0
  if (!global) {
168
0
    return false;
169
0
  }
170
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
171
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
172
0
173
0
  // That might have ended up wrapping us already, due to the wonders
174
0
  // of XBL.  Check for that, and bail out as needed.
175
0
  aReflector.set(aCache->GetWrapper());
176
0
  if (aReflector) {
177
#ifdef DEBUG
178
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
179
#endif // DEBUG
180
    return true;
181
0
  }
182
0
183
0
  JSAutoRealm ar(aCx, global);
184
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
185
0
  if (!canonicalProto) {
186
0
    return false;
187
0
  }
188
0
  JS::Rooted<JSObject*> proto(aCx);
189
0
  if (aGivenProto) {
190
0
    proto = aGivenProto;
191
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
192
0
    // coming in, we changed compartments to that of "parent" so may need
193
0
    // to wrap the proto here.
194
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
195
0
      if (!JS_WrapObject(aCx, &proto)) {
196
0
        return false;
197
0
      }
198
0
    }
199
0
  } else {
200
0
    proto = canonicalProto;
201
0
  }
202
0
203
0
  BindingJSObjectCreator<nsWindowRoot> creator(aCx);
204
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
205
0
  if (!aReflector) {
206
0
    return false;
207
0
  }
208
0
209
0
  aCache->SetWrapper(aReflector);
210
0
  creator.InitializationSucceeded();
211
0
212
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
213
0
             aCache->GetWrapperPreserveColor() == aReflector);
214
0
  // If proto != canonicalProto, we have to preserve our wrapper;
215
0
  // otherwise we won't be able to properly recreate it later, since
216
0
  // we won't know what proto to use.  Note that we don't check
217
0
  // aGivenProto here, since it's entirely possible (and even
218
0
  // somewhat common) to have a non-null aGivenProto which is the
219
0
  // same as canonicalProto.
220
0
  if (proto != canonicalProto) {
221
0
    PreserveWrapper(aObject);
222
0
  }
223
0
224
0
  return true;
225
0
}
226
227
const NativePropertyHooks sNativePropertyHooks[] = { {
228
  nullptr,
229
  nullptr,
230
  nullptr,
231
  { nullptr, nullptr },
232
  prototypes::id::WindowRoot,
233
  constructors::id::WindowRoot,
234
  EventTarget_Binding::sNativePropertyHooks,
235
  &DefaultXrayExpandoObjectClass
236
} };
237
238
void
239
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
240
0
{
241
0
  JS::Handle<JSObject*> parentProto(EventTarget_Binding::GetProtoObjectHandle(aCx));
242
0
  if (!parentProto) {
243
0
    return;
244
0
  }
245
0
246
0
  JS::Handle<JSObject*> constructorProto(EventTarget_Binding::GetConstructorObjectHandle(aCx));
247
0
  if (!constructorProto) {
248
0
    return;
249
0
  }
250
0
251
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::WindowRoot);
252
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::WindowRoot);
253
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
254
0
                              &sPrototypeClass.mBase, protoCache,
255
0
                              nullptr,
256
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
257
0
                              interfaceCache,
258
0
                              nullptr,
259
0
                              nullptr,
260
0
                              "WindowRoot", aDefineOnGlobal,
261
0
                              nullptr,
262
0
                              false);
263
0
}
264
265
JSObject*
266
GetConstructorObject(JSContext* aCx)
267
0
{
268
0
  return GetConstructorObjectHandle(aCx);
269
0
}
270
271
} // namespace WindowRoot_Binding
272
273
274
275
} // namespace dom
276
} // namespace mozilla