Coverage Report

Created: 2018-09-25 14:53

/work/obj-fuzz/dom/bindings/FileSystemBinding.cpp
Line
Count
Source (jump to first uncovered line)
1
/* THIS FILE IS AUTOGENERATED FROM FileSystem.webidl BY Codegen.py - DO NOT EDIT */
2
3
#include "AtomList.h"
4
#include "FileSystemBinding.h"
5
#include "WrapperFactory.h"
6
#include "mozilla/OwningNonNull.h"
7
#include "mozilla/dom/BindingUtils.h"
8
#include "mozilla/dom/DOMException.h"
9
#include "mozilla/dom/DOMJSClass.h"
10
#include "mozilla/dom/FileSystem.h"
11
#include "mozilla/dom/FileSystemDirectoryEntry.h"
12
#include "mozilla/dom/FileSystemEntry.h"
13
#include "mozilla/dom/NonRefcountedDOMObject.h"
14
#include "mozilla/dom/PrimitiveConversions.h"
15
#include "mozilla/dom/ScriptSettings.h"
16
#include "mozilla/dom/SimpleGlobalObject.h"
17
#include "mozilla/dom/XrayExpandoClass.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
FileSystemFlags::FileSystemFlags()
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
FileSystemFlags::InitIds(JSContext* cx, FileSystemFlagsAtoms* 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->exclusive_id.init(cx, "exclusive") ||
43
0
      !atomsCache->create_id.init(cx, "create")) {
44
0
    return false;
45
0
  }
46
0
  return true;
47
0
}
48
49
bool
50
FileSystemFlags::Init(JSContext* cx, JS::Handle<JS::Value> val, const char* sourceDescription, bool passedToJSImpl)
51
0
{
52
0
  // Passing a null JSContext is OK only if we're initing from null,
53
0
  // Since in that case we will not have to do any property gets
54
0
  // Also evaluate isNullOrUndefined in order to avoid false-positive
55
0
  // checkers by static analysis tools
56
0
  MOZ_ASSERT_IF(!cx, val.isNull() && val.isNullOrUndefined());
57
0
  FileSystemFlagsAtoms* atomsCache = nullptr;
58
0
  if (cx) {
59
0
    atomsCache = GetAtomCache<FileSystemFlagsAtoms>(cx);
60
0
    if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
61
0
      return false;
62
0
    }
63
0
  }
64
0
65
0
  if (!IsConvertibleToDictionary(val)) {
66
0
    return ThrowErrorMessage(cx, MSG_NOT_DICTIONARY, sourceDescription);
67
0
  }
68
0
69
0
  bool isNull = val.isNullOrUndefined();
70
0
  // We only need these if !isNull, in which case we have |cx|.
71
0
  Maybe<JS::Rooted<JSObject *> > object;
72
0
  Maybe<JS::Rooted<JS::Value> > temp;
73
0
  if (!isNull) {
74
0
    MOZ_ASSERT(cx);
75
0
    object.emplace(cx, &val.toObject());
76
0
    temp.emplace(cx);
77
0
  }
78
0
  if (!isNull) {
79
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->create_id, temp.ptr())) {
80
0
      return false;
81
0
    }
82
0
  }
83
0
  if (!isNull && !temp->isUndefined()) {
84
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mCreate)) {
85
0
      return false;
86
0
    }
87
0
  } else {
88
0
    mCreate = false;
89
0
  }
90
0
  mIsAnyMemberPresent = true;
91
0
92
0
  if (!isNull) {
93
0
    if (!JS_GetPropertyById(cx, *object, atomsCache->exclusive_id, temp.ptr())) {
94
0
      return false;
95
0
    }
96
0
  }
97
0
  if (!isNull && !temp->isUndefined()) {
98
0
    if (!ValueToPrimitive<bool, eDefault>(cx, temp.ref(), &mExclusive)) {
99
0
      return false;
100
0
    }
101
0
  } else {
102
0
    mExclusive = false;
103
0
  }
