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