Line data Source code
1 : /* THIS FILE IS AUTOGENERATED FROM MediaSource.webidl BY Codegen.py - DO NOT EDIT */
2 :
3 : #include "EventHandlerBinding.h"
4 : #include "EventTargetBinding.h"
5 : #include "MediaSourceBinding.h"
6 : #include "WrapperFactory.h"
7 : #include "jsapi.h"
8 : #include "mozilla/FloatingPoint.h"
9 : #include "mozilla/OwningNonNull.h"
10 : #include "mozilla/dom/BindingUtils.h"
11 : #include "mozilla/dom/DOMJSClass.h"
12 : #include "mozilla/dom/MediaSource.h"
13 : #include "mozilla/dom/NonRefcountedDOMObject.h"
14 : #include "mozilla/dom/Nullable.h"
15 : #include "mozilla/dom/PrimitiveConversions.h"
16 : #include "mozilla/dom/SourceBuffer.h"
17 : #include "mozilla/dom/SourceBufferList.h"
18 : #include "mozilla/dom/XrayExpandoClass.h"
19 : #include "nsContentUtils.h"
20 :
21 : namespace mozilla {
22 : namespace dom {
23 :
24 : namespace MediaSourceReadyStateValues {
25 : extern const EnumEntry strings[4] = {
26 : {"closed", 6},
27 : {"open", 4},
28 : {"ended", 5},
29 : { nullptr, 0 }
30 : };
31 : } // namespace MediaSourceReadyStateValues
32 :
33 : bool
34 0 : ToJSValue(JSContext* aCx, MediaSourceReadyState aArgument, JS::MutableHandle<JS::Value> aValue)
35 : {
36 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaSourceReadyStateValues::strings));
37 : JSString* resultStr =
38 0 : JS_NewStringCopyN(aCx, MediaSourceReadyStateValues::strings[uint32_t(aArgument)].value,
39 0 : MediaSourceReadyStateValues::strings[uint32_t(aArgument)].length);
40 0 : if (!resultStr) {
41 0 : return false;
42 : }
43 0 : aValue.setString(resultStr);
44 0 : return true;
45 : }
46 :
47 :
48 : namespace MediaSourceEndOfStreamErrorValues {
49 : extern const EnumEntry strings[3] = {
50 : {"network", 7},
51 : {"decode", 6},
52 : { nullptr, 0 }
53 : };
54 : } // namespace MediaSourceEndOfStreamErrorValues
55 :
56 : bool
57 0 : ToJSValue(JSContext* aCx, MediaSourceEndOfStreamError aArgument, JS::MutableHandle<JS::Value> aValue)
58 : {
59 0 : MOZ_ASSERT(uint32_t(aArgument) < ArrayLength(MediaSourceEndOfStreamErrorValues::strings));
60 : JSString* resultStr =
61 0 : JS_NewStringCopyN(aCx, MediaSourceEndOfStreamErrorValues::strings[uint32_t(aArgument)].value,
62 0 : MediaSourceEndOfStreamErrorValues::strings[uint32_t(aArgument)].length);
63 0 : if (!resultStr) {
64 0 : return false;
65 : }
66 0 : aValue.setString(resultStr);
67 0 : return true;
68 : }
69 :
70 :
71 : namespace MediaSourceBinding {
72 :
73 : static_assert(IsRefcounted<NativeType>::value == IsRefcounted<EventTargetBinding::NativeType>::value,
74 : "Can't inherit from an interface with a different ownership model.");
75 :
76 : static bool
77 0 : get_sourceBuffers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
78 : {
79 0 : auto result(StrongOrRawPtr<mozilla::dom::SourceBufferList>(self->SourceBuffers()));
80 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
81 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
82 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
83 0 : return false;
84 : }
85 0 : return true;
86 : }
87 :
88 : static const JSJitInfo sourceBuffers_getterinfo = {
89 : { (JSJitGetterOp)get_sourceBuffers },
90 : { prototypes::id::MediaSource },
91 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
92 : JSJitInfo::Getter,
93 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
94 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
95 : false, /* isInfallible. False in setters. */
96 : false, /* isMovable. Not relevant for setters. */
97 : false, /* isEliminatable. Not relevant for setters. */
98 : false, /* isAlwaysInSlot. Only relevant for getters. */
99 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
100 : false, /* isTypedMethod. Only relevant for methods. */
101 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
102 : };
103 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
104 : static_assert(0 < 1, "There is no slot for us");
105 :
106 : static bool
107 0 : get_activeSourceBuffers(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
108 : {
109 0 : auto result(StrongOrRawPtr<mozilla::dom::SourceBufferList>(self->ActiveSourceBuffers()));
110 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
111 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
112 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
113 0 : return false;
114 : }
115 0 : return true;
116 : }
117 :
118 : static const JSJitInfo activeSourceBuffers_getterinfo = {
119 : { (JSJitGetterOp)get_activeSourceBuffers },
120 : { prototypes::id::MediaSource },
121 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
122 : JSJitInfo::Getter,
123 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
124 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
125 : false, /* isInfallible. False in setters. */
126 : false, /* isMovable. Not relevant for setters. */
127 : false, /* isEliminatable. Not relevant for setters. */
128 : false, /* isAlwaysInSlot. Only relevant for getters. */
129 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
130 : false, /* isTypedMethod. Only relevant for methods. */
131 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
132 : };
133 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
134 : static_assert(0 < 1, "There is no slot for us");
135 :
136 : static bool
137 0 : get_readyState(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
138 : {
139 0 : MediaSourceReadyState result(self->ReadyState());
140 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
141 0 : if (!ToJSValue(cx, result, args.rval())) {
142 0 : return false;
143 : }
144 0 : return true;
145 : }
146 :
147 : static const JSJitInfo readyState_getterinfo = {
148 : { (JSJitGetterOp)get_readyState },
149 : { prototypes::id::MediaSource },
150 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
151 : JSJitInfo::Getter,
152 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
153 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
154 : false, /* isInfallible. False in setters. */
155 : false, /* isMovable. Not relevant for setters. */
156 : false, /* isEliminatable. Not relevant for setters. */
157 : false, /* isAlwaysInSlot. Only relevant for getters. */
158 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
159 : false, /* isTypedMethod. Only relevant for methods. */
160 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
161 : };
162 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
163 : static_assert(0 < 1, "There is no slot for us");
164 :
165 : static bool
166 0 : get_duration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
167 : {
168 0 : double result(self->Duration());
169 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
170 0 : args.rval().set(JS_NumberValue(double(result)));
171 0 : return true;
172 : }
173 :
174 : static bool
175 0 : set_duration(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitSetterCallArgs args)
176 : {
177 : double arg0;
178 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
179 0 : return false;
180 : }
181 0 : binding_detail::FastErrorResult rv;
182 0 : self->SetDuration(arg0, rv);
183 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
184 0 : return false;
185 : }
186 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
187 :
188 0 : return true;
189 : }
190 :
191 : static const JSJitInfo duration_getterinfo = {
192 : { (JSJitGetterOp)get_duration },
193 : { prototypes::id::MediaSource },
194 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
195 : JSJitInfo::Getter,
196 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
197 : JSVAL_TYPE_DOUBLE, /* returnType. Not relevant for setters. */
198 : true, /* isInfallible. False in setters. */
199 : false, /* isMovable. Not relevant for setters. */
200 : false, /* isEliminatable. Not relevant for setters. */
201 : false, /* isAlwaysInSlot. Only relevant for getters. */
202 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
203 : false, /* isTypedMethod. Only relevant for methods. */
204 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
205 : };
206 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
207 : static_assert(0 < 1, "There is no slot for us");
208 : static const JSJitInfo duration_setterinfo = {
209 : { (JSJitGetterOp)set_duration },
210 : { prototypes::id::MediaSource },
211 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
212 : JSJitInfo::Setter,
213 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
214 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
215 : false, /* isInfallible. False in setters. */
216 : false, /* isMovable. Not relevant for setters. */
217 : false, /* isEliminatable. Not relevant for setters. */
218 : false, /* isAlwaysInSlot. Only relevant for getters. */
219 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
220 : false, /* isTypedMethod. Only relevant for methods. */
221 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
222 : };
223 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
224 : static_assert(0 < 1, "There is no slot for us");
225 :
226 : static bool
227 0 : get_onsourceopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
228 : {
229 0 : RefPtr<EventHandlerNonNull> result(self->GetOnsourceopen());
230 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
231 0 : if (result) {
232 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
233 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
234 0 : return false;
235 : }
236 0 : return true;
237 : } else {
238 0 : args.rval().setNull();
239 0 : return true;
240 : }
241 : }
242 :
243 : static bool
244 0 : set_onsourceopen(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitSetterCallArgs args)
245 : {
246 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
247 0 : if (args[0].isObject()) {
248 : { // scope for tempRoot
249 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
250 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
251 : }
252 : } else {
253 0 : arg0 = nullptr;
254 : }
255 0 : self->SetOnsourceopen(Constify(arg0));
256 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
257 :
258 0 : return true;
259 : }
260 :
261 : static const JSJitInfo onsourceopen_getterinfo = {
262 : { (JSJitGetterOp)get_onsourceopen },
263 : { prototypes::id::MediaSource },
264 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
265 : JSJitInfo::Getter,
266 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
267 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
268 : false, /* isInfallible. False in setters. */
269 : false, /* isMovable. Not relevant for setters. */
270 : false, /* isEliminatable. Not relevant for setters. */
271 : false, /* isAlwaysInSlot. Only relevant for getters. */
272 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
273 : false, /* isTypedMethod. Only relevant for methods. */
274 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
275 : };
276 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
277 : static_assert(0 < 1, "There is no slot for us");
278 : static const JSJitInfo onsourceopen_setterinfo = {
279 : { (JSJitGetterOp)set_onsourceopen },
280 : { prototypes::id::MediaSource },
281 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
282 : JSJitInfo::Setter,
283 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
284 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
285 : false, /* isInfallible. False in setters. */
286 : false, /* isMovable. Not relevant for setters. */
287 : false, /* isEliminatable. Not relevant for setters. */
288 : false, /* isAlwaysInSlot. Only relevant for getters. */
289 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
290 : false, /* isTypedMethod. Only relevant for methods. */
291 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
292 : };
293 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
294 : static_assert(0 < 1, "There is no slot for us");
295 :
296 : static bool
297 0 : get_onsourceended(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
298 : {
299 0 : RefPtr<EventHandlerNonNull> result(self->GetOnsourceended());
300 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
301 0 : if (result) {
302 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
303 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
304 0 : return false;
305 : }
306 0 : return true;
307 : } else {
308 0 : args.rval().setNull();
309 0 : return true;
310 : }
311 : }
312 :
313 : static bool
314 0 : set_onsourceended(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitSetterCallArgs args)
315 : {
316 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
317 0 : if (args[0].isObject()) {
318 : { // scope for tempRoot
319 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
320 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
321 : }
322 : } else {
323 0 : arg0 = nullptr;
324 : }
325 0 : self->SetOnsourceended(Constify(arg0));
326 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
327 :
328 0 : return true;
329 : }
330 :
331 : static const JSJitInfo onsourceended_getterinfo = {
332 : { (JSJitGetterOp)get_onsourceended },
333 : { prototypes::id::MediaSource },
334 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
335 : JSJitInfo::Getter,
336 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
337 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
338 : false, /* isInfallible. False in setters. */
339 : false, /* isMovable. Not relevant for setters. */
340 : false, /* isEliminatable. Not relevant for setters. */
341 : false, /* isAlwaysInSlot. Only relevant for getters. */
342 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
343 : false, /* isTypedMethod. Only relevant for methods. */
344 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
345 : };
346 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
347 : static_assert(0 < 1, "There is no slot for us");
348 : static const JSJitInfo onsourceended_setterinfo = {
349 : { (JSJitGetterOp)set_onsourceended },
350 : { prototypes::id::MediaSource },
351 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
352 : JSJitInfo::Setter,
353 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
354 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
355 : false, /* isInfallible. False in setters. */
356 : false, /* isMovable. Not relevant for setters. */
357 : false, /* isEliminatable. Not relevant for setters. */
358 : false, /* isAlwaysInSlot. Only relevant for getters. */
359 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
360 : false, /* isTypedMethod. Only relevant for methods. */
361 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
362 : };
363 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
364 : static_assert(0 < 1, "There is no slot for us");
365 :
366 : static bool
367 0 : get_onsourceclosed(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
368 : {
369 0 : RefPtr<EventHandlerNonNull> result(self->GetOnsourceclosed());
370 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
371 0 : if (result) {
372 0 : args.rval().setObjectOrNull(GetCallbackFromCallbackObject(result));
373 0 : if (!MaybeWrapObjectOrNullValue(cx, args.rval())) {
374 0 : return false;
375 : }
376 0 : return true;
377 : } else {
378 0 : args.rval().setNull();
379 0 : return true;
380 : }
381 : }
382 :
383 : static bool
384 0 : set_onsourceclosed(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitSetterCallArgs args)
385 : {
386 0 : RootedCallback<RefPtr<binding_detail::FastEventHandlerNonNull>> arg0(cx);
387 0 : if (args[0].isObject()) {
388 : { // scope for tempRoot
389 0 : JS::Rooted<JSObject*> tempRoot(cx, &args[0].toObject());
390 0 : arg0 = new binding_detail::FastEventHandlerNonNull(tempRoot);
391 : }
392 : } else {
393 0 : arg0 = nullptr;
394 : }
395 0 : self->SetOnsourceclosed(Constify(arg0));
396 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
397 :
398 0 : return true;
399 : }
400 :
401 : static const JSJitInfo onsourceclosed_getterinfo = {
402 : { (JSJitGetterOp)get_onsourceclosed },
403 : { prototypes::id::MediaSource },
404 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
405 : JSJitInfo::Getter,
406 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
407 : JSVAL_TYPE_UNKNOWN, /* returnType. Not relevant for setters. */
408 : false, /* isInfallible. False in setters. */
409 : false, /* isMovable. Not relevant for setters. */
410 : false, /* isEliminatable. Not relevant for setters. */
411 : false, /* isAlwaysInSlot. Only relevant for getters. */
412 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
413 : false, /* isTypedMethod. Only relevant for methods. */
414 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
415 : };
416 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
417 : static_assert(0 < 1, "There is no slot for us");
418 : static const JSJitInfo onsourceclosed_setterinfo = {
419 : { (JSJitGetterOp)set_onsourceclosed },
420 : { prototypes::id::MediaSource },
421 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
422 : JSJitInfo::Setter,
423 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
424 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
425 : false, /* isInfallible. False in setters. */
426 : false, /* isMovable. Not relevant for setters. */
427 : false, /* isEliminatable. Not relevant for setters. */
428 : false, /* isAlwaysInSlot. Only relevant for getters. */
429 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
430 : false, /* isTypedMethod. Only relevant for methods. */
431 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
432 : };
433 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
434 : static_assert(0 < 1, "There is no slot for us");
435 :
436 : static bool
437 0 : addSourceBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, const JSJitMethodCallArgs& args)
438 : {
439 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
440 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaSource.addSourceBuffer");
441 : }
442 0 : binding_detail::FakeString arg0;
443 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
444 0 : return false;
445 : }
446 0 : binding_detail::FastErrorResult rv;
447 0 : auto result(StrongOrRawPtr<mozilla::dom::SourceBuffer>(self->AddSourceBuffer(NonNullHelper(Constify(arg0)), rv)));
448 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
449 0 : return false;
450 : }
451 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
452 : static_assert(!IsPointer<decltype(result)>::value,
453 : "NewObject implies that we need to keep the object alive with a strong reference.");
454 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval())) {
455 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
456 0 : return false;
457 : }
458 0 : return true;
459 : }
460 :
461 : static const JSJitInfo addSourceBuffer_methodinfo = {
462 : { (JSJitGetterOp)addSourceBuffer },
463 : { prototypes::id::MediaSource },
464 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
465 : JSJitInfo::Method,
466 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
467 : JSVAL_TYPE_OBJECT, /* returnType. Not relevant for setters. */
468 : false, /* isInfallible. False in setters. */
469 : false, /* isMovable. Not relevant for setters. */
470 : false, /* isEliminatable. Not relevant for setters. */
471 : false, /* isAlwaysInSlot. Only relevant for getters. */
472 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
473 : false, /* isTypedMethod. Only relevant for methods. */
474 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
475 : };
476 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
477 : static_assert(0 < 1, "There is no slot for us");
478 :
479 : static bool
480 0 : removeSourceBuffer(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, const JSJitMethodCallArgs& args)
481 : {
482 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
483 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaSource.removeSourceBuffer");
484 : }
485 0 : NonNull<mozilla::dom::SourceBuffer> arg0;
486 0 : if (args[0].isObject()) {
487 : {
488 0 : nsresult rv = UnwrapObject<prototypes::id::SourceBuffer, mozilla::dom::SourceBuffer>(args[0], arg0);
489 0 : if (NS_FAILED(rv)) {
490 0 : ThrowErrorMessage(cx, MSG_DOES_NOT_IMPLEMENT_INTERFACE, "Argument 1 of MediaSource.removeSourceBuffer", "SourceBuffer");
491 0 : return false;
492 : }
493 : }
494 : } else {
495 0 : ThrowErrorMessage(cx, MSG_NOT_OBJECT, "Argument 1 of MediaSource.removeSourceBuffer");
496 0 : return false;
497 : }
498 0 : binding_detail::FastErrorResult rv;
499 0 : self->RemoveSourceBuffer(NonNullHelper(arg0), rv);
500 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
501 0 : return false;
502 : }
503 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
504 0 : args.rval().setUndefined();
505 0 : return true;
506 : }
507 :
508 : static const JSJitInfo removeSourceBuffer_methodinfo = {
509 : { (JSJitGetterOp)removeSourceBuffer },
510 : { prototypes::id::MediaSource },
511 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
512 : JSJitInfo::Method,
513 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
514 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
515 : false, /* isInfallible. False in setters. */
516 : false, /* isMovable. Not relevant for setters. */
517 : false, /* isEliminatable. Not relevant for setters. */
518 : false, /* isAlwaysInSlot. Only relevant for getters. */
519 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
520 : false, /* isTypedMethod. Only relevant for methods. */
521 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
522 : };
523 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
524 : static_assert(0 < 1, "There is no slot for us");
525 :
526 : static bool
527 0 : endOfStream(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, const JSJitMethodCallArgs& args)
528 : {
529 0 : Optional<MediaSourceEndOfStreamError> arg0;
530 0 : if (args.hasDefined(0)) {
531 0 : arg0.Construct();
532 : {
533 : int index;
534 0 : if (!FindEnumStringIndex<true>(cx, args[0], MediaSourceEndOfStreamErrorValues::strings, "MediaSourceEndOfStreamError", "Argument 1 of MediaSource.endOfStream", &index)) {
535 0 : return false;
536 : }
537 0 : MOZ_ASSERT(index >= 0);
538 0 : arg0.Value() = static_cast<MediaSourceEndOfStreamError>(index);
539 : }
540 : }
541 0 : binding_detail::FastErrorResult rv;
542 0 : self->EndOfStream(Constify(arg0), rv);
543 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
544 0 : return false;
545 : }
546 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
547 0 : args.rval().setUndefined();
548 0 : return true;
549 : }
550 :
551 : static const JSJitInfo endOfStream_methodinfo = {
552 : { (JSJitGetterOp)endOfStream },
553 : { prototypes::id::MediaSource },
554 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
555 : JSJitInfo::Method,
556 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
557 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
558 : false, /* isInfallible. False in setters. */
559 : false, /* isMovable. Not relevant for setters. */
560 : false, /* isEliminatable. Not relevant for setters. */
561 : false, /* isAlwaysInSlot. Only relevant for getters. */
562 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
563 : false, /* isTypedMethod. Only relevant for methods. */
564 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
565 : };
566 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
567 : static_assert(0 < 1, "There is no slot for us");
568 :
569 : static bool
570 0 : setLiveSeekableRange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, const JSJitMethodCallArgs& args)
571 : {
572 0 : if (MOZ_UNLIKELY(args.length() < 2)) {
573 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaSource.setLiveSeekableRange");
574 : }
575 : double arg0;
576 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[0], &arg0)) {
577 0 : return false;
578 0 : } else if (!mozilla::IsFinite(arg0)) {
579 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 1 of MediaSource.setLiveSeekableRange");
580 0 : return false;
581 : }
582 : double arg1;
583 0 : if (!ValueToPrimitive<double, eDefault>(cx, args[1], &arg1)) {
584 0 : return false;
585 0 : } else if (!mozilla::IsFinite(arg1)) {
586 0 : ThrowErrorMessage(cx, MSG_NOT_FINITE, "Argument 2 of MediaSource.setLiveSeekableRange");
587 0 : return false;
588 : }
589 0 : binding_detail::FastErrorResult rv;
590 0 : self->SetLiveSeekableRange(arg0, arg1, rv);
591 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
592 0 : return false;
593 : }
594 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
595 0 : args.rval().setUndefined();
596 0 : return true;
597 : }
598 :
599 : static const JSJitInfo setLiveSeekableRange_methodinfo = {
600 : { (JSJitGetterOp)setLiveSeekableRange },
601 : { prototypes::id::MediaSource },
602 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
603 : JSJitInfo::Method,
604 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
605 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
606 : false, /* isInfallible. False in setters. */
607 : false, /* isMovable. Not relevant for setters. */
608 : false, /* isEliminatable. Not relevant for setters. */
609 : false, /* isAlwaysInSlot. Only relevant for getters. */
610 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
611 : false, /* isTypedMethod. Only relevant for methods. */
612 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
613 : };
614 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
615 : static_assert(0 < 1, "There is no slot for us");
616 :
617 : static bool
618 0 : clearLiveSeekableRange(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, const JSJitMethodCallArgs& args)
619 : {
620 0 : binding_detail::FastErrorResult rv;
621 0 : self->ClearLiveSeekableRange(rv);
622 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
623 0 : return false;
624 : }
625 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
626 0 : args.rval().setUndefined();
627 0 : return true;
628 : }
629 :
630 : static const JSJitInfo clearLiveSeekableRange_methodinfo = {
631 : { (JSJitGetterOp)clearLiveSeekableRange },
632 : { prototypes::id::MediaSource },
633 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
634 : JSJitInfo::Method,
635 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
636 : JSVAL_TYPE_UNDEFINED, /* returnType. Not relevant for setters. */
637 : false, /* isInfallible. False in setters. */
638 : false, /* isMovable. Not relevant for setters. */
639 : false, /* isEliminatable. Not relevant for setters. */
640 : false, /* isAlwaysInSlot. Only relevant for getters. */
641 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
642 : false, /* isTypedMethod. Only relevant for methods. */
643 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
644 : };
645 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
646 : static_assert(0 < 1, "There is no slot for us");
647 :
648 : static bool
649 0 : isTypeSupported(JSContext* cx, unsigned argc, JS::Value* vp)
650 : {
651 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
652 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
653 :
654 0 : if (MOZ_UNLIKELY(args.length() < 1)) {
655 0 : return ThrowErrorMessage(cx, MSG_MISSING_ARGUMENTS, "MediaSource.isTypeSupported");
656 : }
657 0 : GlobalObject global(cx, xpc::XrayAwareCalleeGlobal(obj));
658 0 : if (global.Failed()) {
659 0 : return false;
660 : }
661 :
662 0 : binding_detail::FakeString arg0;
663 0 : if (!ConvertJSValueToString(cx, args[0], eStringify, eStringify, arg0)) {
664 0 : return false;
665 : }
666 0 : bool result(mozilla::dom::MediaSource::IsTypeSupported(global, NonNullHelper(Constify(arg0))));
667 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
668 0 : args.rval().setBoolean(result);
669 0 : return true;
670 : }
671 :
672 : static bool
673 0 : get_mozDebugReaderData(JSContext* cx, JS::Handle<JSObject*> obj, mozilla::dom::MediaSource* self, JSJitGetterCallArgs args)
674 : {
675 0 : DOMString result;
676 0 : self->GetMozDebugReaderData(result);
677 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
678 0 : if (!xpc::NonVoidStringToJsval(cx, result, args.rval())) {
679 0 : return false;
680 : }
681 0 : return true;
682 : }
683 :
684 : static const JSJitInfo mozDebugReaderData_getterinfo = {
685 : { (JSJitGetterOp)get_mozDebugReaderData },
686 : { prototypes::id::MediaSource },
687 : { PrototypeTraits<prototypes::id::MediaSource>::Depth },
688 : JSJitInfo::Getter,
689 : JSJitInfo::AliasEverything, /* aliasSet. Not relevant for setters. */
690 : JSVAL_TYPE_STRING, /* returnType. Not relevant for setters. */
691 : false, /* isInfallible. False in setters. */
692 : false, /* isMovable. Not relevant for setters. */
693 : false, /* isEliminatable. Not relevant for setters. */
694 : false, /* isAlwaysInSlot. Only relevant for getters. */
695 : false, /* isLazilyCachedInSlot. Only relevant for getters. */
696 : false, /* isTypedMethod. Only relevant for methods. */
697 : 0 /* Reserved slot index, if we're stored in a slot, else 0. */
698 : };
699 : static_assert(0 <= JSJitInfo::maxSlotIndex, "We won't fit");
700 : static_assert(0 < 1, "There is no slot for us");
701 :
702 : static bool
703 0 : _addProperty(JSContext* cx, JS::Handle<JSObject*> obj, JS::Handle<jsid> id, JS::Handle<JS::Value> val)
704 : {
705 0 : mozilla::dom::MediaSource* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaSource>(obj);
706 : // We don't want to preserve if we don't have a wrapper, and we
707 : // obviously can't preserve if we're not initialized.
708 0 : if (self && self->GetWrapperPreserveColor()) {
709 0 : PreserveWrapper(self);
710 : }
711 0 : return true;
712 : }
713 :
714 : static void
715 0 : _finalize(js::FreeOp* fop, JSObject* obj)
716 : {
717 0 : mozilla::dom::MediaSource* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaSource>(obj);
718 0 : if (self) {
719 0 : ClearWrapper(self, self, obj);
720 0 : AddForDeferredFinalization<mozilla::dom::MediaSource>(self);
721 : }
722 0 : }
723 :
724 : static void
725 0 : _objectMoved(JSObject* obj, const JSObject* old)
726 : {
727 0 : mozilla::dom::MediaSource* self = UnwrapPossiblyNotInitializedDOMObject<mozilla::dom::MediaSource>(obj);
728 0 : if (self) {
729 0 : UpdateWrapper(self, self, obj, old);
730 : }
731 0 : }
732 :
733 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
734 : #if defined(__clang__)
735 : #pragma clang diagnostic push
736 : #pragma clang diagnostic ignored "-Wmissing-braces"
737 : #endif
738 : static const JSFunctionSpec sStaticMethods_specs[] = {
739 : JS_FNSPEC("isTypeSupported", isTypeSupported, nullptr, 1, JSPROP_ENUMERATE, nullptr),
740 : JS_FS_END
741 : };
742 : #if defined(__clang__)
743 : #pragma clang diagnostic pop
744 : #endif
745 :
746 :
747 : // Can't be const because the pref-enabled boolean needs to be writable
748 : static Prefable<const JSFunctionSpec> sStaticMethods[] = {
749 : { nullptr, &sStaticMethods_specs[0] },
750 : { nullptr, nullptr }
751 : };
752 :
753 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
754 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
755 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
756 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
757 :
758 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
759 : #if defined(__clang__)
760 : #pragma clang diagnostic push
761 : #pragma clang diagnostic ignored "-Wmissing-braces"
762 : #endif
763 : static const JSFunctionSpec sMethods_specs[] = {
764 : JS_FNSPEC("addSourceBuffer", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&addSourceBuffer_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
765 : JS_FNSPEC("removeSourceBuffer", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&removeSourceBuffer_methodinfo), 1, JSPROP_ENUMERATE, nullptr),
766 : JS_FNSPEC("endOfStream", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&endOfStream_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
767 : JS_FNSPEC("setLiveSeekableRange", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&setLiveSeekableRange_methodinfo), 2, JSPROP_ENUMERATE, nullptr),
768 : JS_FNSPEC("clearLiveSeekableRange", GenericBindingMethod, reinterpret_cast<const JSJitInfo*>(&clearLiveSeekableRange_methodinfo), 0, JSPROP_ENUMERATE, nullptr),
769 : JS_FS_END
770 : };
771 : #if defined(__clang__)
772 : #pragma clang diagnostic pop
773 : #endif
774 :
775 :
776 : // Can't be const because the pref-enabled boolean needs to be writable
777 : static Prefable<const JSFunctionSpec> sMethods[] = {
778 : { nullptr, &sMethods_specs[0] },
779 : { nullptr, nullptr }
780 : };
781 :
782 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
783 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
784 : static_assert(5 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
785 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
786 :
787 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
788 : #if defined(__clang__)
789 : #pragma clang diagnostic push
790 : #pragma clang diagnostic ignored "-Wmissing-braces"
791 : #endif
792 : static const JSPropertySpec sAttributes_specs[] = {
793 : { "sourceBuffers", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &sourceBuffers_getterinfo, nullptr, nullptr },
794 : { "activeSourceBuffers", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &activeSourceBuffers_getterinfo, nullptr, nullptr },
795 : { "readyState", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &readyState_getterinfo, nullptr, nullptr },
796 : { "duration", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &duration_getterinfo, GenericBindingSetter, &duration_setterinfo },
797 : { "onsourceopen", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onsourceopen_getterinfo, GenericBindingSetter, &onsourceopen_setterinfo },
798 : { "onsourceended", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onsourceended_getterinfo, GenericBindingSetter, &onsourceended_setterinfo },
799 : { "onsourceclosed", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &onsourceclosed_getterinfo, GenericBindingSetter, &onsourceclosed_setterinfo },
800 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
801 : };
802 : #if defined(__clang__)
803 : #pragma clang diagnostic pop
804 : #endif
805 :
806 :
807 : // Can't be const because the pref-enabled boolean needs to be writable
808 : static Prefable<const JSPropertySpec> sAttributes[] = {
809 : { nullptr, &sAttributes_specs[0] },
810 : { nullptr, nullptr }
811 : };
812 :
813 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
814 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
815 : static_assert(7 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
816 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
817 :
818 : // We deliberately use brace-elision to make Visual Studio produce better initalization code.
819 : #if defined(__clang__)
820 : #pragma clang diagnostic push
821 : #pragma clang diagnostic ignored "-Wmissing-braces"
822 : #endif
823 : static const JSPropertySpec sChromeAttributes_specs[] = {
824 : { "mozDebugReaderData", JSPROP_SHARED | JSPROP_ENUMERATE, GenericBindingGetter, &mozDebugReaderData_getterinfo, nullptr, nullptr },
825 : { nullptr, 0, nullptr, nullptr, nullptr, nullptr }
826 : };
827 : #if defined(__clang__)
828 : #pragma clang diagnostic pop
829 : #endif
830 :
831 :
832 : // Can't be const because the pref-enabled boolean needs to be writable
833 : static Prefable<const JSPropertySpec> sChromeAttributes[] = {
834 : { nullptr, &sChromeAttributes_specs[0] },
835 : { nullptr, nullptr }
836 : };
837 :
838 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_PREF_INDEX,
839 : "We have a prefable index that is >= (1 << NUM_BITS_PROPERTY_INFO_PREF_INDEX)");
840 : static_assert(1 <= 1ull << NUM_BITS_PROPERTY_INFO_SPEC_INDEX,
841 : "We have a spec index that is >= (1 << NUM_BITS_PROPERTY_INFO_SPEC_INDEX)");
842 :
843 :
844 : static uint16_t sNativeProperties_sortedPropertyIndices[13];
845 : static PropertyInfo sNativeProperties_propertyInfos[13];
846 :
847 : static const NativePropertiesN<3> sNativeProperties = {
848 : true, 0 /* sStaticMethods */,
849 : false, 0,
850 : true, 1 /* sMethods */,
851 : true, 2 /* sAttributes */,
852 : false, 0,
853 : false, 0,
854 : false, 0,
855 : -1,
856 : 13,
857 : sNativeProperties_sortedPropertyIndices,
858 : {
859 : { sStaticMethods, &sNativeProperties_propertyInfos[0] },
860 : { sMethods, &sNativeProperties_propertyInfos[1] },
861 : { sAttributes, &sNativeProperties_propertyInfos[6] }
862 : }
863 : };
864 : static_assert(13 < 1ull << CHAR_BIT * sizeof(sNativeProperties.propertyInfoCount),
865 : "We have a property info count that is oversized");
866 :
867 : static uint16_t sChromeOnlyNativeProperties_sortedPropertyIndices[1];
868 : static PropertyInfo sChromeOnlyNativeProperties_propertyInfos[1];
869 :
870 : static const NativePropertiesN<1> sChromeOnlyNativeProperties = {
871 : false, 0,
872 : false, 0,
873 : false, 0,
874 : true, 0 /* sChromeAttributes */,
875 : false, 0,
876 : false, 0,
877 : false, 0,
878 : -1,
879 : 1,
880 : sChromeOnlyNativeProperties_sortedPropertyIndices,
881 : {
882 : { sChromeAttributes, &sChromeOnlyNativeProperties_propertyInfos[0] }
883 : }
884 : };
885 : static_assert(1 < 1ull << CHAR_BIT * sizeof(sChromeOnlyNativeProperties.propertyInfoCount),
886 : "We have a property info count that is oversized");
887 :
888 : static bool
889 0 : _constructor(JSContext* cx, unsigned argc, JS::Value* vp)
890 : {
891 0 : JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
892 0 : JS::Rooted<JSObject*> obj(cx, &args.callee());
893 0 : if (!args.isConstructing()) {
894 : // XXXbz wish I could get the name from the callee instead of
895 : // Adding more relocations
896 0 : return ThrowConstructorWithoutNew(cx, "MediaSource");
897 : }
898 :
899 0 : GlobalObject global(cx, obj);
900 0 : if (global.Failed()) {
901 0 : return false;
902 : }
903 :
904 0 : JS::Rooted<JSObject*> desiredProto(cx);
905 0 : if (!GetDesiredProto(cx, args, &desiredProto)) {
906 0 : return false;
907 : }
908 :
909 0 : bool objIsXray = xpc::WrapperFactory::IsXrayWrapper(obj);
910 0 : Maybe<JSAutoCompartment> ac;
911 0 : if (objIsXray) {
912 0 : obj = js::CheckedUnwrap(obj);
913 0 : if (!obj) {
914 0 : return false;
915 : }
916 0 : ac.emplace(cx, obj);
917 0 : if (!JS_WrapObject(cx, &desiredProto)) {
918 0 : return false;
919 : }
920 : }
921 0 : binding_detail::FastErrorResult rv;
922 0 : auto result(StrongOrRawPtr<mozilla::dom::MediaSource>(mozilla::dom::MediaSource::Constructor(global, rv)));
923 0 : if (MOZ_UNLIKELY(rv.MaybeSetPendingException(cx))) {
924 0 : return false;
925 : }
926 0 : MOZ_ASSERT(!JS_IsExceptionPending(cx));
927 : static_assert(!IsPointer<decltype(result)>::value,
928 : "NewObject implies that we need to keep the object alive with a strong reference.");
929 0 : if (!GetOrCreateDOMReflector(cx, result, args.rval(), desiredProto)) {
930 0 : MOZ_ASSERT(true || JS_IsExceptionPending(cx));
931 0 : return false;
932 : }
933 0 : return true;
934 : }
935 :
936 : static const js::ClassOps sInterfaceObjectClassOps = {
937 : nullptr, /* addProperty */
938 : nullptr, /* delProperty */
939 : nullptr, /* getProperty */
940 : nullptr, /* setProperty */
941 : nullptr, /* enumerate */
942 : nullptr, /* newEnumerate */
943 : nullptr, /* resolve */
944 : nullptr, /* mayResolve */
945 : nullptr, /* finalize */
946 : _constructor, /* call */
947 : nullptr, /* hasInstance */
948 : _constructor, /* construct */
949 : nullptr, /* trace */
950 : };
951 :
952 : static const DOMIfaceAndProtoJSClass sInterfaceObjectClass = {
953 : {
954 : "Function",
955 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_SLOTS_BASE),
956 : &sInterfaceObjectClassOps,
957 : JS_NULL_CLASS_SPEC,
958 : JS_NULL_CLASS_EXT,
959 : &sInterfaceObjectClassObjectOps
960 : },
961 : eInterface,
962 : true,
963 : prototypes::id::MediaSource,
964 : PrototypeTraits<prototypes::id::MediaSource>::Depth,
965 : sNativePropertyHooks,
966 : "function MediaSource() {\n [native code]\n}",
967 : EventTargetBinding::GetConstructorObject
968 : };
969 :
970 : static const DOMIfaceAndProtoJSClass sPrototypeClass = {
971 : {
972 : "MediaSourcePrototype",
973 : JSCLASS_IS_DOMIFACEANDPROTOJSCLASS | JSCLASS_HAS_RESERVED_SLOTS(DOM_INTERFACE_PROTO_SLOTS_BASE),
974 : JS_NULL_CLASS_OPS,
975 : JS_NULL_CLASS_SPEC,
976 : JS_NULL_CLASS_EXT,
977 : JS_NULL_OBJECT_OPS
978 : },
979 : eInterfacePrototype,
980 : false,
981 : prototypes::id::MediaSource,
982 : PrototypeTraits<prototypes::id::MediaSource>::Depth,
983 : sNativePropertyHooks,
984 : "[object MediaSourcePrototype]",
985 : EventTargetBinding::GetProtoObject
986 : };
987 :
988 : bool
989 0 : ConstructorEnabled(JSContext* aCx, JS::Handle<JSObject*> aObj)
990 : {
991 0 : return mozilla::dom::MediaSource::Enabled(aCx, aObj);
992 : }
993 :
994 : JSObject*
995 0 : DefineDOMInterface(JSContext* aCx, JS::Handle<JSObject*> aGlobal, JS::Handle<jsid> id, bool aDefineOnGlobal)
996 : {
997 0 : return GetConstructorObjectHandle(aCx, aDefineOnGlobal);
998 : }
999 :
1000 : static const js::ClassOps sClassOps = {
1001 : _addProperty, /* addProperty */
1002 : nullptr, /* delProperty */
1003 : nullptr, /* getProperty */
1004 : nullptr, /* setProperty */
1005 : nullptr, /* enumerate */
1006 : nullptr, /* newEnumerate */
1007 : nullptr, /* resolve */
1008 : nullptr, /* mayResolve */
1009 : _finalize, /* finalize */
1010 : nullptr, /* call */
1011 : nullptr, /* hasInstance */
1012 : nullptr, /* construct */
1013 : nullptr, /* trace */
1014 : };
1015 :
1016 : static const js::ClassExtension sClassExtension = {
1017 : nullptr, /* weakmapKeyDelegateOp */
1018 : _objectMoved /* objectMovedOp */
1019 : };
1020 :
1021 : static const DOMJSClass sClass = {
1022 : { "MediaSource",
1023 : JSCLASS_IS_DOMJSCLASS | JSCLASS_FOREGROUND_FINALIZE | JSCLASS_HAS_RESERVED_SLOTS(1),
1024 : &sClassOps,
1025 : JS_NULL_CLASS_SPEC,
1026 : &sClassExtension,
1027 : JS_NULL_OBJECT_OPS
1028 : },
1029 : { prototypes::id::EventTarget, prototypes::id::MediaSource, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count, prototypes::id::_ID_Count },
1030 : IsBaseOf<nsISupports, mozilla::dom::MediaSource >::value,
1031 : sNativePropertyHooks,
1032 : FindAssociatedGlobalForNative<mozilla::dom::MediaSource>::Get,
1033 : GetProtoObjectHandle,
1034 : GetCCParticipant<mozilla::dom::MediaSource>::Get()
1035 : };
1036 : static_assert(1 == DOM_INSTANCE_RESERVED_SLOTS,
1037 : "Must have the right minimal number of reserved slots.");
1038 : static_assert(1 >= 1,
1039 : "Must have enough reserved slots.");
1040 :
1041 : const JSClass*
1042 0 : GetJSClass()
1043 : {
1044 0 : return sClass.ToJSClass();
1045 : }
1046 :
1047 : bool
1048 0 : Wrap(JSContext* aCx, mozilla::dom::MediaSource* aObject, nsWrapperCache* aCache, JS::Handle<JSObject*> aGivenProto, JS::MutableHandle<JSObject*> aReflector)
1049 : {
1050 : MOZ_ASSERT(static_cast<mozilla::dom::MediaSource*>(aObject) ==
1051 : reinterpret_cast<mozilla::dom::MediaSource*>(aObject),
1052 : "Multiple inheritance for mozilla::dom::MediaSource is broken.");
1053 : MOZ_ASSERT(static_cast<mozilla::dom::EventTarget*>(aObject) ==
1054 : reinterpret_cast<mozilla::dom::EventTarget*>(aObject),
1055 : "Multiple inheritance for mozilla::dom::EventTarget is broken.");
1056 0 : MOZ_ASSERT(ToSupportsIsCorrect(aObject));
1057 0 : MOZ_ASSERT_IF(aGivenProto, js::IsObjectInContextCompartment(aGivenProto, aCx));
1058 0 : MOZ_ASSERT(!aCache->GetWrapper(),
1059 : "You should probably not be using Wrap() directly; use "
1060 : "GetOrCreateDOMReflector instead");
1061 :
1062 0 : MOZ_ASSERT(ToSupportsIsOnPrimaryInheritanceChain(aObject, aCache),
1063 : "nsISupports must be on our primary inheritance chain");
1064 :
1065 0 : JS::Rooted<JSObject*> global(aCx, FindAssociatedGlobal(aCx, aObject->GetParentObject()));
1066 0 : if (!global) {
1067 0 : return false;
1068 : }
1069 0 : MOZ_ASSERT(JS_IsGlobalObject(global));
1070 0 : MOZ_ASSERT(JS::ObjectIsNotGray(global));
1071 :
1072 : // That might have ended up wrapping us already, due to the wonders
1073 : // of XBL. Check for that, and bail out as needed.
1074 0 : aReflector.set(aCache->GetWrapper());
1075 0 : if (aReflector) {
1076 : #ifdef DEBUG
1077 0 : binding_detail::AssertReflectorHasGivenProto(aCx, aReflector, aGivenProto);
1078 : #endif // DEBUG
1079 0 : return true;
1080 : }
1081 :
1082 0 : JSAutoCompartment ac(aCx, global);
1083 0 : JS::Handle<JSObject*> canonicalProto = GetProtoObjectHandle(aCx);
1084 0 : if (!canonicalProto) {
1085 0 : return false;
1086 : }
1087 0 : JS::Rooted<JSObject*> proto(aCx);
1088 0 : if (aGivenProto) {
1089 0 : proto = aGivenProto;
1090 : // Unfortunately, while aGivenProto was in the compartment of aCx
1091 : // coming in, we changed compartments to that of "parent" so may need
1092 : // to wrap the proto here.
1093 0 : if (js::GetContextCompartment(aCx) != js::GetObjectCompartment(proto)) {
1094 0 : if (!JS_WrapObject(aCx, &proto)) {
1095 0 : return false;
1096 : }
1097 : }
1098 : } else {
1099 0 : proto = canonicalProto;
1100 : }
1101 :
1102 0 : BindingJSObjectCreator<mozilla::dom::MediaSource> creator(aCx);
1103 0 : creator.CreateObject(aCx, sClass.ToJSClass(), proto, aObject, aReflector);
1104 0 : if (!aReflector) {
1105 0 : return false;
1106 : }
1107 :
1108 0 : aCache->SetWrapper(aReflector);
1109 0 : creator.InitializationSucceeded();
1110 :
1111 0 : MOZ_ASSERT(aCache->GetWrapperPreserveColor() &&
1112 : aCache->GetWrapperPreserveColor() == aReflector);
1113 : // If proto != canonicalProto, we have to preserve our wrapper;
1114 : // otherwise we won't be able to properly recreate it later, since
1115 : // we won't know what proto to use. Note that we don't check
1116 : // aGivenProto here, since it's entirely possible (and even
1117 : // somewhat common) to have a non-null aGivenProto which is the
1118 : // same as canonicalProto.
1119 0 : if (proto != canonicalProto) {
1120 0 : PreserveWrapper(aObject);
1121 : }
1122 :
1123 0 : return true;
1124 : }
1125 :
1126 : const NativePropertyHooks sNativePropertyHooks[] = { {
1127 : nullptr,
1128 : nullptr,
1129 : nullptr,
1130 : { sNativeProperties.Upcast(), sChromeOnlyNativeProperties.Upcast() },
1131 : prototypes::id::MediaSource,
1132 : constructors::id::MediaSource,
1133 : EventTargetBinding::sNativePropertyHooks,
1134 : &DefaultXrayExpandoObjectClass
1135 : } };
1136 :
1137 : void
1138 0 : CreateInterfaceObjects(JSContext* aCx, JS::Handle<JSObject*> aGlobal, ProtoAndIfaceCache& aProtoAndIfaceCache, bool aDefineOnGlobal)
1139 : {
1140 0 : JS::Handle<JSObject*> parentProto(EventTargetBinding::GetProtoObjectHandle(aCx));
1141 0 : if (!parentProto) {
1142 0 : return;
1143 : }
1144 :
1145 0 : JS::Handle<JSObject*> constructorProto(EventTargetBinding::GetConstructorObjectHandle(aCx));
1146 0 : if (!constructorProto) {
1147 0 : return;
1148 : }
1149 :
1150 : static bool sIdsInited = false;
1151 0 : if (!sIdsInited && NS_IsMainThread()) {
1152 0 : if (!InitIds(aCx, sNativeProperties.Upcast())) {
1153 0 : return;
1154 : }
1155 0 : if (!InitIds(aCx, sChromeOnlyNativeProperties.Upcast())) {
1156 0 : return;
1157 : }
1158 0 : sIdsInited = true;
1159 : }
1160 :
1161 0 : JS::Heap<JSObject*>* protoCache = &aProtoAndIfaceCache.EntrySlotOrCreate(prototypes::id::MediaSource);
1162 0 : JS::Heap<JSObject*>* interfaceCache = &aProtoAndIfaceCache.EntrySlotOrCreate(constructors::id::MediaSource);
1163 0 : dom::CreateInterfaceObjects(aCx, aGlobal, parentProto,
1164 : &sPrototypeClass.mBase, protoCache,
1165 : constructorProto, &sInterfaceObjectClass.mBase, 0, nullptr,
1166 : interfaceCache,
1167 : sNativeProperties.Upcast(),
1168 0 : nsContentUtils::ThreadsafeIsSystemCaller(aCx) ? sChromeOnlyNativeProperties.Upcast() : nullptr,
1169 : "MediaSource", aDefineOnGlobal,
1170 : nullptr,
1171 0 : false);
1172 : }
1173 :
1174 : JS::Handle<JSObject*>
1175 0 : GetProtoObjectHandle(JSContext* aCx)
1176 : {
1177 : /* Get the interface prototype object for this class. This will create the
1178 : object as needed. */
1179 0 : bool aDefineOnGlobal = true;
1180 :
1181 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1182 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1183 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1184 0 : return nullptr;
1185 : }
1186 :
1187 : /* Check to see whether the interface objects are already installed */
1188 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1189 0 : if (!protoAndIfaceCache.HasEntryInSlot(prototypes::id::MediaSource)) {
1190 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1191 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1192 : }
1193 :
1194 : /*
1195 : * The object might _still_ be null, but that's OK.
1196 : *
1197 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1198 : * traced by TraceProtoAndIfaceCache() and its contents are never
1199 : * changed after they have been set.
1200 : *
1201 : * Calling address() avoids the read read barrier that does gray
1202 : * unmarking, but it's not possible for the object to be gray here.
1203 : */
1204 :
1205 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(prototypes::id::MediaSource);
1206 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1207 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1208 : }
1209 :
1210 : JS::Handle<JSObject*>
1211 0 : GetConstructorObjectHandle(JSContext* aCx, bool aDefineOnGlobal)
1212 : {
1213 : /* Get the interface object for this class. This will create the object as
1214 : needed. */
1215 :
1216 : /* Make sure our global is sane. Hopefully we can remove this sometime */
1217 0 : JSObject* global = JS::CurrentGlobalOrNull(aCx);
1218 0 : if (!(js::GetObjectClass(global)->flags & JSCLASS_DOM_GLOBAL)) {
1219 0 : return nullptr;
1220 : }
1221 :
1222 : /* Check to see whether the interface objects are already installed */
1223 0 : ProtoAndIfaceCache& protoAndIfaceCache = *GetProtoAndIfaceCache(global);
1224 0 : if (!protoAndIfaceCache.HasEntryInSlot(constructors::id::MediaSource)) {
1225 0 : JS::Rooted<JSObject*> rootedGlobal(aCx, global);
1226 0 : CreateInterfaceObjects(aCx, rootedGlobal, protoAndIfaceCache, aDefineOnGlobal);
1227 : }
1228 :
1229 : /*
1230 : * The object might _still_ be null, but that's OK.
1231 : *
1232 : * Calling fromMarkedLocation() is safe because protoAndIfaceCache is
1233 : * traced by TraceProtoAndIfaceCache() and its contents are never
1234 : * changed after they have been set.
1235 : *
1236 : * Calling address() avoids the read read barrier that does gray
1237 : * unmarking, but it's not possible for the object to be gray here.
1238 : */
1239 :
1240 0 : const JS::Heap<JSObject*>& entrySlot = protoAndIfaceCache.EntrySlotMustExist(constructors::id::MediaSource);
1241 0 : MOZ_ASSERT(JS::ObjectIsNotGray(entrySlot));
1242 0 : return JS::Handle<JSObject*>::fromMarkedLocation(entrySlot.address());
1243 : }
1244 :
1245 : JSObject*
1246 0 : GetConstructorObject(JSContext* aCx)
1247 : {
1248 0 : return GetConstructorObjectHandle(aCx);
1249 : }
1250 :
1251 : } // namespace MediaSourceBinding
1252 :
1253 :
1254 :
1255 : } // namespace dom
1256 : } // namespace mozilla
|