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