/work/obj-fuzz/dom/bindings/DirectoryBinding.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* THIS FILE IS AUTOGENERATED FROM Directory.webidl BY Codegen.py - DO NOT EDIT */ |
2 | | |
3 | | #include "DirectoryBinding.h" |
4 | | #include "WrapperFactory.h" |
5 | | #include "mozilla/OwningNonNull.h" |
6 | | #include "mozilla/dom/BindingUtils.h" |
7 | | #include "mozilla/dom/DOMJSClass.h" |
8 | | #include "mozilla/dom/Directory.h" |
9 | | #include "mozilla/dom/NonRefcountedDOMObject.h" |
10 | | #include "mozilla/dom/PrimitiveConversions.h" |
11 | | #include "mozilla/dom/Promise.h" |
12 | | #include "mozilla/dom/ToJSValue.h" |
13 | | #include "mozilla/dom/XrayExpandoClass.h" |
14 | | #include "nsContentUtils.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 Directory_Binding { |
24 | | |
25 | | MOZ_CAN_RUN_SCRIPT static bool |
26 | | get_name(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Directory* self, JSJitGetterCallArgs args) |
27 | 0 | { |
28 | 0 | AUTO_PROFILER_LABEL_FAST("get Directory.name", DOM, cx); |
29 | 0 |
|
30 | 0 | FastErrorResult rv; |
31 | 0 | DOMString result; |
32 | 0 | self->GetName(result, rv); |
33 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
34 | 0 | return false; |
35 | 0 | } |
36 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
37 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
38 | 0 | return false; |
39 | 0 | } |
40 | 0 | return true; |
41 | 0 | } |
42 | | |
43 | | static const JSJitInfo name_getterinfo = { |
44 | | { (JSJitGetterOp)get_name }, |
45 | | { prototypes::id::Directory }, |
46 | | { PrototypeTraits<prototypes::id::Directory>::Depth }, |
47 | | JSJitInfo::Getter, |
48 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
49 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
50 | | false, /* isInfallible. False in setters. */ |
51 | | false, /* isMovable. Not relevant for setters. */ |
52 | | false, /* isEliminatable. Not relevant for setters. */ |
53 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
54 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
55 | | false, /* isTypedMethod. Only relevant for methods. */ |
56 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
57 | | }; |
58 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
59 | | static_assert(0 < 1, "There is no slot for us"); |
60 | | |
61 | | MOZ_CAN_RUN_SCRIPT static bool |
62 | | get_path(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Directory* self, JSJitGetterCallArgs args) |
63 | 0 | { |
64 | 0 | AUTO_PROFILER_LABEL_FAST("get Directory.path", DOM, cx); |
65 | 0 |
|
66 | 0 | FastErrorResult rv; |
67 | 0 | DOMString result; |
68 | 0 | self->GetPath(result, rv); |
69 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
70 | 0 | return false; |
71 | 0 | } |
72 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
73 | 0 | if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) { |
74 | 0 | return false; |
75 | 0 | } |
76 | 0 | return true; |
77 | 0 | } |
78 | | |
79 | | static const JSJitInfo path_getterinfo = { |
80 | | { (JSJitGetterOp)get_path }, |
81 | | { prototypes::id::Directory }, |
82 | | { PrototypeTraits<prototypes::id::Directory>::Depth }, |
83 | | JSJitInfo::Getter, |
84 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
85 | | JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */ |
86 | | false, /* isInfallible. False in setters. */ |
87 | | false, /* isMovable. Not relevant for setters. */ |
88 | | false, /* isEliminatable. Not relevant for setters. */ |
89 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
90 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
91 | | false, /* isTypedMethod. Only relevant for methods. */ |
92 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
93 | | }; |
94 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
95 | | static_assert(0 < 1, "There is no slot for us"); |
96 | | |
97 | | MOZ_CAN_RUN_SCRIPT static bool |
98 | | getFilesAndDirectories(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Directory* self, const JSJitMethodCallArgs& args) |
99 | 0 | { |
100 | 0 | AUTO_PROFILER_LABEL_FAST("Directory.getFilesAndDirectories", DOM, cx); |
101 | 0 |
|
102 | 0 | FastErrorResult rv; |
103 | 0 | auto result(StrongOrRawPtr<Promise>(self->GetFilesAndDirectories(rv))); |
104 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
105 | 0 | return false; |
106 | 0 | } |
107 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
108 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
109 | 0 | return false; |
110 | 0 | } |
111 | 0 | return true; |
112 | 0 | } |
113 | | |
114 | | MOZ_CAN_RUN_SCRIPT static bool |
115 | | getFilesAndDirectories_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Directory* self, const JSJitMethodCallArgs& args) |
116 | 0 | { |
117 | 0 | bool ok = getFilesAndDirectories(cx, obj, self, args); |
118 | 0 | if (ok) { |
119 | 0 | return true; |
120 | 0 | } |
121 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
122 | 0 | } |
123 | | |
124 | | static const JSJitInfo getFilesAndDirectories_methodinfo = { |
125 | | { (JSJitGetterOp)getFilesAndDirectories_promiseWrapper }, |
126 | | { prototypes::id::Directory }, |
127 | | { PrototypeTraits<prototypes::id::Directory>::Depth }, |
128 | | JSJitInfo::Method, |
129 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
130 | | JSVAL_TYPE_OBJECT, /* 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 | | MOZ_CAN_RUN_SCRIPT static bool |
143 | | getFiles(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Directory* self, const JSJitMethodCallArgs& args) |
144 | 0 | { |
145 | 0 | AUTO_PROFILER_LABEL_FAST("Directory.getFiles", DOM, cx); |
146 | 0 |
|
147 | 0 | bool arg0; |
148 | 0 | if (args.hasDefined(0)) { |
149 | 0 | if (!ValueToPrimitive<bool, eDefault>(cx, args[0], &arg0)) { |
150 | 0 | return false; |
151 | 0 | } |
152 | 0 | } else { |
153 | 0 | arg0 = false; |
154 | 0 | } |
155 | 0 | FastErrorResult rv; |
156 | 0 | auto result(StrongOrRawPtr<Promise>(self->GetFiles(arg0, rv))); |
157 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
158 | 0 | return false; |
159 | 0 | } |
160 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
161 | 0 | if (!ToJSValue(cx, result, args.rval())) { |
162 | 0 | return false; |
163 | 0 | } |
164 | 0 | return true; |
165 | 0 | } |
166 | | |
167 | | MOZ_CAN_RUN_SCRIPT static bool |
168 | | getFiles_promiseWrapper(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::Directory* self, const JSJitMethodCallArgs& args) |
169 | 0 | { |
170 | 0 | bool ok = getFiles(cx, obj, self, args); |
171 | 0 | if (ok) { |
172 | 0 | return true; |
173 | 0 | } |
174 | 0 | return ConvertExceptionToPromise(cx, args.rval()); |
175 | 0 | } |
176 | | |
177 | | static const JSJitInfo getFiles_methodinfo = { |
178 | | { (JSJitGetterOp)getFiles_promiseWrapper }, |
179 | | { prototypes::id::Directory }, |
180 | | { PrototypeTraits<prototypes::id::Directory>::Depth }, |
181 | | JSJitInfo::Method, |
182 | | JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */ |
183 | | JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */ |
184 | | false, /* isInfallible. False in setters. */ |
185 | | false, /* isMovable. Not relevant for setters. */ |
186 | | false, /* isEliminatable. Not relevant for setters. */ |
187 | | false, /* isAlwaysInSlot. Only relevant for getters. */ |
188 | | false, /* isLazilyCachedInSlot. Only relevant for getters. */ |
189 | | false, /* isTypedMethod. Only relevant for methods. */ |
190 | | 0 /* Reserved slot index, if we're stored in a slot, else 0. */ |
191 | | }; |
192 | | static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit"); |
193 | | static_assert(0 < 1, "There is no slot for us"); |
194 | | |
195 | | static bool |
196 | | _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val) |
197 | 0 | { |
198 | 0 | mozilla::dom::Directory* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Directory>(obj); |
199 | 0 | // We don't want to preserve if we don't have a wrapper, and we |
200 | 0 | // obviously can't preserve if we're not initialized. |
201 | 0 | if (self && self->GetWrapperPreserveColor()) { |
202 | 0 | PreserveWrapper(self); |
203 | 0 | } |
204 | 0 | return true; |
205 | 0 | } |
206 | | |
207 | | static void |
208 | | _finalize(js::FreeOp* fop, JSObject* obj) |
209 | 0 | { |
210 | 0 | mozilla::dom::Directory* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Directory>(obj); |
211 | 0 | if (self) { |
212 | 0 | ClearWrapper(self, self, obj); |
213 | 0 | AddForDeferredFinalization<mozilla::dom::Directory>(self); |
214 | 0 | } |
215 | 0 | } |
216 | | |
217 | | static size_t |
218 | | _objectMoved(JSObject* obj, JSObject* old) |
219 | 0 | { |
220 | 0 | mozilla::dom::Directory* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::Directory>(obj); |
221 | 0 | if (self) { |
222 | 0 | UpdateWrapper(self, self, obj, old); |
223 | 0 | } |
224 | 0 |
|
225 | 0 | return 0; |
226 | 0 | } |
227 | | |
228 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
229 | | #if defined(__clang__) |
230 | | #pragma clang diagnostic push |
231 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
232 | | #endif |
233 | | static const JSFunctionSpec sMethods_specs[] = { |
234 | | JS_FNSPEC("getFilesAndDirectories", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getFilesAndDirectories_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
235 | | JS_FNSPEC("getFiles", (GenericMethod<NormalThisPolicy, ConvertExceptionsToPromises>), reinterpret_cast<const JSJitInfo*>(&getFiles_methodinfo), 0, JSPROP_ENUMERATE, nullptr), |
236 | | JS_FS_END |
237 | | }; |
238 | | #if defined(__clang__) |
239 | | #pragma clang diagnostic pop |
240 | | #endif |
241 | | |
242 | | |
243 | | static const Prefable<const JSFunctionSpec> sMethods[] = { |
244 | | { nullptr, &sMethods_specs[0] }, |
245 | | { nullptr, nullptr } |
246 | | }; |
247 | | |
248 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
249 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
250 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
251 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
252 | | |
253 | | // We deliberately use brace-elision to make Visual Studio produce better initalization code. |
254 | | #if defined(__clang__) |
255 | | #pragma clang diagnostic push |
256 | | #pragma clang diagnostic ignored "-Wmissing-braces" |
257 | | #endif |
258 | | static const JSPropertySpec sAttributes_specs[] = { |
259 | | { "name", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &name_getterinfo, nullptr, nullptr }, |
260 | | { "path", JSPROP_ENUMERATE, GenericGetter<NormalThisPolicy, ThrowExceptions>, &path_getterinfo, nullptr, nullptr }, |
261 | | { nullptr, 0, nullptr, nullptr, nullptr, nullptr } |
262 | | }; |
263 | | #if defined(__clang__) |
264 | | #pragma clang diagnostic pop |
265 | | #endif |
266 | | |
267 | | |
268 | | static const Prefable<const JSPropertySpec> sAttributes[] = { |
269 | | { nullptr, &sAttributes_specs[0] }, |
270 | | { nullptr, nullptr } |
271 | | }; |
272 | | |
273 | | static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX, |
274 | | "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)"); |
275 | | static_assert(2 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX, |
276 | | "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)"); |
277 | | |
278 | | |
279 | | static uint16_t sNativeProperties_sortedPropertyIndices[4]; |
280 | | static PropertyInfo sNativeProperties_propertyInfos[4]; |
281 | | |
282 | | static const NativePropertiesN<2> sNativeProperties = { |
283 | | false, 0, |
284 | | false, 0, |
285 | | true, 0 /* sMethods */, |
286 | | true, 1 /* sAttributes */, |
287 | | false, 0, |
288 | | false, 0, |
289 | | false, 0, |
290 | | -1, |
291 | | 4, |
292 | | sNativeProperties_sortedPropertyIndices, |
293 | | { |
294 | | { sMethods, &sNativeProperties_propertyInfos[0] }, |
295 | | { sAttributes, &sNativeProperties_propertyInfos[2] } |
296 | | } |
297 | | }; |
298 | | static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount), |
299 | | "We have a property info count that is oversized"); |
300 | | |
301 | | static bool |
302 | | _constructor(JSContext* cx, unsigned argc, JS::Value* vp) |
303 | 0 | { |
304 | 0 | AUTO_PROFILER_LABEL_FAST("Directory constructor", DOM, cx); |
305 | 0 |
|
306 | 0 | JS::CallArgs args = JS::CallArgsFromVp(argc, vp); |
307 | 0 | JS::Rooted<JSObject*> obj(cx, &args.callee()); |
308 | 0 | if (!nsContentUtils::ThreadsafeIsSystemCaller(cx)) { |
309 | 0 | return ThrowingConstructor(cx, argc, vp); |
310 | 0 | } |
311 | 0 | |
312 | 0 | if (!args.isConstructing()) { |
313 | 0 | // XXXbz wish I could get the name from the callee instead of |
314 | 0 | // Adding more relocations |
315 | 0 | return ThrowConstructorWithoutNew(cx, "Directory"); |
316 | 0 | } |
317 | 0 | |
318 | 0 | JS::Rooted<JSObject*> desiredProto(cx); |
319 | 0 | if (!GetDesiredProto(cx, args, &desiredProto)) { |
320 | 0 | return false; |
321 | 0 | } |
322 | 0 | |
323 | 0 | if (MOZ_UNLIKELY(args.length() < 1)) { |
324 | 0 | return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "Directory"); |
325 | 0 | } |
326 | 0 | GlobalObject global(cx, obj); |
327 | 0 | if (global.Failed()) { |
328 | 0 | return false; |
329 | 0 | } |
330 | 0 | |
331 | 0 | bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj); |
332 | 0 | binding_detail::FakeString arg0; |
333 | 0 | if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) { |
334 | 0 | return false; |
335 | 0 | } |
336 | 0 | Maybe<JSAutoRealm> ar; |
337 | 0 | if (objIsXray) { |
338 | 0 | obj = js::CheckedUnwrap(obj); |
339 | 0 | if (!obj) { |
340 | 0 | return false; |
341 | 0 | } |
342 | 0 | ar.emplace(cx, obj); |
343 | 0 | if (!JS_WrapObject(cx, &desiredProto)) { |
344 | 0 | return false; |
345 | 0 | } |
346 | 0 | } |
347 | 0 | FastErrorResult rv; |
348 | 0 | auto result(StrongOrRawPtr<mozilla::dom::Directory>(mozilla::dom::Directory::Constructor(global, NonNullHelper(Constify(arg0)), rv))); |
349 | 0 | if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) { |
350 | 0 | return false; |
351 | 0 | } |
352 | 0 | MOZ_ASSERT(!JS_IsExceptionPending(cx)); |
353 | 0 | static_assert(!IsPointer<decltype(result)>::value, |
354 | 0 | "NewObject implies that we need to keep the object alive with a strong reference."); |
355 | 0 | if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) { |
356 | 0 | MOZ_ASSERT(JS_IsExceptionPending(cx)); |
357 | 0 | return false; |
358 | 0 | } |
359 | 0 | return true; |
360 | 0 | } |
361 | | |
362 | | static const js::ClassOps sInterfaceObjectClassOps = { |
363 | | nullptr, /* addProperty */ |
364 | | nullptr, /* delProperty */ |
365 | | nullptr, /* enumerate */ |
366 | | nullptr, /* newEnumerate */ |
367 | | nullptr, /* resolve */ |
368 | | nullptr, /* mayResolve */ |
369 | | nullptr, /* finalize */ |
370 | | _constructor, /* call */ |
371 | | nullptr, /* hasInstance */ |
372 | | _constructor, /* construct */ |
373 | | nullptr, /* trace */ |
374 | | }; |
375 | | |
376 | | static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = { |
377 | | { |
378 | | "Function", |
379 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE), |
380 | | &sInterfaceObjectClassOps, |
381 | | JS_NULL_CLASS_SPEC, |
382 | | JS_NULL_CLASS_EXT, |
383 | | &sInterfaceObjectClassObjectOps |
384 | | }, |
385 | | eInterface, |
386 | | true, |
387 | | prototypes::id::Directory, |
388 | | PrototypeTraits<prototypes::id::Directory>::Depth, |
389 | | sNativePropertyHooks, |
390 | | "function Directory() {\n [native code]\n}", |
391 | | JS::GetRealmFunctionPrototype |
392 | | }; |
393 | | |
394 | | static const DOMIfaceAndProtoJSClass sPrototypeClass = { |
395 | | { |
396 | | "DirectoryPrototype", |
397 | | JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE), |
398 | | JS_NULL_CLASS_OPS, |
399 | | JS_NULL_CLASS_SPEC, |
400 | | JS_NULL_CLASS_EXT, |
401 | | JS_NULL_OBJECT_OPS |
402 | | }, |
403 | | eInterfacePrototype, |
404 | | false, |
405 | | prototypes::id::Directory, |
406 | | PrototypeTraits<prototypes::id::Directory>::Depth, |
407 | | sNativePropertyHooks, |
408 | | "[object DirectoryPrototype]", |
409 | | JS::GetRealmObjectPrototype |
410 | | }; |
411 | | |
412 | | static const js::ClassOps sClassOps = { |
413 | | _addProperty, /* addProperty */ |
414 | | nullptr, /* delProperty */ |
415 | | nullptr, /* enumerate */ |
416 | | nullptr, /* newEnumerate */ |
417 | | nullptr, /* resolve */ |
418 | | nullptr, /* mayResolve */ |
419 | | _finalize, /* finalize */ |
420 | | nullptr, /* call */ |
421 | | nullptr, /* hasInstance */ |
422 | | nullptr, /* construct */ |
423 | | nullptr, /* trace */ |
424 | | }; |
425 | | |
426 | | static const js::ClassExtension sClassExtension = { |
427 | | nullptr, /* weakmapKeyDelegateOp */ |
428 | | _objectMoved /* objectMovedOp */ |
429 | | }; |
430 | | |
431 | | static const DOMJSClass sClass = { |
432 | | { "Directory", |
433 | | JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1), |
434 | | &sClassOps, |
435 | | JS_NULL_CLASS_SPEC, |
436 | | &sClassExtension, |
437 | | JS_NULL_OBJECT_OPS |
438 | | }, |
439 | | { prototypes::id::Directory, 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 }, |
440 | | IsBaseOf<nsISupports, mozilla::dom::Directory >::value, |
441 | | sNativePropertyHooks, |
442 | | FindAssociatedGlobalForNative<mozilla::dom::Directory>::Get, |
443 | | GetProtoObjectHandle, |
444 | | GetCCParticipant<mozilla::dom::Directory>::Get() |
445 | | }; |
446 | | static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS, |
447 | | "Must have the right minimal number of reserved slots."); |
448 | | static_assert(1 >= 1, |
449 | | "Must have enough reserved slots."); |
450 | | |
451 | | const JSClass* |
452 | | GetJSClass() |
453 | 0 | { |
454 | 0 | return sClass.ToJSClass(); |
455 | 0 | } |
456 | | |
457 | | bool |
458 | | Wrap(JSContext* aCx, mozilla::dom::Directory* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector) |
459 | 0 | { |
460 | 0 | static_assert(!IsBaseOf<NonRefcountedDOMObject, mozilla::dom::Directory>::value, |
461 | 0 | "Shouldn't have wrappercached things that are not refcounted."); |
462 | 0 | MOZ_ASSERT(static_cast<mozilla::dom::Directory*>(aObject) == |
463 | 0 | reinterpret_cast<mozilla::dom::Directory*>(aObject), |
464 | 0 | "Multiple inheritance for mozilla::dom::Directory is broken."); |
465 | 0 | MOZ_ASSERT(ToSupportsIsCorrect(aObject)); |
466 | 0 | MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx)); |
467 | 0 | MOZ_ASSERT(!aCache->GetWrapper(), |
468 | 0 | "You should probably not be using Wrap() directly; use " |
469 | 0 | "GetOrCreateDOMReflector instead"); |
470 | 0 |
|
471 | 0 | MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache), |
472 | 0 | "nsISupports must be on our primary inheritance chain"); |
473 | 0 |
|
474 | 0 | JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject())); |
475 | 0 | if (!global) { |
476 | 0 | return false; |
477 | 0 | } |
478 | 0 | MOZ_ASSERT(JS_IsGlobalObject(global)); |
479 | 0 | MOZ_ASSERT(JS::ObjectIsNotGray(global)); |
480 | 0 |
|
481 | 0 | // That might have ended up wrapping us already, due to the wonders |
482 | 0 | // of XBL. Check for that, and bail out as needed. |
483 | 0 | aReflector.set(aCache->GetWrapper()); |
484 | 0 | if (aReflector) { |
485 | | #ifdef DEBUG |
486 | | AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto); |
487 | | #endif // DEBUG |
488 | | return true; |
489 | 0 | } |
490 | 0 |
|
491 | 0 | JSAutoRealm ar(aCx, global); |
492 | 0 | JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx); |
493 | 0 | if (!canonicalProto) { |
494 | 0 | return false; |
495 | 0 | } |
496 | 0 | JS::Rooted<JSObject*> proto(aCx); |
497 | 0 | if (aGivenProto) { |
498 | 0 | proto = aGivenProto; |
499 | 0 | // Unfortunately, while aGivenProto was in the compartment of aCx |
500 | 0 | // coming in, we changed compartments to that of "parent" so may need |
501 | 0 | // to wrap the proto here. |
502 | 0 | if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) { |
503 | 0 | if (!JS_WrapObject(aCx, &proto)) { |
504 | 0 | return false; |
505 | 0 | } |
506 | 0 | } |
507 | 0 | } else { |
508 | 0 | proto = canonicalProto; |
509 | 0 | } |
510 | 0 |
|
511 | 0 | BindingJSObjectCreator<mozilla::dom::Directory> creator(aCx); |
512 | 0 | creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector); |
513 | 0 | if (!aReflector) { |
514 | 0 | return false; |
515 | 0 | } |
516 | 0 | |
517 | 0 | aCache->SetWrapper(aReflector); |
518 | 0 | creator.InitializationSucceeded(); |
519 | 0 |
|
520 | 0 | MOZ_ASSERT(aCache->GetWrapperPreserveColor() && |
521 | 0 | aCache->GetWrapperPreserveColor() == aReflector); |
522 | 0 | // If proto != canonicalProto, we have to preserve our wrapper; |
523 | 0 | // otherwise we won't be able to properly recreate it later, since |
524 | 0 | // we won't know what proto to use. Note that we don't check |
525 | 0 | // aGivenProto here, since it's entirely possible (and even |
526 | 0 | // somewhat common) to have a non-null aGivenProto which is the |
527 | 0 | // same as canonicalProto. |
528 | 0 | if (proto != canonicalProto) { |
529 | 0 | PreserveWrapper(aObject); |
530 | 0 | } |
531 | 0 |
|
532 | 0 | return true; |
533 | 0 | } |
534 | | |
535 | | const NativePropertyHooks sNativePropertyHooks[] = { { |
536 | | nullptr, |
537 | | nullptr, |
538 | | nullptr, |
539 | | { sNativeProperties.Upcast(), nullptr }, |
540 | | prototypes::id::Directory, |
541 | | constructors::id::Directory, |
542 | | nullptr, |
543 | | &DefaultXrayExpandoObjectClass |
544 | | } }; |
545 | | |
546 | | void |
547 | | CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal) |
548 | 0 | { |
549 | 0 | JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx)); |
550 | 0 | if (!parentProto) { |
551 | 0 | return; |
552 | 0 | } |
553 | 0 | |
554 | 0 | JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx)); |
555 | 0 | if (!constructorProto) { |
556 | 0 | return; |
557 | 0 | } |
558 | 0 | |
559 | 0 | static bool sIdsInited = false; |
560 | 0 | if (!sIdsInited && NS_IsMainThread()) { |
561 | 0 | if (!InitIds(aCx, sNativeProperties.Upcast())) { |
562 | 0 | return; |
563 | 0 | } |
564 | 0 | sIdsInited = true; |
565 | 0 | } |
566 | 0 |
|
567 | 0 | JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::Directory); |
568 | 0 | JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::Directory); |
569 | 0 | dom::CreateInterfaceObjects(aCx, aGlobal, parentProto, |
570 | 0 | &sPrototypeClass.mBase, protoCache, |
571 | 0 | nullptr, |
572 | 0 | constructorProto, &sInterfaceObjectClass.mBase, 1, nullptr, |
573 | 0 | interfaceCache, |
574 | 0 | sNativeProperties.Upcast(), |
575 | 0 | nullptr, |
576 | 0 | "Directory", aDefineOnGlobal, |
577 | 0 | nullptr, |
578 | 0 | false); |
579 | 0 | } |
580 | | |
581 | | JSObject* |
582 | | GetConstructorObject(JSContext* aCx) |
583 | 0 | { |
584 | 0 | return GetConstructorObjectHandle(aCx); |
585 | 0 | } |
586 | | |
587 | | } // namespace Directory_Binding |
588 | | |
589 | | |
590 | | |
591 | | } // namespace dom |
592 | | } // namespace mozilla |