Coverage Report

Created: 2018-09-25 14:53

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