Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM FileSystemEntry.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "FileSystemBinding.h"
4 : #include "FileSystemEntryBinding.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/FileSystem.h"
10 : #include "mozilla/dom/FileSystemEntry.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/PrimitiveConversions.h"
13 : #include "mozilla/dom/XrayExpandoClass.h"
14 :
15 : namespace mozilla {
16 : namespace dom {
17 :
18 : namespace FileSystemEntryBinding {
19 :
20 : static bool
21 0 : get_isFile(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystemEntry* self, JSJitGetterCallArgs args)
22 : {
23 0 : bool result(self->IsFile());
24 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
25 0 : args.rval().setBoolean(result);
26 0 : return true;
27 : }
28 :
29 : static const JSJitInfo isFile_getterinfo = {
30 : { (JSJitGetterOp)get_isFile },
31 : { prototypes::id::FileSystemEntry },
32 : { PrototypeTraits<prototypes::id::FileSystemEntry>::Depth },
33 : JSJitInfo::Getter,
34 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
35 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
36 : true, /* isInfallible. False in setters. */
37 : false, /* isMovable. Not relevant for setters. */
38 : false, /* isEliminatable. Not relevant for setters. */
39 : false, /* isAlwaysInSlot. Only relevant for getters. */
40 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
41 : false, /* isTypedMethod. Only relevant for methods. */
42 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
43 : };
44 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
45 : static_assert(0 < 1, "There is no slot for us");
46 :
47 : static bool
48 0 : get_isDirectory(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystemEntry* self, JSJitGetterCallArgs args)
49 : {
50 0 : bool result(self->IsDirectory());
51 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
52 0 : args.rval().setBoolean(result);
53 0 : return true;
54 : }
55 :
56 : static const JSJitInfo isDirectory_getterinfo = {
57 : { (JSJitGetterOp)get_isDirectory },
58 : { prototypes::id::FileSystemEntry },
59 : { PrototypeTraits<prototypes::id::FileSystemEntry>::Depth },
60 : JSJitInfo::Getter,
61 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
62 : JSVAL_TYPE_BOOLEAN, /* returnType. Not relevant for setters. */
63 : true, /* isInfallible. False in setters. */
64 : false, /* isMovable. Not relevant for setters. */
65 : false, /* isEliminatable. Not relevant for setters. */
66 : false, /* isAlwaysInSlot. Only relevant for getters. */
67 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
68 : false, /* isTypedMethod. Only relevant for methods. */
69 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
70 : };
71 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
72 : static_assert(0 < 1, "There is no slot for us");
73 :
74 : static bool
75 0 : get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystemEntry* self, JSJitGetterCallArgs args)
76 : {
77 0 : binding_detail::FastErrorResult rv;
78 0 : DOMString result;
79 0 : self->GetName(result, rv);
80 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
81 0 : return false;
82 : }
83 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
84 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
85 0 : return false;
86 : }
87 0 : return true;
88 : }
89 :
90 : static const JSJitInfo name_getterinfo = {
91 : { (JSJitGetterOp)get_name },
92 : { prototypes::id::FileSystemEntry },
93 : { PrototypeTraits<prototypes::id::FileSystemEntry>::Depth },
94 : JSJitInfo::Getter,
95 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
96 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
97 : false, /* isInfallible. False in setters. */
98 : false, /* isMovable. Not relevant for setters. */
99 : false, /* isEliminatable. Not relevant for setters. */
100 : false, /* isAlwaysInSlot. Only relevant for getters. */
101 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
102 : false, /* isTypedMethod. Only relevant for methods. */
103 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
104 : };
105 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
106 : static_assert(0 < 1, "There is no slot for us");
107 :
108 : static bool
109 0 : get_fullPath(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystemEntry* self, JSJitGetterCallArgs args)
110 : {
111 0 : binding_detail::FastErrorResult rv;
112 0 : DOMString result;
113 0 : self->GetFullPath(result, rv);
114 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
115 0 : return false;
116 : }
117 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
118 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
119 0 : return false;
120 : }
121 0 : return true;
122 : }
123 :
124 : static const JSJitInfo fullPath_getterinfo = {
125 : { (JSJitGetterOp)get_fullPath },
126 : { prototypes::id::FileSystemEntry },
127 : { PrototypeTraits<prototypes::id::FileSystemEntry>::Depth },
128 : JSJitInfo::Getter,
129 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
130 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
131 : false, /* isInfallible. False in setters. */
132 : false, /* isMovable. Not relevant for setters. */
133 : false, /* isEliminatable. Not relevant for setters. */
134 : false, /* isAlwaysInSlot. Only relevant for getters. */
135 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
136 : false, /* isTypedMethod. Only relevant for methods. */
137 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
138 : };
139 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
140 : static_assert(0 < 1, "There is no slot for us");
141 :
142 : static bool
143 0 : get_filesystem(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystemEntry* self, JSJitGetterCallArgs args)
144 : {
145 0 : auto result(StrongOrRawPtr<mozilla::dom::FileSystem>(self->Filesystem()));
146 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
147 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
148 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
149 0 : return false;
150 : }
151 0 : return true;
152 : }
153 :
154 : static const JSJitInfo filesystem_getterinfo = {
155 : { (JSJitGetterOp)get_filesystem },
156 : { prototypes::id::FileSystemEntry },
157 : { PrototypeTraits<prototypes::id::FileSystemEntry>::Depth },
158 : JSJitInfo::Getter,
159 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
160 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
161 : false, /* isInfallible. False in setters. */
162 : false, /* isMovable. Not relevant for setters. */
163 : false, /* isEliminatable. Not relevant for setters. */
164 : false, /* isAlwaysInSlot. Only relevant for getters. */
165 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
166 : false, /* isTypedMethod. Only relevant for methods. */
167 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
168 : };
169 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
170 : static_assert(0 < 1, "There is no slot for us");
171 :
172 : static bool
173 0 : getParent(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileSystemEntry* self, const JSJitMethodCallArgs& args)
174 : {
175 0 : Optional<OwningNonNull<FileSystemEntryCallback>> arg0;
176 0 : if (args.hasDefined(0)) {
177 0 : arg0.Construct();
178 0 : if (args[0].isObject()) {
179 : { // scope for tempRoot
180 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
181 0 : arg0.Value() = new FileSystemEntryCallback(cx, tempRoot, GetIncumbentGlobal());
182 : }
183 : } else {
184 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of FileSystemEntry.getParent");
185 0 : return false;
186 : }
187 : }
188 0 : Optional<OwningNonNull<ErrorCallback>> arg1;
189 0 : if (args.hasDefined(1)) {
190 0 : arg1.Construct();
191 0 : if (args[1].isObject()) {
192 : { // scope for tempRoot
193 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[1].toObject());
194 0 : arg1.Value() = new ErrorCallback(cx, tempRoot, GetIncumbentGlobal());
195 : }
196 : } else {
197 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 2 of FileSystemEntry.getParent");
198 0 : return false;
199 : }
200 : }
201 0 : self->GetParent(NonNullHelper(Constify(arg0)), NonNullHelper(Constify(arg1)));
202 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
203 0 : args.rval().setUndefined();
204 0 : return true;
205 : }
206 :
207 : static const JSJitInfo getParent_methodinfo = {
208 : { (JSJitGetterOp)getParent },
209 : { prototypes::id::FileSystemEntry },
210 : { PrototypeTraits<prototypes::id::FileSystemEntry>::Depth },
211 : JSJitInfo::Method,
212 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
213 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
214 : false, /* isInfallible. False in setters. */
215 : false, /* isMovable. Not relevant for setters. */
216 : false, /* isEliminatable. Not relevant for setters. */
217 : false, /* isAlwaysInSlot. Only relevant for getters. */
218 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
219 : false, /* isTypedMethod. Only relevant for methods. */
220 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
221 : };
222 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
223 : static_assert(0 < 1, "There is no slot for us");
224 :
225 : static bool
226 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
227 : {
228 0 : mozilla::dom::FileSystemEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileSystemEntry>(obj);
229 : // We don't want to preserve if we don't have a wrapper, and we
230 : // obviously can't preserve if we're not initialized.
231 0 : if (self && self->GetWrapperPreserveColor()) {
232 0 : PreserveWrapper(self);
233 : }
234 0 : return true;
235 : }
236 :
237 : static void
238 0 : _finalize(js::FreeOp* fop, JSObject* obj)
239 : {
240 0 : mozilla::dom::FileSystemEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileSystemEntry>(obj);
241 0 : if (self) {
242 0 : ClearWrapper(self, self, obj);
243 0 : AddForDeferredFinalization<mozilla::dom::FileSystemEntry>(self);
244 : }
245 0 : }
246 :
247 : static void
248 0 : _objectMoved(JSObject* obj, const JSObject* old)
249 : {
250 0 : mozilla::dom::FileSystemEntry* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileSystemEntry>(obj);
251 0 : if (self) {
252 0 : UpdateWrapper(self, self, obj, old);
253 : }
254 0 : }
255 :
256 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
257 : #if defined(__clang__)
258 : #pragma clang diagnostic push
259 : #pragma clang diagnostic ignored "-Wmissing-braces"
260 : #endif
261 : static const JSFunctionSpec sMethods_specs[] = {
262 : JS_FNSPEC("getParent", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&getParent_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
263 : JS_FS_END
264 : };
265 : #if defined(__clang__)
266 : #pragma clang diagnostic pop
267 : #endif
268 :
269 :
270 : // Can't be const because the pref-enabled boolean needs to be writable
271 : static Prefable<const JSFunctionSpec> sMethods[] = {
272 : { nullptr, &sMethods_specs[0] },
273 : { nullptr, nullptr }
274 : };
275 :
276 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
277 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
278 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
279 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
280 :
281 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
282 : #if defined(__clang__)
283 : #pragma clang diagnostic push
284 : #pragma clang diagnostic ignored "-Wmissing-braces"
285 : #endif
286 : static const JSPropertySpec sAttributes_specs[] = {
287 : { "isFile", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &isFile_getterinfo, nullptr, nullptr },
288 : { "isDirectory", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &isDirectory_getterinfo, nullptr, nullptr },
289 : { "name", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &name_getterinfo, nullptr, nullptr },
290 : { "fullPath", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &fullPath_getterinfo, nullptr, nullptr },
291 : { "filesystem", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &filesystem_getterinfo, nullptr, nullptr },
292 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
293 : };
294 : #if defined(__clang__)
295 : #pragma clang diagnostic pop
296 : #endif
297 :
298 :
299 : // Can't be const because the pref-enabled boolean needs to be writable
300 : static Prefable<const JSPropertySpec> sAttributes[] = {
301 : { nullptr, &sAttributes_specs[0] },
302 : { nullptr, nullptr }
303 : };
304 :
305 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
306 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
307 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
308 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
309 :
310 :
311 : static uint16_t sNativeProperties_sortedPropertyIndices[6];
312 : static PropertyInfo sNativeProperties_propertyInfos[6];
313 :
314 : static const NativePropertiesN<2> sNativeProperties = {
315 : false, 0,
316 : false, 0,
317 : true, 0 /* sMethods */,
318 : true, 1 /* sAttributes */,
319 : false, 0,
320 : false, 0,
321 : false, 0,
322 : -1,
323 : 6,
324 : sNativeProperties_sortedPropertyIndices,
325 : {
326 : { sMethods, &sNativeProperties_propertyInfos[0] },
327 : { sAttributes, &sNativeProperties_propertyInfos[1] }
328 : }
329 : };
330 : static_assert(6 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
331 : "We have a property info count that is oversized");
332 :
333 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
334 : {
335 : "Function",
336 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
337 : &sBoringInterfaceObjectClassClassOps,
338 : JS_NULL_CLASS_SPEC,
339 : JS_NULL_CLASS_EXT,
340 : &sInterfaceObjectClassObjectOps
341 : },
342 : eInterface,
343 : true,
344 : prototypes::id::FileSystemEntry,
345 : PrototypeTraits<prototypes::id::FileSystemEntry>::Depth,
346 : sNativePropertyHooks,
347 : "function FileSystemEntry() {\n [native code]\n}",
348 : JS::GetRealmFunctionPrototype
349 : };
350 :
351 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
352 : {
353 : "FileSystemEntryPrototype",
354 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
355 : JS_NULL_CLASS_OPS,
356 : JS_NULL_CLASS_SPEC,
357 : JS_NULL_CLASS_EXT,
358 : JS_NULL_OBJECT_OPS
359 : },
360 : eInterfacePrototype,
361 : false,
362 : prototypes::id::FileSystemEntry,
363 : PrototypeTraits<prototypes::id::FileSystemEntry>::Depth,
364 : sNativePropertyHooks,
365 : "[object FileSystemEntryPrototype]",
366 : JS::GetRealmObjectPrototype
367 : };
368 :
369 : JSObject*
370 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
371 : {
372 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
373 : }
374 :
375 : static const js::ClassOps sClassOps = {
376 : _addProperty, /* addProperty */
377 : nullptr, /* delProperty */
378 : nullptr, /* getProperty */
379 : nullptr, /* setProperty */
380 : nullptr, /* enumerate */
381 : nullptr, /* newEnumerate */
382 : nullptr, /* resolve */
383 : nullptr, /* mayResolve */
384 : _finalize, /* finalize */
385 : nullptr, /* call */
386 : nullptr, /* hasInstance */
387 : nullptr, /* construct */
388 : nullptr, /* trace */
389 : };
390 :
391 : static const js::ClassExtension sClassExtension = {
392 : nullptr, /* weakmapKeyDelegateOp */
393 : _objectMoved /* objectMovedOp */
394 : };
395 :
396 : static const DOMJSClass sClass = {
397 : { "FileSystemEntry",
398 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
399 : &sClassOps,
400 : JS_NULL_CLASS_SPEC,
401 : &sClassExtension,
402 : JS_NULL_OBJECT_OPS
403 : },
404 : { prototypes::id::FileSystemEntry, 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 },
405 : IsBaseOf<nsISupports, mozilla::dom::FileSystemEntry >::value,
406 : sNativePropertyHooks,
407 : FindAssociatedGlobalForNative<mozilla::dom::FileSystemEntry>::Get,
408 : GetProtoObjectHandle,
409 : GetCCParticipant<mozilla::dom::FileSystemEntry>::Get()
410 : };
411 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
412 : "Must have the right minimal number of reserved slots.");
413 : static_assert(1 >= 1,
414 : "Must have enough reserved slots.");
415 :
416 : const JSClass*
417 0 : GetJSClass()
418 : {
419 0 : return sClass.ToJSClass();
420 : }
421 :
422 : bool
423 0 : Wrap(JSContext* aCx, mozilla::dom::FileSystemEntry* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
424 : {
425 : MOZ_ASSERT(static_cast<mozilla::dom::FileSystemEntry*>(aObject) ==
426 : reinterpret_cast<mozilla::dom::FileSystemEntry*>(aObject),
427 : "Multiple inheritance for mozilla::dom::FileSystemEntry is broken.");
428 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
429 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
430 0 : MOZ_ASSERT(!aCache->GetWrapper(),
431 : "You should probably not be using Wrap() directly; use "
432 : "GetOrCreateDOMReflector instead");
433 :
434 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
435 : "nsISupports must be on our primary inheritance chain");
436 :
437 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
438 0 : if (!global) {
439 0 : return false;
440 : }
441 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
442 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
443 :
444 : // That might have ended up wrapping us already, due to the wonders
445 : // of XBL. Check for that, and bail out as needed.
446 0 : aReflector.set(aCache->GetWrapper());
447 0 : if (aReflector) {
448 : #ifdef DEBUG
449 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
450 : #endif // DEBUG
451 0 : return true;
452 : }
453 :
454 0 : JSAutoCompartment ac(aCx, global);
455 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
456 0 : if (!canonicalProto) {
457 0 : return false;
458 : }
459 0 : JS::Rooted<JSObject*> proto(aCx);
460 0 : if (aGivenProto) {
461 0 : proto = aGivenProto;
462 : // Unfortunately, while aGivenProto was in the compartment of aCx
463 : // coming in, we changed compartments to that of "parent" so may need
464 : // to wrap the proto here.
465 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
466 0 : if (!JS_WrapObject(aCx, &proto)) {
467 0 : return false;
468 : }
469 : }
470 : } else {
471 0 : proto = canonicalProto;
472 : }
473 :
474 0 : BindingJSObjectCreator<mozilla::dom::FileSystemEntry> creator(aCx);
475 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
476 0 : if (!aReflector) {
477 0 : return false;
478 : }
479 :
480 0 : aCache->SetWrapper(aReflector);
481 0 : creator.InitializationSucceeded();
482 :
483 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
484 : aCache->GetWrapperPreserveColor() == aReflector);
485 : // If proto != canonicalProto, we have to preserve our wrapper;
486 : // otherwise we won't be able to properly recreate it later, since
487 : // we won't know what proto to use. Note that we don't check
488 : // aGivenProto here, since it's entirely possible (and even
489 : // somewhat common) to have a non-null aGivenProto which is the
490 : // same as canonicalProto.
491 0 : if (proto != canonicalProto) {
492 0 : PreserveWrapper(aObject);
493 : }
494 :
495 0 : return true;
496 : }
497 :
498 : const NativePropertyHooks sNativePropertyHooks[] = { {
499 : nullptr,
500 : nullptr,
501 : nullptr,
502 : { sNativeProperties.Upcast(), nullptr },
503 : prototypes::id::FileSystemEntry,
504 : constructors::id::FileSystemEntry,
505 : nullptr,
506 : &DefaultXrayExpandoObjectClass
507 : } };
508 :
509 : void
510 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
511 : {
512 0 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
513 0 : if (!parentProto) {
514 0 : return;
515 : }
516 :
517 0 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
518 0 : if (!constructorProto) {
519 0 : return;
520 : }
521 :
522 : static bool sIdsInited = false;
523 0 : if (!sIdsInited && NS_IsMainThread()) {
524 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
525 0 : return;
526 : }
527 0 : sIdsInited = true;
528 : }
529 :
530 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FileSystemEntry);
531 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FileSystemEntry);
532 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
533 : &sPrototypeClass.mBase, protoCache,
534 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
535 : interfaceCache,
536 : sNativeProperties.Upcast(),
537 : nullptr,
538 : "FileSystemEntry", aDefineOnGlobal,
539 : nullptr,
540 0 : false);
541 : }
542 :
543 : JS::Handle<JSObject*>
544 0 : GetProtoObjectHandle(JSContext* aCx)
545 : {
546 : /* Get the interface prototype object for this class. This will create the
547 : object as needed. */
548 0 : bool aDefineOnGlobal = true;
549 :
550 : /* Make sure our global is sane. Hopefully we can remove this sometime */
551 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
552 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
553 0 : return nullptr;
554 : }
555 :
556 : /* Check to see whether the interface objects are already installed */
557 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
558 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::FileSystemEntry)) {
559 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
560 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
561 : }
562 :
563 : /*
564 : * The object might _still_ be null, but that's OK.
565 : *
566 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
567 : * traced by TraceProtoAndIfaceCache() and its contents are never
568 : * changed after they have been set.
569 : *
570 : * Calling address() avoids the read read barrier that does gray
571 : * unmarking, but it's not possible for the object to be gray here.
572 : */
573 :
574 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::FileSystemEntry);
575 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
576 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
577 : }
578 :
579 : JSObject*
580 0 : GetProtoObject(JSContext* aCx)
581 : {
582 0 : return GetProtoObjectHandle(aCx);
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::FileSystemEntry)) {
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::FileSystemEntry);
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 FileSystemEntryBinding
627 :
628 :
629 :
630 : } // namespace dom
631 : } // namespace mozilla
|