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