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