104
0
  mIsAnyMemberPresent = true;
105
0
  return true;
106
0
}
107
108
bool
109
FileSystemFlags::Init(const nsAString& aJSON)
110
0
{
111
0
  AutoJSAPI jsapi;
112
0
  JSObject* cleanGlobal = SimpleGlobalObject::Create(SimpleGlobalObject::GlobalType::BindingDetail);
113
0
  if (!cleanGlobal) {
114
0
    return false;
115
0
  }
116
0
  if (!jsapi.Init(cleanGlobal)) {
117
0
    return false;
118
0
  }
119
0
  JSContext* cx = jsapi.cx();
120
0
  JS::Rooted<JS::Value> json(cx);
121
0
  bool ok = ParseJSON(cx, aJSON, &json);
122
0
  NS_ENSURE_TRUE(ok, false);
123
0
  return Init(cx, json);
124
0
}
125
126
bool
127
FileSystemFlags::ToObjectInternal(JSContext* cx, JS::MutableHandle<JS::Value> rval) const
128
0
{
129
0
  FileSystemFlagsAtoms* atomsCache = GetAtomCache<FileSystemFlagsAtoms>(cx);
130
0
  if (!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) {
131
0
    return false;
132
0
  }
133
0
134
0
  JS::Rooted<JSObject*> obj(cx, JS_NewPlainObject(cx));
135
0
  if (!obj) {
136
0
    return false;
137
0
  }
138
0
  rval.set(JS::ObjectValue(*obj));
139
0
140
0
  do {
141
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
142
0
    JS::Rooted<JS::Value> temp(cx);
143
0
    bool const & currentValue = mCreate;
144
0
    temp.setBoolean(currentValue);
145
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->create_id, temp, JSPROP_ENUMERATE)) {
146
0
      return false;
147
0
    }
148
0
    break;
149
0
  } while(false);
150
0
151
0
  do {
152
0
    // block for our 'break' successCode and scope for 'temp' and 'currentValue'
153
0
    JS::Rooted<JS::Value> temp(cx);
154
0
    bool const & currentValue = mExclusive;
155
0
    temp.setBoolean(currentValue);
156
0
    if (!JS_DefinePropertyById(cx, obj, atomsCache->exclusive_id, temp, JSPROP_ENUMERATE)) {
157
0
      return false;
158
0
    }
159
0
    break;
160
0
  } while(false);
161
0
162
0
  return true;
163
0
}
164
165
bool
166
FileSystemFlags::ToJSON(nsAString& aJSON) const
167
0
{
168
0
  AutoJSAPI jsapi;
169
0
  jsapi.Init();
170
0
  JSContext *cx = jsapi.cx();
171
0
  // It's safe to use UnprivilegedJunkScopeOrWorkerGlobal here
172
0
  // because we'll only be creating objects, in ways that have no
173
0
  // side-effects, followed by a call to JS::ToJSONMaybeSafely,
174
0
  // which likewise guarantees no side-effects for the sorts of
175
0
  // things we will pass it.
176
0
  JSAutoRealm ar(cx, UnprivilegedJunkScopeOrWorkerGlobal());
177
0
  JS::Rooted<JS::Value> val(cx);
178
0
  if (!ToObjectInternal(cx, &val)) {
179
0
    return false;
180
0
  }
181
0
  JS::Rooted<JSObject*> obj(cx, &val.toObject());
182
0
  return StringifyToJSON(cx, obj, aJSON);
183
0
}
184
185
void
186
FileSystemFlags::TraceDictionary(JSTracer* trc)
187
0
{
188
0
}
189
190
FileSystemFlags&
191
FileSystemFlags::operator=(const FileSystemFlags& aOther)
192
0
{
193
0
  DictionaryBase::operator=(aOther);
194
0
  mCreate = aOther.mCreate;
195
0
  mExclusive = aOther.mExclusive;
196
0
  return *this;
197
0
}
198
199
namespace binding_detail {
200
} // namespace binding_detail
201
202
203
namespace FileSystem_Binding {
204
205
MOZ_CAN_RUN_SCRIPT static bool
206
get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystem* self, JSJitGetterCallArgs args)
207
0
{
208
0
  AUTO_PROFILER_LABEL_FAST("get FileSystem.name", DOM, cx);
209
0
210
0
  DOMString result;
211
0
  self->GetName(result);
212
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
213
0
  if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
214
0
    return false;
215
0
  }
