Coverage Report

Created: 2018-09-25 14:53

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