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