216
0
  return true;
217
0
}
218
219
static const JSJitInfo name_getterinfo = {
220
  { (JSJitGetterOp)get_name },
221
  { prototypes::id::FileSystem },
222
  { PrototypeTraits<prototypes::id::FileSystem>::Depth },
223
  JSJitInfo::Getter,
224
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
225
  JSVAL_TYPE_STRING,  /* returnType.  Not relevant for setters. */
226
  false,  /* isInfallible. False in setters. */
227
  false,  /* isMovable.  Not relevant for setters. */
228
  false, /* isEliminatable.  Not relevant for setters. */
229
  false, /* isAlwaysInSlot.  Only relevant for getters. */
230
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
231
  false,  /* isTypedMethod.  Only relevant for methods. */
232
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
233
};
234
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
235
static_assert(0 < 1, "There is no slot for us");
236
237
MOZ_CAN_RUN_SCRIPT static bool
238
get_root(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystem* self, JSJitGetterCallArgs args)
239
0
{
240
0
  AUTO_PROFILER_LABEL_FAST("get FileSystem.root", DOM, cx);
241
0
242
0
  auto result(StrongOrRawPtr<mozilla::dom::FileSystemDirectoryEntry>(self->Root()));
243
0
  MOZ_ASSERT(!JS_IsExceptionPending(cx));
244
0
  if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
245
0
    MOZ_ASSERT(JS_IsExceptionPending(cx));
246
0
    return false;
247
0
  }
248
0
  return true;
