1/*
2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19*/
20
21#include "config.h"
22
23#if ENABLE(MEDIA_SOURCE)
24
25#include "JSMediaSource.h"
26
27#include "EventNames.h"
28#include "JSDOMAttribute.h"
29#include "JSDOMBinding.h"
30#include "JSDOMConstructor.h"
31#include "JSDOMConvertBoolean.h"
32#include "JSDOMConvertInterface.h"
33#include "JSDOMConvertNumbers.h"
34#include "JSDOMConvertStrings.h"
35#include "JSDOMExceptionHandling.h"
36#include "JSDOMGlobalObject.h"
37#include "JSDOMOperation.h"
38#include "JSDOMWrapperCache.h"
39#include "JSEventListener.h"
40#include "JSSourceBuffer.h"
41#include "JSSourceBufferList.h"
42#include "ScriptExecutionContext.h"
43#include <JavaScriptCore/HeapSnapshotBuilder.h>
44#include <JavaScriptCore/JSCInlines.h>
45#include <JavaScriptCore/JSString.h>
46#include <wtf/GetPtr.h>
47#include <wtf/PointerPreparations.h>
48#include <wtf/URL.h>
49
50
51namespace WebCore {
52using namespace JSC;
53
54String convertEnumerationToString(MediaSource::EndOfStreamError enumerationValue)
55{
56 static const NeverDestroyed<String> values[] = {
57 MAKE_STATIC_STRING_IMPL("network"),
58 MAKE_STATIC_STRING_IMPL("decode"),
59 };
60 static_assert(static_cast<size_t>(MediaSource::EndOfStreamError::Network) == 0, "MediaSource::EndOfStreamError::Network is not 0 as expected");
61 static_assert(static_cast<size_t>(MediaSource::EndOfStreamError::Decode) == 1, "MediaSource::EndOfStreamError::Decode is not 1 as expected");
62 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
63 return values[static_cast<size_t>(enumerationValue)];
64}
65
66template<> JSString* convertEnumerationToJS(ExecState& state, MediaSource::EndOfStreamError enumerationValue)
67{
68 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
69}
70
71template<> Optional<MediaSource::EndOfStreamError> parseEnumeration<MediaSource::EndOfStreamError>(ExecState& state, JSValue value)
72{
73 auto stringValue = value.toWTFString(&state);
74 if (stringValue == "network")
75 return MediaSource::EndOfStreamError::Network;
76 if (stringValue == "decode")
77 return MediaSource::EndOfStreamError::Decode;
78 return WTF::nullopt;
79}
80
81template<> const char* expectedEnumerationValues<MediaSource::EndOfStreamError>()
82{
83 return "\"network\", \"decode\"";
84}
85
86String convertEnumerationToString(MediaSource::ReadyState enumerationValue)
87{
88 static const NeverDestroyed<String> values[] = {
89 MAKE_STATIC_STRING_IMPL("closed"),
90 MAKE_STATIC_STRING_IMPL("open"),
91 MAKE_STATIC_STRING_IMPL("ended"),
92 };
93 static_assert(static_cast<size_t>(MediaSource::ReadyState::Closed) == 0, "MediaSource::ReadyState::Closed is not 0 as expected");
94 static_assert(static_cast<size_t>(MediaSource::ReadyState::Open) == 1, "MediaSource::ReadyState::Open is not 1 as expected");
95 static_assert(static_cast<size_t>(MediaSource::ReadyState::Ended) == 2, "MediaSource::ReadyState::Ended is not 2 as expected");
96 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
97 return values[static_cast<size_t>(enumerationValue)];
98}
99
100template<> JSString* convertEnumerationToJS(ExecState& state, MediaSource::ReadyState enumerationValue)
101{
102 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
103}
104
105template<> Optional<MediaSource::ReadyState> parseEnumeration<MediaSource::ReadyState>(ExecState& state, JSValue value)
106{
107 auto stringValue = value.toWTFString(&state);
108 if (stringValue == "closed")
109 return MediaSource::ReadyState::Closed;
110 if (stringValue == "open")
111 return MediaSource::ReadyState::Open;
112 if (stringValue == "ended")
113 return MediaSource::ReadyState::Ended;
114 return WTF::nullopt;
115}
116
117template<> const char* expectedEnumerationValues<MediaSource::ReadyState>()
118{
119 return "\"closed\", \"open\", \"ended\"";
120}
121
122// Functions
123
124JSC::EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionAddSourceBuffer(JSC::ExecState*);
125JSC::EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionRemoveSourceBuffer(JSC::ExecState*);
126JSC::EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionEndOfStream(JSC::ExecState*);
127JSC::EncodedJSValue JSC_HOST_CALL jsMediaSourceConstructorFunctionIsTypeSupported(JSC::ExecState*);
128JSC::EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionSetLiveSeekableRange(JSC::ExecState*);
129JSC::EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionClearLiveSeekableRange(JSC::ExecState*);
130
131// Attributes
132
133JSC::EncodedJSValue jsMediaSourceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
134bool setJSMediaSourceConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
135JSC::EncodedJSValue jsMediaSourceSourceBuffers(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
136JSC::EncodedJSValue jsMediaSourceActiveSourceBuffers(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
137JSC::EncodedJSValue jsMediaSourceDuration(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
138bool setJSMediaSourceDuration(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
139JSC::EncodedJSValue jsMediaSourceReadyState(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
140JSC::EncodedJSValue jsMediaSourceOnsourceopen(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
141bool setJSMediaSourceOnsourceopen(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
142JSC::EncodedJSValue jsMediaSourceOnsourceended(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
143bool setJSMediaSourceOnsourceended(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
144JSC::EncodedJSValue jsMediaSourceOnsourceclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
145bool setJSMediaSourceOnsourceclose(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
146
147class JSMediaSourcePrototype : public JSC::JSNonFinalObject {
148public:
149 using Base = JSC::JSNonFinalObject;
150 static JSMediaSourcePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
151 {
152 JSMediaSourcePrototype* ptr = new (NotNull, JSC::allocateCell<JSMediaSourcePrototype>(vm.heap)) JSMediaSourcePrototype(vm, globalObject, structure);
153 ptr->finishCreation(vm);
154 return ptr;
155 }
156
157 DECLARE_INFO;
158 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
159 {
160 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
161 }
162
163private:
164 JSMediaSourcePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
165 : JSC::JSNonFinalObject(vm, structure)
166 {
167 }
168
169 void finishCreation(JSC::VM&);
170};
171
172using JSMediaSourceConstructor = JSDOMConstructor<JSMediaSource>;
173
174/* Hash table for constructor */
175
176static const HashTableValue JSMediaSourceConstructorTableValues[] =
177{
178 { "isTypeSupported", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaSourceConstructorFunctionIsTypeSupported), (intptr_t) (1) } },
179};
180
181template<> EncodedJSValue JSC_HOST_CALL JSMediaSourceConstructor::construct(ExecState* state)
182{
183 VM& vm = state->vm();
184 auto throwScope = DECLARE_THROW_SCOPE(vm);
185 UNUSED_PARAM(throwScope);
186 auto* castedThis = jsCast<JSMediaSourceConstructor*>(state->jsCallee());
187 ASSERT(castedThis);
188 auto* context = castedThis->scriptExecutionContext();
189 if (UNLIKELY(!context))
190 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "MediaSource");
191 auto object = MediaSource::create(*context);
192 return JSValue::encode(toJSNewlyCreated<IDLInterface<MediaSource>>(*state, *castedThis->globalObject(), WTFMove(object)));
193}
194
195template<> JSValue JSMediaSourceConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
196{
197 return JSEventTarget::getConstructor(vm, &globalObject);
198}
199
200template<> void JSMediaSourceConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
201{
202 putDirect(vm, vm.propertyNames->prototype, JSMediaSource::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
203 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("MediaSource"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
204 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
205 reifyStaticProperties(vm, JSMediaSource::info(), JSMediaSourceConstructorTableValues, *this);
206}
207
208template<> const ClassInfo JSMediaSourceConstructor::s_info = { "MediaSource", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaSourceConstructor) };
209
210/* Hash table for prototype */
211
212static const HashTableValue JSMediaSourcePrototypeTableValues[] =
213{
214 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaSourceConstructor) } },
215 { "sourceBuffers", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceSourceBuffers), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
216 { "activeSourceBuffers", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceActiveSourceBuffers), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
217 { "duration", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceDuration), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaSourceDuration) } },
218 { "readyState", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceReadyState), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
219 { "onsourceopen", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceOnsourceopen), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaSourceOnsourceopen) } },
220 { "onsourceended", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceOnsourceended), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaSourceOnsourceended) } },
221 { "onsourceclose", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaSourceOnsourceclose), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaSourceOnsourceclose) } },
222 { "addSourceBuffer", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaSourcePrototypeFunctionAddSourceBuffer), (intptr_t) (1) } },
223 { "removeSourceBuffer", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaSourcePrototypeFunctionRemoveSourceBuffer), (intptr_t) (1) } },
224 { "endOfStream", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaSourcePrototypeFunctionEndOfStream), (intptr_t) (0) } },
225 { "setLiveSeekableRange", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaSourcePrototypeFunctionSetLiveSeekableRange), (intptr_t) (2) } },
226 { "clearLiveSeekableRange", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaSourcePrototypeFunctionClearLiveSeekableRange), (intptr_t) (0) } },
227};
228
229const ClassInfo JSMediaSourcePrototype::s_info = { "MediaSourcePrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaSourcePrototype) };
230
231void JSMediaSourcePrototype::finishCreation(VM& vm)
232{
233 Base::finishCreation(vm);
234 reifyStaticProperties(vm, JSMediaSource::info(), JSMediaSourcePrototypeTableValues, *this);
235}
236
237const ClassInfo JSMediaSource::s_info = { "MediaSource", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaSource) };
238
239JSMediaSource::JSMediaSource(Structure* structure, JSDOMGlobalObject& globalObject, Ref<MediaSource>&& impl)
240 : JSEventTarget(structure, globalObject, WTFMove(impl))
241{
242}
243
244void JSMediaSource::finishCreation(VM& vm)
245{
246 Base::finishCreation(vm);
247 ASSERT(inherits(vm, info()));
248
249}
250
251JSObject* JSMediaSource::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
252{
253 return JSMediaSourcePrototype::create(vm, &globalObject, JSMediaSourcePrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
254}
255
256JSObject* JSMediaSource::prototype(VM& vm, JSDOMGlobalObject& globalObject)
257{
258 return getDOMPrototype<JSMediaSource>(vm, globalObject);
259}
260
261JSValue JSMediaSource::getConstructor(VM& vm, const JSGlobalObject* globalObject)
262{
263 return getDOMConstructor<JSMediaSourceConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
264}
265
266template<> inline JSMediaSource* IDLAttribute<JSMediaSource>::cast(ExecState& state, EncodedJSValue thisValue)
267{
268 return jsDynamicCast<JSMediaSource*>(state.vm(), JSValue::decode(thisValue));
269}
270
271template<> inline JSMediaSource* IDLOperation<JSMediaSource>::cast(ExecState& state)
272{
273 return jsDynamicCast<JSMediaSource*>(state.vm(), state.thisValue());
274}
275
276EncodedJSValue jsMediaSourceConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
277{
278 VM& vm = state->vm();
279 auto throwScope = DECLARE_THROW_SCOPE(vm);
280 auto* prototype = jsDynamicCast<JSMediaSourcePrototype*>(vm, JSValue::decode(thisValue));
281 if (UNLIKELY(!prototype))
282 return throwVMTypeError(state, throwScope);
283 return JSValue::encode(JSMediaSource::getConstructor(state->vm(), prototype->globalObject()));
284}
285
286bool setJSMediaSourceConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
287{
288 VM& vm = state->vm();
289 auto throwScope = DECLARE_THROW_SCOPE(vm);
290 auto* prototype = jsDynamicCast<JSMediaSourcePrototype*>(vm, JSValue::decode(thisValue));
291 if (UNLIKELY(!prototype)) {
292 throwVMTypeError(state, throwScope);
293 return false;
294 }
295 // Shadowing a built-in constructor
296 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
297}
298
299static inline JSValue jsMediaSourceSourceBuffersGetter(ExecState& state, JSMediaSource& thisObject, ThrowScope& throwScope)
300{
301 UNUSED_PARAM(throwScope);
302 UNUSED_PARAM(state);
303 auto& impl = thisObject.wrapped();
304 JSValue result = toJS<IDLInterface<SourceBufferList>>(state, *thisObject.globalObject(), throwScope, impl.sourceBuffers());
305 return result;
306}
307
308EncodedJSValue jsMediaSourceSourceBuffers(ExecState* state, EncodedJSValue thisValue, PropertyName)
309{
310 return IDLAttribute<JSMediaSource>::get<jsMediaSourceSourceBuffersGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "sourceBuffers");
311}
312
313static inline JSValue jsMediaSourceActiveSourceBuffersGetter(ExecState& state, JSMediaSource& thisObject, ThrowScope& throwScope)
314{
315 UNUSED_PARAM(throwScope);
316 UNUSED_PARAM(state);
317 auto& impl = thisObject.wrapped();
318 JSValue result = toJS<IDLInterface<SourceBufferList>>(state, *thisObject.globalObject(), throwScope, impl.activeSourceBuffers());
319 return result;
320}
321
322EncodedJSValue jsMediaSourceActiveSourceBuffers(ExecState* state, EncodedJSValue thisValue, PropertyName)
323{
324 return IDLAttribute<JSMediaSource>::get<jsMediaSourceActiveSourceBuffersGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "activeSourceBuffers");
325}
326
327static inline JSValue jsMediaSourceDurationGetter(ExecState& state, JSMediaSource& thisObject, ThrowScope& throwScope)
328{
329 UNUSED_PARAM(throwScope);
330 UNUSED_PARAM(state);
331 auto& impl = thisObject.wrapped();
332 JSValue result = toJS<IDLUnrestrictedDouble>(state, throwScope, impl.duration());
333 return result;
334}
335
336EncodedJSValue jsMediaSourceDuration(ExecState* state, EncodedJSValue thisValue, PropertyName)
337{
338 return IDLAttribute<JSMediaSource>::get<jsMediaSourceDurationGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "duration");
339}
340
341static inline bool setJSMediaSourceDurationSetter(ExecState& state, JSMediaSource& thisObject, JSValue value, ThrowScope& throwScope)
342{
343 UNUSED_PARAM(throwScope);
344 auto& impl = thisObject.wrapped();
345 auto nativeValue = convert<IDLUnrestrictedDouble>(state, value);
346 RETURN_IF_EXCEPTION(throwScope, false);
347 AttributeSetter::call(state, throwScope, [&] {
348 return impl.setDuration(WTFMove(nativeValue));
349 });
350 return true;
351}
352
353bool setJSMediaSourceDuration(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
354{
355 return IDLAttribute<JSMediaSource>::set<setJSMediaSourceDurationSetter>(*state, thisValue, encodedValue, "duration");
356}
357
358static inline JSValue jsMediaSourceReadyStateGetter(ExecState& state, JSMediaSource& thisObject, ThrowScope& throwScope)
359{
360 UNUSED_PARAM(throwScope);
361 UNUSED_PARAM(state);
362 auto& impl = thisObject.wrapped();
363 JSValue result = toJS<IDLEnumeration<MediaSource::ReadyState>>(state, throwScope, impl.readyState());
364 return result;
365}
366
367EncodedJSValue jsMediaSourceReadyState(ExecState* state, EncodedJSValue thisValue, PropertyName)
368{
369 return IDLAttribute<JSMediaSource>::get<jsMediaSourceReadyStateGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "readyState");
370}
371
372static inline JSValue jsMediaSourceOnsourceopenGetter(ExecState& state, JSMediaSource& thisObject, ThrowScope& throwScope)
373{
374 UNUSED_PARAM(throwScope);
375 UNUSED_PARAM(state);
376 return eventHandlerAttribute(thisObject.wrapped(), eventNames().sourceopenEvent, worldForDOMObject(thisObject));
377}
378
379EncodedJSValue jsMediaSourceOnsourceopen(ExecState* state, EncodedJSValue thisValue, PropertyName)
380{
381 return IDLAttribute<JSMediaSource>::get<jsMediaSourceOnsourceopenGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onsourceopen");
382}
383
384static inline bool setJSMediaSourceOnsourceopenSetter(ExecState& state, JSMediaSource& thisObject, JSValue value, ThrowScope& throwScope)
385{
386 UNUSED_PARAM(throwScope);
387 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().sourceopenEvent, value);
388 return true;
389}
390
391bool setJSMediaSourceOnsourceopen(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
392{
393 return IDLAttribute<JSMediaSource>::set<setJSMediaSourceOnsourceopenSetter>(*state, thisValue, encodedValue, "onsourceopen");
394}
395
396static inline JSValue jsMediaSourceOnsourceendedGetter(ExecState& state, JSMediaSource& thisObject, ThrowScope& throwScope)
397{
398 UNUSED_PARAM(throwScope);
399 UNUSED_PARAM(state);
400 return eventHandlerAttribute(thisObject.wrapped(), eventNames().sourceendedEvent, worldForDOMObject(thisObject));
401}
402
403EncodedJSValue jsMediaSourceOnsourceended(ExecState* state, EncodedJSValue thisValue, PropertyName)
404{
405 return IDLAttribute<JSMediaSource>::get<jsMediaSourceOnsourceendedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onsourceended");
406}
407
408static inline bool setJSMediaSourceOnsourceendedSetter(ExecState& state, JSMediaSource& thisObject, JSValue value, ThrowScope& throwScope)
409{
410 UNUSED_PARAM(throwScope);
411 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().sourceendedEvent, value);
412 return true;
413}
414
415bool setJSMediaSourceOnsourceended(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
416{
417 return IDLAttribute<JSMediaSource>::set<setJSMediaSourceOnsourceendedSetter>(*state, thisValue, encodedValue, "onsourceended");
418}
419
420static inline JSValue jsMediaSourceOnsourcecloseGetter(ExecState& state, JSMediaSource& thisObject, ThrowScope& throwScope)
421{
422 UNUSED_PARAM(throwScope);
423 UNUSED_PARAM(state);
424 return eventHandlerAttribute(thisObject.wrapped(), eventNames().sourcecloseEvent, worldForDOMObject(thisObject));
425}
426
427EncodedJSValue jsMediaSourceOnsourceclose(ExecState* state, EncodedJSValue thisValue, PropertyName)
428{
429 return IDLAttribute<JSMediaSource>::get<jsMediaSourceOnsourcecloseGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onsourceclose");
430}
431
432static inline bool setJSMediaSourceOnsourcecloseSetter(ExecState& state, JSMediaSource& thisObject, JSValue value, ThrowScope& throwScope)
433{
434 UNUSED_PARAM(throwScope);
435 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().sourcecloseEvent, value);
436 return true;
437}
438
439bool setJSMediaSourceOnsourceclose(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
440{
441 return IDLAttribute<JSMediaSource>::set<setJSMediaSourceOnsourcecloseSetter>(*state, thisValue, encodedValue, "onsourceclose");
442}
443
444static inline JSC::EncodedJSValue jsMediaSourcePrototypeFunctionAddSourceBufferBody(JSC::ExecState* state, typename IDLOperation<JSMediaSource>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
445{
446 UNUSED_PARAM(state);
447 UNUSED_PARAM(throwScope);
448 auto& impl = castedThis->wrapped();
449 if (UNLIKELY(state->argumentCount() < 1))
450 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
451 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
452 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
453 return JSValue::encode(toJSNewlyCreated<IDLInterface<SourceBuffer>>(*state, *castedThis->globalObject(), throwScope, impl.addSourceBuffer(WTFMove(type))));
454}
455
456EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionAddSourceBuffer(ExecState* state)
457{
458 return IDLOperation<JSMediaSource>::call<jsMediaSourcePrototypeFunctionAddSourceBufferBody>(*state, "addSourceBuffer");
459}
460
461static inline JSC::EncodedJSValue jsMediaSourcePrototypeFunctionRemoveSourceBufferBody(JSC::ExecState* state, typename IDLOperation<JSMediaSource>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
462{
463 UNUSED_PARAM(state);
464 UNUSED_PARAM(throwScope);
465 auto& impl = castedThis->wrapped();
466 if (UNLIKELY(state->argumentCount() < 1))
467 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
468 auto buffer = convert<IDLInterface<SourceBuffer>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "buffer", "MediaSource", "removeSourceBuffer", "SourceBuffer"); });
469 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
470 propagateException(*state, throwScope, impl.removeSourceBuffer(*buffer));
471 return JSValue::encode(jsUndefined());
472}
473
474EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionRemoveSourceBuffer(ExecState* state)
475{
476 return IDLOperation<JSMediaSource>::call<jsMediaSourcePrototypeFunctionRemoveSourceBufferBody>(*state, "removeSourceBuffer");
477}
478
479static inline JSC::EncodedJSValue jsMediaSourcePrototypeFunctionEndOfStreamBody(JSC::ExecState* state, typename IDLOperation<JSMediaSource>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
480{
481 UNUSED_PARAM(state);
482 UNUSED_PARAM(throwScope);
483 auto& impl = castedThis->wrapped();
484 auto error = state->argument(0).isUndefined() ? Optional<Converter<IDLEnumeration<MediaSource::EndOfStreamError>>::ReturnType>() : Optional<Converter<IDLEnumeration<MediaSource::EndOfStreamError>>::ReturnType>(convert<IDLEnumeration<MediaSource::EndOfStreamError>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentMustBeEnumError(state, scope, 0, "error", "MediaSource", "endOfStream", expectedEnumerationValues<MediaSource::EndOfStreamError>()); }));
485 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
486 propagateException(*state, throwScope, impl.endOfStream(WTFMove(error)));
487 return JSValue::encode(jsUndefined());
488}
489
490EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionEndOfStream(ExecState* state)
491{
492 return IDLOperation<JSMediaSource>::call<jsMediaSourcePrototypeFunctionEndOfStreamBody>(*state, "endOfStream");
493}
494
495static inline JSC::EncodedJSValue jsMediaSourceConstructorFunctionIsTypeSupportedBody(JSC::ExecState* state, JSC::ThrowScope& throwScope)
496{
497 UNUSED_PARAM(state);
498 UNUSED_PARAM(throwScope);
499 if (UNLIKELY(state->argumentCount() < 1))
500 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
501 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
502 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
503 return JSValue::encode(toJS<IDLBoolean>(MediaSource::isTypeSupported(WTFMove(type))));
504}
505
506EncodedJSValue JSC_HOST_CALL jsMediaSourceConstructorFunctionIsTypeSupported(ExecState* state)
507{
508 return IDLOperation<JSMediaSource>::callStatic<jsMediaSourceConstructorFunctionIsTypeSupportedBody>(*state, "isTypeSupported");
509}
510
511static inline JSC::EncodedJSValue jsMediaSourcePrototypeFunctionSetLiveSeekableRangeBody(JSC::ExecState* state, typename IDLOperation<JSMediaSource>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
512{
513 UNUSED_PARAM(state);
514 UNUSED_PARAM(throwScope);
515 auto& impl = castedThis->wrapped();
516 if (UNLIKELY(state->argumentCount() < 2))
517 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
518 auto start = convert<IDLDouble>(*state, state->uncheckedArgument(0));
519 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
520 auto end = convert<IDLDouble>(*state, state->uncheckedArgument(1));
521 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
522 propagateException(*state, throwScope, impl.setLiveSeekableRange(WTFMove(start), WTFMove(end)));
523 return JSValue::encode(jsUndefined());
524}
525
526EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionSetLiveSeekableRange(ExecState* state)
527{
528 return IDLOperation<JSMediaSource>::call<jsMediaSourcePrototypeFunctionSetLiveSeekableRangeBody>(*state, "setLiveSeekableRange");
529}
530
531static inline JSC::EncodedJSValue jsMediaSourcePrototypeFunctionClearLiveSeekableRangeBody(JSC::ExecState* state, typename IDLOperation<JSMediaSource>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
532{
533 UNUSED_PARAM(state);
534 UNUSED_PARAM(throwScope);
535 auto& impl = castedThis->wrapped();
536 propagateException(*state, throwScope, impl.clearLiveSeekableRange());
537 return JSValue::encode(jsUndefined());
538}
539
540EncodedJSValue JSC_HOST_CALL jsMediaSourcePrototypeFunctionClearLiveSeekableRange(ExecState* state)
541{
542 return IDLOperation<JSMediaSource>::call<jsMediaSourcePrototypeFunctionClearLiveSeekableRangeBody>(*state, "clearLiveSeekableRange");
543}
544
545void JSMediaSource::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
546{
547 auto* thisObject = jsCast<JSMediaSource*>(cell);
548 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
549 if (thisObject->scriptExecutionContext())
550 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
551 Base::heapSnapshot(cell, builder);
552}
553
554bool JSMediaSourceOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
555{
556 auto* jsMediaSource = jsCast<JSMediaSource*>(handle.slot()->asCell());
557 if (jsMediaSource->wrapped().hasPendingActivity()) {
558 if (UNLIKELY(reason))
559 *reason = "ActiveDOMObject with pending activity";
560 return true;
561 }
562 if (jsMediaSource->wrapped().isFiringEventListeners()) {
563 if (UNLIKELY(reason))
564 *reason = "EventTarget firing event listeners";
565 return true;
566 }
567 UNUSED_PARAM(visitor);
568 UNUSED_PARAM(reason);
569 return false;
570}
571
572void JSMediaSourceOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
573{
574 auto* jsMediaSource = static_cast<JSMediaSource*>(handle.slot()->asCell());
575 auto& world = *static_cast<DOMWrapperWorld*>(context);
576 uncacheWrapper(world, &jsMediaSource->wrapped(), jsMediaSource);
577}
578
579#if ENABLE(BINDING_INTEGRITY)
580#if PLATFORM(WIN)
581#pragma warning(disable: 4483)
582extern "C" { extern void (*const __identifier("??_7MediaSource@WebCore@@6B@")[])(); }
583#else
584extern "C" { extern void* _ZTVN7WebCore11MediaSourceE[]; }
585#endif
586#endif
587
588JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<MediaSource>&& impl)
589{
590
591#if ENABLE(BINDING_INTEGRITY)
592 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
593#if PLATFORM(WIN)
594 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7MediaSource@WebCore@@6B@"));
595#else
596 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11MediaSourceE[2]);
597#endif
598
599 // If this fails MediaSource does not have a vtable, so you need to add the
600 // ImplementationLacksVTable attribute to the interface definition
601 static_assert(std::is_polymorphic<MediaSource>::value, "MediaSource is not polymorphic");
602
603 // If you hit this assertion you either have a use after free bug, or
604 // MediaSource has subclasses. If MediaSource has subclasses that get passed
605 // to toJS() we currently require MediaSource you to opt out of binding hardening
606 // by adding the SkipVTableValidation attribute to the interface IDL definition
607 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
608#endif
609 return createWrapper<MediaSource>(globalObject, WTFMove(impl));
610}
611
612JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, MediaSource& impl)
613{
614 return wrap(state, globalObject, impl);
615}
616
617MediaSource* JSMediaSource::toWrapped(JSC::VM& vm, JSC::JSValue value)
618{
619 if (auto* wrapper = jsDynamicCast<JSMediaSource*>(vm, value))
620 return &wrapper->wrapped();
621 return nullptr;
622}
623
624}
625
626#endif // ENABLE(MEDIA_SOURCE)
627