Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM FileList.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "FileListBinding.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/DOMJSProxyHandler.h"
9 : #include "mozilla/dom/File.h"
10 : #include "mozilla/dom/FileList.h"
11 : #include "mozilla/dom/NonRefcountedDOMObject.h"
12 : #include "mozilla/dom/Nullable.h"
13 : #include "mozilla/dom/PrimitiveConversions.h"
14 : #include "mozilla/dom/XrayExpandoClass.h"
15 : #include "nsISupports.h"
16 : #include "xpcjsid.h"
17 :
18 : namespace mozilla {
19 : namespace dom {
20 :
21 : namespace FileListBinding {
22 :
23 : static bool
24 0 : item(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileList* self, const JSJitMethodCallArgs& args)
25 : {
26 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
27 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "FileList.item");
28 : }
29 : uint32_t arg0;
30 0 : if (!ValueToPrimitive<uint32_t, eDefault>(cx, args[0], &arg0)) {
31 0 : return false;
32 : }
33 0 : auto result(StrongOrRawPtr<mozilla::dom::File>(self->Item(arg0)));
34 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
35 0 : if (!result) {
36 0 : args.rval().setNull();
37 0 : return true;
38 : }
39 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
40 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
41 0 : return false;
42 : }
43 0 : return true;
44 : }
45 :
46 : static const JSJitInfo item_methodinfo = {
47 : { (JSJitGetterOp)item },
48 : { prototypes::id::FileList },
49 : { PrototypeTraits<prototypes::id::FileList>::Depth },
50 : JSJitInfo::Method,
51 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
52 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
53 : false, /* isInfallible. False in setters. */
54 : false, /* isMovable. Not relevant for setters. */
55 : false, /* isEliminatable. Not relevant for setters. */
56 : false, /* isAlwaysInSlot. Only relevant for getters. */
57 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
58 : false, /* isTypedMethod. Only relevant for methods. */
59 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
60 : };
61 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
62 : static_assert(0 < 1, "There is no slot for us");
63 :
64 : static bool
65 0 : get_length(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::FileList* self, JSJitGetterCallArgs args)
66 : {
67 0 : uint32_t result(self->Length());
68 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
69 0 : args.rval().setNumber(result);
70 0 : return true;
71 : }
72 :
73 : static const JSJitInfo length_getterinfo = {
74 : { (JSJitGetterOp)get_length },
75 : { prototypes::id::FileList },
76 : { PrototypeTraits<prototypes::id::FileList>::Depth },
77 : JSJitInfo::Getter,
78 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
79 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
80 : true, /* isInfallible. False in setters. */
81 : false, /* isMovable. Not relevant for setters. */
82 : false, /* isEliminatable. Not relevant for setters. */
83 : false, /* isAlwaysInSlot. Only relevant for getters. */
84 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
85 : false, /* isTypedMethod. Only relevant for methods. */
86 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
87 : };
88 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
89 : static_assert(0 < 1, "There is no slot for us");
90 :
91 : static void
92 0 : _objectMoved(JSObject* obj, const JSObject* old)
93 : {
94 0 : mozilla::dom::FileList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileList>(obj);
95 0 : if (self) {
96 0 : UpdateWrapper(self, self, obj, old);
97 : }
98 0 : }
99 :
100 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
101 : #if defined(__clang__)
102 : #pragma clang diagnostic push
103 : #pragma clang diagnostic ignored "-Wmissing-braces"
104 : #endif
105 : static const JSFunctionSpec sMethods_specs[] = {
106 : JS_FNSPEC("item", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&item_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
107 : JS_FS_END,
108 : JS_FNSPEC("QueryInterface", QueryInterface, nullptr, 1, 0, nullptr),
109 : JS_FS_END,
110 : JS_SYM_FNSPEC(iterator, nullptr, nullptr, 0, 0, "ArrayValues"),
111 : JS_FS_END
112 : };
113 : #if defined(__clang__)
114 : #pragma clang diagnostic pop
115 : #endif
116 :
117 : static PrefableDisablers sMethods_disablers2 = {
118 : true, false, 0, &WantsQueryInterface<mozilla::dom::FileList>::Enabled
119 : };
120 :
121 : // Can't be const because the pref-enabled boolean needs to be writable
122 : static Prefable<const JSFunctionSpec> sMethods[] = {
123 : { nullptr, &sMethods_specs[0] },
124 : { &sMethods_disablers2, &sMethods_specs[2] },
125 : { nullptr, &sMethods_specs[4] },
126 : { nullptr, nullptr }
127 : };
128 :
129 : static_assert(3 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
130 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
131 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
132 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
133 :
134 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
135 : #if defined(__clang__)
136 : #pragma clang diagnostic push
137 : #pragma clang diagnostic ignored "-Wmissing-braces"
138 : #endif
139 : static const JSPropertySpec sAttributes_specs[] = {
140 : { "length", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &length_getterinfo, nullptr, nullptr },
141 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
142 : };
143 : #if defined(__clang__)
144 : #pragma clang diagnostic pop
145 : #endif
146 :
147 :
148 : // Can't be const because the pref-enabled boolean needs to be writable
149 : static Prefable<const JSPropertySpec> sAttributes[] = {
150 : { nullptr, &sAttributes_specs[0] },
151 : { nullptr, nullptr }
152 : };
153 :
154 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
155 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
156 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
157 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
158 :
159 :
160 : static uint16_t sNativeProperties_sortedPropertyIndices[4];
161 : static PropertyInfo sNativeProperties_propertyInfos[4];
162 :
163 : static const NativePropertiesN<2> sNativeProperties = {
164 : false, 0,
165 : false, 0,
166 : true, 0 /* sMethods */,
167 : true, 1 /* sAttributes */,
168 : false, 0,
169 : false, 0,
170 : false, 0,
171 : -1,
172 : 4,
173 : sNativeProperties_sortedPropertyIndices,
174 : {
175 : { sMethods, &sNativeProperties_propertyInfos[0] },
176 : { sAttributes, &sNativeProperties_propertyInfos[3] }
177 : }
178 : };
179 : static_assert(4 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
180 : "We have a property info count that is oversized");
181 :
182 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
183 : {
184 : "Function",
185 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
186 : &sBoringInterfaceObjectClassClassOps,
187 : JS_NULL_CLASS_SPEC,
188 : JS_NULL_CLASS_EXT,
189 : &sInterfaceObjectClassObjectOps
190 : },
191 : eInterface,
192 : true,
193 : prototypes::id::FileList,
194 : PrototypeTraits<prototypes::id::FileList>::Depth,
195 : sNativePropertyHooks,
196 : "function FileList() {\n [native code]\n}",
197 : JS::GetRealmFunctionPrototype
198 : };
199 :
200 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
201 : {
202 : "FileListPrototype",
203 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
204 : JS_NULL_CLASS_OPS,
205 : JS_NULL_CLASS_SPEC,
206 : JS_NULL_CLASS_EXT,
207 : JS_NULL_OBJECT_OPS
208 : },
209 : eInterfacePrototype,
210 : false,
211 : prototypes::id::FileList,
212 : PrototypeTraits<prototypes::id::FileList>::Depth,
213 : sNativePropertyHooks,
214 : "[object FileListPrototype]",
215 : JS::GetRealmObjectPrototype
216 : };
217 :
218 : JSObject*
219 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
220 : {
221 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
222 : }
223 :
224 : static_assert(IsBaseOf<nsISupports, mozilla::dom::FileList >::value,
225 : "We don't support non-nsISupports native classes for "
226 : "proxy-based bindings yet");
227 :
228 :
229 : class DOMProxyHandler : public mozilla::dom::DOMProxyHandler
230 : {
231 : public:
232 : explicit constexpr DOMProxyHandler()
233 : {
234 : }
235 :
236 : virtual bool
237 : getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const override;
238 :
239 : virtual bool
240 : defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const override;
241 :
242 : using mozilla::dom::DOMProxyHandler::defineProperty;
243 :
244 : virtual bool
245 : ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const override;
246 :
247 : virtual bool
248 : hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const override;
249 :
250 : virtual bool
251 : get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const override;
252 :
253 : virtual const char*
254 : className(JSContext* cx, JS::Handle<JSObject*> proxy) const override;
255 :
256 : virtual bool
257 : finalizeInBackground(const JS::Value& priv) const override;
258 :
259 : virtual void
260 : finalize(JSFreeOp* fop, JSObject* proxy) const override;
261 :
262 : static const DOMProxyHandler*
263 : getInstance();
264 :
265 : virtual bool
266 : delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const override;
267 :
268 : virtual bool
269 : getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const override;
270 : };
271 :
272 : MOZ_ALWAYS_INLINE bool
273 0 : IsProxy(JSObject* obj)
274 : {
275 0 : return js::IsProxy(obj) && js::GetProxyHandler(obj) == DOMProxyHandler::getInstance();
276 : }
277 :
278 : MOZ_ALWAYS_INLINE mozilla::dom::FileList*
279 0 : UnwrapProxy(JSObject* obj)
280 : {
281 0 : MOZ_ASSERT(js::IsProxy(obj));
282 0 : if (js::GetProxyHandler(obj) != DOMProxyHandler::getInstance()) {
283 0 : MOZ_ASSERT(xpc::WrapperFactory::IsXrayWrapper(obj));
284 0 : obj = js::UncheckedUnwrap(obj);
285 : }
286 0 : MOZ_ASSERT(IsProxy(obj));
287 0 : return static_cast<mozilla::dom::FileList*>(js::GetProxyReservedSlot(obj, DOM_OBJECT_SLOT).toPrivate());
288 : }
289 :
290 : bool
291 0 : DOMProxyHandler::getOwnPropDescriptor(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool ignoreNamedProps, JS::MutableHandle<JS::PropertyDescriptor> desc) const
292 : {
293 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
294 0 : uint32_t index = GetArrayIndexFromId(cx, id);
295 0 : if (IsArrayIndex(index)) {
296 0 : mozilla::dom::FileList* self = UnwrapProxy(proxy);
297 0 : bool found = false;
298 0 : auto result(StrongOrRawPtr<mozilla::dom::File>(self->IndexedGetter(index, found)));
299 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
300 :
301 0 : if (found) {
302 0 : if (!result) {
303 0 : desc.value().setNull();
304 0 : FillPropertyDescriptor(desc, proxy, true);
305 0 : return true;
306 : }
307 0 : if (!GetOrCreateDOMReflector(cx, result, desc.value())) {
308 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
309 0 : return false;
310 : }
311 0 : FillPropertyDescriptor(desc, proxy, true);
312 0 : return true;
313 : }
314 : }
315 :
316 0 : JS::Rooted<JSObject*> expando(cx);
317 0 : if (!isXray && (expando = GetExpandoObject(proxy))) {
318 0 : if (!JS_GetOwnPropertyDescriptorById(cx, expando, id, desc)) {
319 0 : return false;
320 : }
321 0 : if (desc.object()) {
322 : // Pretend the property lives on the wrapper.
323 0 : desc.object().set(proxy);
324 0 : return true;
325 : }
326 : }
327 :
328 0 : desc.object().set(nullptr);
329 0 : return true;
330 : }
331 :
332 : bool
333 0 : DOMProxyHandler::defineProperty(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::Handle<JS::PropertyDescriptor> desc, JS::ObjectOpResult& opresult, bool* defined) const
334 : {
335 0 : if (IsArrayIndex(GetArrayIndexFromId(cx, id))) {
336 0 : *defined = true;
337 0 : return opresult.failNoIndexedSetter();
338 : }
339 0 : return mozilla::dom::DOMProxyHandler::defineProperty(cx, proxy, id, desc, opresult, defined);
340 : }
341 :
342 :
343 : bool
344 0 : DOMProxyHandler::ownPropNames(JSContext* cx, JS::Handle<JSObject*> proxy, unsigned flags, JS::AutoIdVector& props) const
345 : {
346 0 : bool isXray = xpc::WrapperFactory::IsXrayWrapper(proxy);
347 :
348 0 : uint32_t length = UnwrapProxy(proxy)->Length();
349 0 : MOZ_ASSERT(int32_t(length) >= 0);
350 0 : for (int32_t i = 0; i < int32_t(length); ++i) {
351 0 : if (!props.append(INT_TO_JSID(i))) {
352 0 : return false;
353 : }
354 : }
355 :
356 0 : JS::Rooted<JSObject*> expando(cx);
357 0 : if (!isXray && (expando = DOMProxyHandler::GetExpandoObject(proxy)) &&
358 0 : !js::GetPropertyKeys(cx, expando, flags, &props)) {
359 0 : return false;
360 : }
361 :
362 0 : return true;
363 : }
364 :
365 : bool
366 0 : DOMProxyHandler::hasOwn(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, bool* bp) const
367 : {
368 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
369 : "Should not have a XrayWrapper here");
370 :
371 0 : uint32_t index = GetArrayIndexFromId(cx, id);
372 0 : if (IsArrayIndex(index)) {
373 0 : bool found = false;
374 0 : mozilla::dom::FileList* self = UnwrapProxy(proxy);
375 0 : auto result(StrongOrRawPtr<mozilla::dom::File>(self->IndexedGetter(index, found)));
376 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
377 : (void)result;
378 :
379 0 : *bp = found;
380 0 : return true;
381 : }
382 :
383 :
384 0 : JS::Rooted<JSObject*> expando(cx, GetExpandoObject(proxy));
385 0 : if (expando) {
386 0 : bool b = true;
387 0 : bool ok = JS_HasPropertyById(cx, expando, id, &b);
388 0 : *bp = !!b;
389 0 : if (!ok || *bp) {
390 0 : return ok;
391 : }
392 : }
393 :
394 0 : *bp = false;
395 0 : return true;
396 : }
397 :
398 : bool
399 0 : DOMProxyHandler::get(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<JS::Value> receiver, JS::Handle<jsid> id, JS::MutableHandle<JS::Value> vp) const
400 : {
401 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
402 : "Should not have a XrayWrapper here");
403 :
404 0 : uint32_t index = GetArrayIndexFromId(cx, id);
405 0 : if (IsArrayIndex(index)) {
406 0 : mozilla::dom::FileList* self = UnwrapProxy(proxy);
407 0 : bool found = false;
408 0 : auto result(StrongOrRawPtr<mozilla::dom::File>(self->IndexedGetter(index, found)));
409 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
410 :
411 0 : if (found) {
412 0 : if (!result) {
413 0 : vp.setNull();
414 0 : return true;
415 : }
416 0 : if (!GetOrCreateDOMReflector(cx, result, vp)) {
417 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
418 0 : return false;
419 : }
420 0 : return true;
421 : }
422 : // Even if we don't have this index, we don't forward the
423 : // get on to our expando object.
424 : } else {
425 : { // Scope for expando
426 0 : JS::Rooted<JSObject*> expando(cx, DOMProxyHandler::GetExpandoObject(proxy));
427 0 : if (expando) {
428 : bool hasProp;
429 0 : if (!JS_HasPropertyById(cx, expando, id, &hasProp)) {
430 0 : return false;
431 : }
432 :
433 0 : if (hasProp) {
434 : // Forward the get to the expando object, but our receiver is whatever our
435 : // receiver is.
436 0 : return JS_ForwardGetPropertyTo(cx, expando, id, receiver, vp);
437 : }
438 : }
439 : }
440 : }
441 :
442 : bool foundOnPrototype;
443 0 : if (!GetPropertyOnPrototype(cx, proxy, receiver, id, &foundOnPrototype, vp)) {
444 0 : return false;
445 : }
446 :
447 0 : if (foundOnPrototype) {
448 0 : return true;
449 : }
450 :
451 0 : vp.setUndefined();
452 0 : return true;
453 : }
454 :
455 : const char*
456 0 : DOMProxyHandler::className(JSContext* cx, JS::Handle<JSObject*> proxy) const
457 : {
458 0 : return "FileList";
459 : }
460 :
461 : bool
462 0 : DOMProxyHandler::finalizeInBackground(const JS::Value& priv) const
463 : {
464 0 : return false;
465 : }
466 :
467 : void
468 0 : DOMProxyHandler::finalize(JSFreeOp* fop, JSObject* proxy) const
469 : {
470 0 : mozilla::dom::FileList* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::FileList>(proxy);
471 0 : if (self) {
472 0 : ClearWrapper(self, self, proxy);
473 0 : AddForDeferredFinalization<mozilla::dom::FileList>(self);
474 : }
475 0 : }
476 :
477 : const DOMProxyHandler*
478 0 : DOMProxyHandler::getInstance()
479 : {
480 : static const DOMProxyHandler instance;
481 0 : return &instance;
482 : }
483 :
484 : bool
485 0 : DOMProxyHandler::delete_(JSContext* cx, JS::Handle<JSObject*> proxy, JS::Handle<jsid> id, JS::ObjectOpResult& opresult) const
486 : {
487 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
488 : "Should not have a XrayWrapper here");
489 :
490 0 : uint32_t index = GetArrayIndexFromId(cx, id);
491 0 : if (IsArrayIndex(index)) {
492 : bool deleteSucceeded;
493 0 : bool found = false;
494 0 : mozilla::dom::FileList* self = UnwrapProxy(proxy);
495 0 : auto result(StrongOrRawPtr<mozilla::dom::File>(self->IndexedGetter(index, found)));
496 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
497 : (void)result;
498 0 : deleteSucceeded = !found;
499 0 : return deleteSucceeded ? opresult.succeed() : opresult.failCantDelete();
500 : }
501 :
502 0 : return dom::DOMProxyHandler::delete_(cx, proxy, id, opresult);
503 : }
504 :
505 : bool
506 0 : DOMProxyHandler::getElements(JSContext* cx, JS::Handle<JSObject*> proxy, uint32_t begin, uint32_t end, js::ElementAdder* adder) const
507 : {
508 0 : JS::Rooted<JS::Value> temp(cx);
509 0 : MOZ_ASSERT(!xpc::WrapperFactory::IsXrayWrapper(proxy),
510 : "Should not have a XrayWrapper here");
511 :
512 0 : mozilla::dom::FileList* self = UnwrapProxy(proxy);
513 0 : uint32_t length = self->Length();
514 : // Compute the end of the indices we'll get ourselves
515 0 : uint32_t ourEnd = std::max(begin, std::min(end, length));
516 :
517 0 : for (uint32_t index = begin; index < ourEnd; ++index) {
518 0 : bool found = false;
519 0 : auto result(StrongOrRawPtr<mozilla::dom::File>(self->IndexedGetter(index, found)));
520 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
521 :
522 0 : MOZ_ASSERT(found);
523 0 : if (!result) {
524 0 : temp.setNull();
525 0 : if (!adder->append(cx, temp)) return false;
526 0 : continue;
527 : }
528 0 : if (!GetOrCreateDOMReflector(cx, result, &temp)) {
529 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
530 0 : return false;
531 : }
532 0 : if (!adder->append(cx, temp)) return false;
533 0 : continue;
534 : }
535 :
536 0 : if (end > ourEnd) {
537 0 : JS::Rooted<JSObject*> proto(cx);
538 0 : if (!js::GetObjectProto(cx, proxy, &proto)) {
539 0 : return false;
540 : }
541 0 : return js::GetElementsWithAdder(cx, proto, proxy, ourEnd, end, adder);
542 : }
543 :
544 0 : return true;
545 : }
546 :
547 : static const js::ClassExtension sClassExtension = PROXY_MAKE_EXT(
548 : _objectMoved
549 : );
550 :
551 : static const DOMJSClass sClass = {
552 : PROXY_CLASS_WITH_EXT("FileList",
553 : JSCLASS_IS_DOMJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(1),
554 : &sClassExtension),
555 : { prototypes::id::FileList, 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 },
556 : IsBaseOf<nsISupports, mozilla::dom::FileList >::value,
557 : sNativePropertyHooks,
558 : FindAssociatedGlobalForNative<mozilla::dom::FileList>::Get,
559 : GetProtoObjectHandle,
560 : GetCCParticipant<mozilla::dom::FileList>::Get()
561 : };
562 :
563 : bool
564 0 : Wrap(JSContext* aCx, mozilla::dom::FileList* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
565 : {
566 : MOZ_ASSERT(static_cast<mozilla::dom::FileList*>(aObject) ==
567 : reinterpret_cast<mozilla::dom::FileList*>(aObject),
568 : "Multiple inheritance for mozilla::dom::FileList is broken.");
569 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
570 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
571 0 : MOZ_ASSERT(!aCache->GetWrapper(),
572 : "You should probably not be using Wrap() directly; use "
573 : "GetOrCreateDOMReflector instead");
574 :
575 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
576 : "nsISupports must be on our primary inheritance chain");
577 :
578 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
579 0 : if (!global) {
580 0 : return false;
581 : }
582 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
583 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
584 :
585 : // That might have ended up wrapping us already, due to the wonders
586 : // of XBL. Check for that, and bail out as needed.
587 0 : aReflector.set(aCache->GetWrapper());
588 0 : if (aReflector) {
589 : #ifdef DEBUG
590 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
591 : #endif // DEBUG
592 0 : return true;
593 : }
594 :
595 0 : JSAutoCompartment ac(aCx, global);
596 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
597 0 : if (!canonicalProto) {
598 0 : return false;
599 : }
600 0 : JS::Rooted<JSObject*> proto(aCx);
601 0 : if (aGivenProto) {
602 0 : proto = aGivenProto;
603 : // Unfortunately, while aGivenProto was in the compartment of aCx
604 : // coming in, we changed compartments to that of "parent" so may need
605 : // to wrap the proto here.
606 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
607 0 : if (!JS_WrapObject(aCx, &proto)) {
608 0 : return false;
609 : }
610 : }
611 : } else {
612 0 : proto = canonicalProto;
613 : }
614 :
615 0 : BindingJSObjectCreator<mozilla::dom::FileList> creator(aCx);
616 0 : JS::Rooted<JS::Value> expandoValue(aCx, JS::UndefinedValue());
617 0 : creator.CreateProxyObject(aCx, &sClass.mBase, DOMProxyHandler::getInstance(),
618 0 : proto, aObject, expandoValue, aReflector);
619 0 : if (!aReflector) {
620 0 : return false;
621 : }
622 :
623 :
624 0 : aCache->SetWrapper(aReflector);
625 0 : creator.InitializationSucceeded();
626 :
627 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
628 : aCache->GetWrapperPreserveColor() == aReflector);
629 : // If proto != canonicalProto, we have to preserve our wrapper;
630 : // otherwise we won't be able to properly recreate it later, since
631 : // we won't know what proto to use. Note that we don't check
632 : // aGivenProto here, since it's entirely possible (and even
633 : // somewhat common) to have a non-null aGivenProto which is the
634 : // same as canonicalProto.
635 0 : if (proto != canonicalProto) {
636 0 : PreserveWrapper(aObject);
637 : }
638 :
639 0 : return true;
640 : }
641 :
642 : static bool
643 0 : ResolveOwnProperty(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::MutableHandle<JS::PropertyDescriptor> desc)
644 : {
645 0 : return js::GetProxyHandler(obj)->getOwnPropertyDescriptor(cx, wrapper, id, desc);
646 : }
647 :
648 : static bool
649 0 : EnumerateOwnProperties(JSContext* cx, JS::Handle<JSObject*> wrapper, JS::Handle<JSObject*> obj, JS::AutoIdVector& props)
650 : {
651 0 : return js::GetProxyHandler(obj)->ownPropertyKeys(cx, wrapper, props);
652 : }
653 :
654 : const NativePropertyHooks sNativePropertyHooks[] = { {
655 : ResolveOwnProperty,
656 : EnumerateOwnProperties,
657 : nullptr,
658 : { sNativeProperties.Upcast(), nullptr },
659 : prototypes::id::FileList,
660 : constructors::id::FileList,
661 : nullptr,
662 : &DefaultXrayExpandoObjectClass
663 : } };
664 :
665 : void
666 1 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
667 : {
668 2 : JS::Rooted<JSObject*> parentProto(aCx, JS::GetRealmObjectPrototype(aCx));
669 1 : if (!parentProto) {
670 0 : return;
671 : }
672 :
673 2 : JS::Rooted<JSObject*> constructorProto(aCx, JS::GetRealmFunctionPrototype(aCx));
674 1 : if (!constructorProto) {
675 0 : return;
676 : }
677 :
678 : static bool sIdsInited = false;
679 1 : if (!sIdsInited && NS_IsMainThread()) {
680 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
681 0 : return;
682 : }
683 0 : sIdsInited = true;
684 : }
685 :
686 1 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::FileList);
687 1 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::FileList);
688 2 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
689 : &sPrototypeClass.mBase, protoCache,
690 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
691 : interfaceCache,
692 : sNativeProperties.Upcast(),
693 : nullptr,
694 : "FileList", aDefineOnGlobal,
695 : nullptr,
696 1 : false);
697 : }
698 :
699 : JS::Handle<JSObject*>
700 0 : GetProtoObjectHandle(JSContext* aCx)
701 : {
702 : /* Get the interface prototype object for this class. This will create the
703 : object as needed. */
704 0 : bool aDefineOnGlobal = true;
705 :
706 : /* Make sure our global is sane. Hopefully we can remove this sometime */
707 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
708 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
709 0 : return nullptr;
710 : }
711 :
712 : /* Check to see whether the interface objects are already installed */
713 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
714 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::FileList)) {
715 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
716 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
717 : }
718 :
719 : /*
720 : * The object might _still_ be null, but that's OK.
721 : *
722 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
723 : * traced by TraceProtoAndIfaceCache() and its contents are never
724 : * changed after they have been set.
725 : *
726 : * Calling address() avoids the read read barrier that does gray
727 : * unmarking, but it's not possible for the object to be gray here.
728 : */
729 :
730 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::FileList);
731 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
732 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
733 : }
734 :
735 : JS::Handle<JSObject*>
736 1 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
737 : {
738 : /* Get the interface object for this class. This will create the object as
739 : needed. */
740 :
741 : /* Make sure our global is sane. Hopefully we can remove this sometime */
742 1 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
743 1 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
744 0 : return nullptr;
745 : }
746 :
747 : /* Check to see whether the interface objects are already installed */
748 1 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
749 1 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::FileList)) {
750 2 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
751 1 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
752 : }
753 :
754 : /*
755 : * The object might _still_ be null, but that's OK.
756 : *
757 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
758 : * traced by TraceProtoAndIfaceCache() and its contents are never
759 : * changed after they have been set.
760 : *
761 : * Calling address() avoids the read read barrier that does gray
762 : * unmarking, but it's not possible for the object to be gray here.
763 : */
764 :
765 1 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::FileList);
766 1 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
767 1 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
768 : }
769 :
770 : JSObject*
771 1 : GetConstructorObject(JSContext* aCx)
772 : {
773 1 : return GetConstructorObjectHandle(aCx);
774 : }
775 :
776 : } // namespace FileListBinding
777 :
778 :
779 :
780 : } // namespace dom
781 : } // namespace mozilla
|