249
0
}
250
251
static const JSJitInfo root_getterinfo = {
252
  { (JSJitGetterOp)get_root },
253
  { prototypes::id::FileSystem },
254
  { PrototypeTraits<prototypes::id::FileSystem>::Depth },
255
  JSJitInfo::Getter,
256
  JSJitInfo::AliasEverything, /* aliasSet.  Not relevant for setters. */
257
  JSVAL_TYPE_OBJECT,  /* returnType.  Not relevant for setters. */
258
  false,  /* isInfallible. False in setters. */
259
  false,  /* isMovable.  Not relevant for setters. */
260
  false, /* isEliminatable.  Not relevant for setters. */
261
  false, /* isAlwaysInSlot.  Only relevant for getters. */
262
  false, /* isLazilyCachedInSlot.  Only relevant for getters. */
263
  false,  /* isTypedMethod.  Only relevant for methods. */
264
  0   /* Reserved slot index, if we're stored in a slot, else 0. */
265
};
266
static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
267
static_assert(0 < 1, "There is no slot for us");
268
269
static bool
270
_addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
271
0
{
272
0
  mozilla::dom::FileSystem* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileSystem>(obj);
273
0
  // We don't want to preserve if we don't have a wrapper, and we
274
0
  // obviously can't preserve if we're not initialized.
275
0
  if (self && self->GetWrapperPreserveColor()) {
276
0
    PreserveWrapper(self);
277
0
  }
278
0
  return true;
279
0
}
280
281
static void
282
_finalize(js::FreeOp* fop, JSObject* obj)
283
0
{
284
0
  mozilla::dom::FileSystem* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileSystem>(obj);
285
0
  if (self) {
286
0
    ClearWrapper(self, self, obj);
287
0
    AddForDeferredFinalization<mozilla::dom::FileSystem>(self);
288
0
  }
289
0
}
290
291
static size_t
292
_objectMoved(JSObject* obj, JSObject* old)
293
0
{
294
0
  mozilla::dom::FileSystem* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileSystem>(obj);
295
0
  if (self) {
296
0
    UpdateWrapper(self, self, obj, old);
297
0
  }
298
0
299
0
  return 0;
300
0
}
301
302
// We deliberately use brace-elision to make Visual Studio produce better initalization code.
303
#if defined(__clang__)
304
#pragma clang diagnostic push
305
#pragma clang diagnostic ignored "-Wmissing-braces"
306
#endif
307
static const JSPropertySpec sAttributes_specs[] = {
308
  { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr },
309
  { "root", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &root_getterinfo, nullptr, nullptr },
310
  { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
311
};
312
#if defined(__clang__)
313
#pragma clang diagnostic pop
314
#endif
315
316
317
static const Prefable<const JSPropertySpec> sAttributes[] = {
318
  { nullptr, &sAttributes_specs[0] },
319
  { nullptr, nullptr }
320
};
321
322
static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
323
    "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
324
static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
325
    "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
326
327
328
static uint16_t sNativeProperties_sortedPropertyIndices[2];
329
static PropertyInfo sNativeProperties_propertyInfos[2];
330
331
static const NativePropertiesN<1> sNativeProperties = {
332
  false, 0,
333
  false, 0,
334
  false, 0,
335
  true,  0 /* sAttributes */,
336
  false, 0,
337
  false, 0,
338
  false, 0,
339
  -1,
340
  2,
341
  sNativeProperties_sortedPropertyIndices,
342
  {
343
    { sAttributes, &sNativeProperties_propertyInfos[0] }
344
  }
345
};
346
static_assert(2 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
347
    "We have a property info count that is oversized");
348
349
static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
350
  {
351
    "Function",
352
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
353
    &sBoringInterfaceObjectClassClassOps,
354
    JS_NULL_CLASS_SPEC,
355
    JS_NULL_CLASS_EXT,
356
    &sInterfaceObjectClassObjectOps
357
  },
358
  eInterface,
359
  true,
360
  prototypes::id::FileSystem,
361
  PrototypeTraits<prototypes::id::FileSystem>::Depth,
362
  sNativePropertyHooks,
363
  "function FileSystem() {\n    [native code]\n}",
364
  JS::GetRealmFunctionPrototype
365
};
366
367
static const DOMIfaceAndProtoJSClass sPrototypeClass = {
368
  {
369
    "FileSystemPrototype",
370
    JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
371
    JS_NULL_CLASS_OPS,
372
    JS_NULL_CLASS_SPEC,
373
    JS_NULL_CLASS_EXT,
374
    JS_NULL_OBJECT_OPS
375
  },
376
  eInterfacePrototype,
377
  false,
378
  prototypes::id::FileSystem,
379
  PrototypeTraits<prototypes::id::FileSystem>::Depth,
380
  sNativePropertyHooks,
381
  "[object FileSystemPrototype]",
382
  JS::GetRealmObjectPrototype
383
};
384
385
static const js::ClassOps sClassOps = {
386
  _addProperty, /* addProperty */
387
  nullptr,               /* delProperty */
388
  nullptr,               /* enumerate */
389
  nullptr, /* newEnumerate */
390
  nullptr, /* resolve */
391
  nullptr, /* mayResolve */
392
  _finalize, /* finalize */
393
  nullptr, /* call */
394
  nullptr,               /* hasInstance */
395
  nullptr,               /* construct */
396
  nullptr, /* trace */
397
};
398
399
static const js::ClassExtension sClassExtension = {
400
  nullptr, /* weakmapKeyDelegateOp */
401
  _objectMoved /* objectMovedOp */
402
};
403
404
static const DOMJSClass sClass = {
405
  { "FileSystem",
406
    JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
407
    &sClassOps,
408
    JS_NULL_CLASS_SPEC,
409
    &sClassExtension,
410
    JS_NULL_OBJECT_OPS
411
  },
412
  { prototypes::id::FileSystem, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
413
  IsBaseOf<nsISupports, mozilla::dom::FileSystem >::value,
414
  sNativePropertyHooks,
415
  FindAssociatedGlobalForNative<mozilla::dom::FileSystem>::Get,
416
  GetProtoObjectHandle,
417
  GetCCParticipant<mozilla::dom::FileSystem>::Get()
418
};
419
static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
420
              "Must have the right minimal number of reserved slots.");
421
static_assert(1 >= 1,
422
              "Must have enough reserved slots.");
423
424
const JSClass*
425
GetJSClass()
426
0
{
427
0
  return sClass.ToJSClass();
428
0
}
429
430
bool
431
Wrap(JSContext* aCx, mozilla::dom::FileSystem* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
432
0
{
433
0
  static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::FileSystem>::value,
434
0
                "Shouldn't have wrappercached things that are not refcounted.");
435
0
  MOZ_ASSERT(static_cast<mozilla::dom::FileSystem*>(aObject) ==
436
0
             reinterpret_cast<mozilla::dom::FileSystem*>(aObject),
437
0
             "Multiple inheritance for mozilla::dom::FileSystem is broken.");
438
0
  MOZ_ASSERT(ToSupportsIsCorrect(aObject));
439
0
  MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
440
0
  MOZ_ASSERT(!aCache->GetWrapper(),
441
0
             "You should probably not be using Wrap() directly; use "
442
0
             "GetOrCreateDOMReflector instead");
443
0
444
0
  MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
445
0
             "nsISupports must be on our primary inheritance chain");
446
0
447
0
  JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
448
0
  if (!global) {
449
0
    return false;
450
0
  }
451
0
  MOZ_ASSERT(JS_IsGlobalObject(global));
452
0
  MOZ_ASSERT(JS::ObjectIsNotGray(global));
453
0
454
0
  // That might have ended up wrapping us already, due to the wonders
455
0
  // of XBL.  Check for that, and bail out as needed.
456
0
  aReflector.set(aCache->GetWrapper());
457
0
  if (aReflector) {
458
#ifdef DEBUG
459
    AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
460
#endif // DEBUG
461
    return true;
462
0
  }
463
0
464
0
  JSAutoRealm ar(aCx, global);
465
0
  JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
466
0
  if (!canonicalProto) {
467
0
    return false;
468
0
  }
469
0
  JS::Rooted<JSObject*> proto(aCx);
470
0
  if (aGivenProto) {
471
0
    proto = aGivenProto;
472
0
    // Unfortunately, while aGivenProto was in the compartment of aCx
473
0
    // coming in, we changed compartments to that of "parent" so may need
474
0
    // to wrap the proto here.
475
0
    if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
476
0
      if (!JS_WrapObject(aCx, &proto)) {
477
0
        return false;
478
0
      }
479
0
    }
480
0
  } else {
481
0
    proto = canonicalProto;
482
0
  }
483
0
484
0
  BindingJSObjectCreator<mozilla::dom::FileSystem> creator(aCx);
485
0
  creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
486
0
  if (!aReflector) {
487
0
    return false;
488
0
  }
489
0
490
0
  aCache->SetWrapper(aReflector);
491
0
  creator.InitializationSucceeded();
492
0
493
0
  MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
494
0
             aCache->GetWrapperPreserveColor() == aReflector);
495
0
  // If proto != canonicalProto, we have to preserve our wrapper;
496
0
  // otherwise we won't be able to properly recreate it later, since
497
0
  // we won't know what proto to use.  Note that we don't check
498
0
  // aGivenProto here, since it's entirely possible (and even
499
0
  // somewhat common) to have a non-null aGivenProto which is the
500
0
  // same as canonicalProto.
501
0
  if (proto != canonicalProto) {
502
0
    PreserveWrapper(aObject);
503
0
  }
504
0
505
0
  return true;
506
0
}
507
508
const NativePropertyHooks sNativePropertyHooks[] = { {
509
  nullptr,
510
  nullptr,
511
  nullptr,
512
  { sNativeProperties.Upcast(), nullptr },
513
  prototypes::id::FileSystem,
514
  constructors::id::FileSystem,
515
  nullptr,
516
  &DefaultXrayExpandoObjectClass
517
} };
518
519
void
520
CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
521
0
{
522
0
  JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
523
0
  if (!parentProto) {
524
0
    return;
525
0
  }
526
0
527
0
  JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
528
0
  if (!constructorProto) {
529
0
    return;
530
0
  }
531
0
532
0
  static bool sIdsInited = false;
533
0
  if (!sIdsInited && NS_IsMainThread()) {
534
0
    if (!InitIds(aCx, sNativeProperties.Upcast())) {
535
0
      return;
536
0
    }
537
0
    sIdsInited = true;
538
0
  }
539
0
540
0
  JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FileSystem);
541
0
  JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FileSystem);
542
0
  dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
543
0
                              &sPrototypeClass.mBase, protoCache,
544
0
                              nullptr,
545
0
                              constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
546
0
                              interfaceCache,
547
0
                              sNativeProperties.Upcast(),
548
0
                              nullptr,
549
0
                              "FileSystem", aDefineOnGlobal,
550
0
                              nullptr,
551
0
                              false);
552
0
}
553
554
JSObject*
555
GetConstructorObject(JSContext* aCx)
556
0
{
557
0
  return GetConstructorObjectHandle(aCx);
558
0
}
559
560
} // namespace FileSystem_Binding
561
562
563
564
void
565
ErrorCallback::HandleEvent(JSContext* cx, JS::Handle<JS::Value> aThisVal, DOMException& err, ErrorResult& aRv)
566
0
{
567
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
568
0
  JS::AutoValueVector argv(cx);
569
0
  if (!argv.resize(1)) {
570
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
571
0
    return;
572
0
  }
573
0
  unsigned argc = 1;
574
0
575
0
  do {
576
0
    if (!GetOrCreateDOMReflector(cx, err, argv[0])) {
577
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
578
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
579
0
      return;
580
0
    }
581
0
    break;
582
0
  } while (false);
583
0
584
0
  bool isCallable = JS::IsCallable(mCallback);
585
0
  JS::Rooted<JS::Value> callable(cx);
586
0
  if (isCallable) {
587
0
    callable = JS::ObjectValue(*mCallback);
588
0
  } else {
589
0
    ErrorCallbackAtoms* atomsCache = GetAtomCache<ErrorCallbackAtoms>(cx);
590
0
    if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
591
0
        !GetCallableProperty(cx, atomsCache->handleEvent_id, &callable)) {
592
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
593
0
      return;
594
0
    }
595
0
  }
596
0
  JS::Rooted<JS::Value> thisValue(cx, isCallable ? aThisVal.get()
597
0
                                                 : JS::ObjectValue(*mCallback));
598
0
  if (!JS::Call(cx, thisValue, callable,
599
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
600
0
    aRv.NoteJSContextException(cx);
601
0
    return;
602
0
  }
603
0
}
604
605
bool
606
ErrorCallback::InitIds(JSContext* cx, ErrorCallbackAtoms* atomsCache)
607
0
{
608
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
609
0
610
0
  // Initialize these in reverse order so that any failure leaves the first one
611
0
  // uninitialized.
612
0
  if (!atomsCache->handleEvent_id.init(cx, "handleEvent")) {
613
0
    return false;
614
0
  }
615
0
  return true;
616
0
}
617
618
619
620
void
621
FileSystemEntryCallback::HandleEvent(JSContext* cx, JS::Handle<JS::Value> aThisVal, FileSystemEntry& entry, ErrorResult& aRv)
622
0
{
623
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
624
0
  JS::AutoValueVector argv(cx);
625
0
  if (!argv.resize(1)) {
626
0
    aRv.Throw(NS_ERROR_OUT_OF_MEMORY);
627
0
    return;
628
0
  }
629
0
  unsigned argc = 1;
630
0
631
0
  do {
632
0
    if (!GetOrCreateDOMReflector(cx, entry, argv[0])) {
633
0
      MOZ_ASSERT(JS_IsExceptionPending(cx));
634
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
635
0
      return;
636
0
    }
637
0
    break;
638
0
  } while (false);
639
0
640
0
  bool isCallable = JS::IsCallable(mCallback);
641
0
  JS::Rooted<JS::Value> callable(cx);
642
0
  if (isCallable) {
643
0
    callable = JS::ObjectValue(*mCallback);
644
0
  } else {
645
0
    FileSystemEntryCallbackAtoms* atomsCache = GetAtomCache<FileSystemEntryCallbackAtoms>(cx);
646
0
    if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
647
0
        !GetCallableProperty(cx, atomsCache->handleEvent_id, &callable)) {
648
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
649
0
      return;
650
0
    }
651
0
  }
652
0
  JS::Rooted<JS::Value> thisValue(cx, isCallable ? aThisVal.get()
653
0
                                                 : JS::ObjectValue(*mCallback));
654
0
  if (!JS::Call(cx, thisValue, callable,
655
0
                JS::HandleValueArray::subarray(argv, 0, argc), &rval)) {
656
0
    aRv.NoteJSContextException(cx);
657
0
    return;
658
0
  }
659
0
}
660
661
bool
662
FileSystemEntryCallback::InitIds(JSContext* cx, FileSystemEntryCallbackAtoms* atomsCache)
663
0
{
664
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
665
0
666
0
  // Initialize these in reverse order so that any failure leaves the first one
667
0
  // uninitialized.
668
0
  if (!atomsCache->handleEvent_id.init(cx, "handleEvent")) {
669
0
    return false;
670
0
  }
671
0
  return true;
672
0
}
673
674
675
676
void
677
VoidCallback::HandleEvent(JSContext* cx, JS::Handle<JS::Value> aThisVal, ErrorResult& aRv)
678
0
{
679
0
  JS::Rooted<JS::Value> rval(cx, JS::UndefinedValue());
680
0
681
0
  bool isCallable = JS::IsCallable(mCallback);
682
0
  JS::Rooted<JS::Value> callable(cx);
683
0
  if (isCallable) {
684
0
    callable = JS::ObjectValue(*mCallback);
685
0
  } else {
686
0
    VoidCallbackAtoms* atomsCache = GetAtomCache<VoidCallbackAtoms>(cx);
687
0
    if ((!*reinterpret_cast<jsid**>(atomsCache) && !InitIds(cx, atomsCache)) ||
688
0
        !GetCallableProperty(cx, atomsCache->handleEvent_id, &callable)) {
689
0
      aRv.Throw(NS_ERROR_UNEXPECTED);
690
0
      return;
691
0
    }
692
0
  }
693
0
  JS::Rooted<JS::Value> thisValue(cx, isCallable ? aThisVal.get()
694
0
                                                 : JS::ObjectValue(*mCallback));
695
0
  if (!JS::Call(cx, thisValue, callable,
696
0
                JS::HandleValueArray::empty(), &rval)) {
697
0
    aRv.NoteJSContextException(cx);
698
0
    return;
699
0
  }
700
0
}
701
702
bool
703
VoidCallback::InitIds(JSContext* cx, VoidCallbackAtoms* atomsCache)
704
0
{
705
0
  MOZ_ASSERT(!*reinterpret_cast<jsid**>(atomsCache));
706
0
707
0
  // Initialize these in reverse order so that any failure leaves the first one
708
0
  // uninitialized.
709
0
  if (!atomsCache->handleEvent_id.init(cx, "handleEvent")) {
710
0
    return false;
711
0
  }
712
0
  return true;
713
0
}
714
715
716
717
namespace binding_detail {
718
} // namespace binding_detail
719
720
721
namespace binding_detail {
722
} // namespace binding_detail
723
724
725
namespace binding_detail {
726
} // namespace binding_detail
727
728
729
} // namespace dom
730
} // namespace mozilla