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_STREAM)
24
25#include "JSMediaStream.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 "JSDOMConvertSequences.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 "JSMediaStream.h"
41#include "JSMediaStreamTrack.h"
42#include "ScriptExecutionContext.h"
43#include "WebCoreJSClientData.h"
44#include <JavaScriptCore/HeapSnapshotBuilder.h>
45#include <JavaScriptCore/JSArray.h>
46#include <JavaScriptCore/JSCInlines.h>
47#include <wtf/GetPtr.h>
48#include <wtf/PointerPreparations.h>
49#include <wtf/URL.h>
50
51#if ENABLE(MEDIA_STREAM)
52#include <JavaScriptCore/IteratorOperations.h>
53#endif
54
55
56namespace WebCore {
57using namespace JSC;
58
59// Functions
60
61JSC::EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetAudioTracks(JSC::ExecState*);
62JSC::EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetVideoTracks(JSC::ExecState*);
63JSC::EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetTracks(JSC::ExecState*);
64JSC::EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetTrackById(JSC::ExecState*);
65JSC::EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionAddTrack(JSC::ExecState*);
66JSC::EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionRemoveTrack(JSC::ExecState*);
67JSC::EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionClone(JSC::ExecState*);
68
69// Attributes
70
71JSC::EncodedJSValue jsMediaStreamConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
72bool setJSMediaStreamConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
73JSC::EncodedJSValue jsMediaStreamId(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
74JSC::EncodedJSValue jsMediaStreamActive(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
75JSC::EncodedJSValue jsMediaStreamOnaddtrack(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
76bool setJSMediaStreamOnaddtrack(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
77JSC::EncodedJSValue jsMediaStreamOnremovetrack(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
78bool setJSMediaStreamOnremovetrack(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
79
80class JSMediaStreamPrototype : public JSC::JSNonFinalObject {
81public:
82 using Base = JSC::JSNonFinalObject;
83 static JSMediaStreamPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
84 {
85 JSMediaStreamPrototype* ptr = new (NotNull, JSC::allocateCell<JSMediaStreamPrototype>(vm.heap)) JSMediaStreamPrototype(vm, globalObject, structure);
86 ptr->finishCreation(vm);
87 return ptr;
88 }
89
90 DECLARE_INFO;
91 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
92 {
93 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
94 }
95
96private:
97 JSMediaStreamPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
98 : JSC::JSNonFinalObject(vm, structure)
99 {
100 }
101
102 void finishCreation(JSC::VM&);
103};
104
105using JSMediaStreamConstructor = JSDOMConstructor<JSMediaStream>;
106
107static inline EncodedJSValue constructJSMediaStream1(ExecState* state)
108{
109 VM& vm = state->vm();
110 auto throwScope = DECLARE_THROW_SCOPE(vm);
111 UNUSED_PARAM(throwScope);
112 auto* castedThis = jsCast<JSMediaStreamConstructor*>(state->jsCallee());
113 ASSERT(castedThis);
114 auto* context = castedThis->scriptExecutionContext();
115 if (UNLIKELY(!context))
116 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "MediaStream");
117 auto object = MediaStream::create(*context);
118 return JSValue::encode(toJSNewlyCreated<IDLInterface<MediaStream>>(*state, *castedThis->globalObject(), WTFMove(object)));
119}
120
121static inline EncodedJSValue constructJSMediaStream2(ExecState* state)
122{
123 VM& vm = state->vm();
124 auto throwScope = DECLARE_THROW_SCOPE(vm);
125 UNUSED_PARAM(throwScope);
126 auto* castedThis = jsCast<JSMediaStreamConstructor*>(state->jsCallee());
127 ASSERT(castedThis);
128 auto* context = castedThis->scriptExecutionContext();
129 if (UNLIKELY(!context))
130 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "MediaStream");
131 auto stream = convert<IDLInterface<MediaStream>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "stream", "MediaStream", nullptr, "MediaStream"); });
132 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
133 auto object = MediaStream::create(*context, *stream);
134 return JSValue::encode(toJSNewlyCreated<IDLInterface<MediaStream>>(*state, *castedThis->globalObject(), WTFMove(object)));
135}
136
137static inline EncodedJSValue constructJSMediaStream3(ExecState* state)
138{
139 VM& vm = state->vm();
140 auto throwScope = DECLARE_THROW_SCOPE(vm);
141 UNUSED_PARAM(throwScope);
142 auto* castedThis = jsCast<JSMediaStreamConstructor*>(state->jsCallee());
143 ASSERT(castedThis);
144 auto* context = castedThis->scriptExecutionContext();
145 if (UNLIKELY(!context))
146 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "MediaStream");
147 auto tracks = convert<IDLSequence<IDLInterface<MediaStreamTrack>>>(*state, state->uncheckedArgument(0));
148 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
149 auto object = MediaStream::create(*context, WTFMove(tracks));
150 return JSValue::encode(toJSNewlyCreated<IDLInterface<MediaStream>>(*state, *castedThis->globalObject(), WTFMove(object)));
151}
152
153template<> EncodedJSValue JSC_HOST_CALL JSMediaStreamConstructor::construct(ExecState* state)
154{
155 VM& vm = state->vm();
156 auto throwScope = DECLARE_THROW_SCOPE(vm);
157 UNUSED_PARAM(throwScope);
158 size_t argsCount = std::min<size_t>(1, state->argumentCount());
159 if (argsCount == 0) {
160#if ENABLE(MEDIA_STREAM)
161 return constructJSMediaStream1(state);
162#endif
163 }
164 if (argsCount == 1) {
165 JSValue distinguishingArg = state->uncheckedArgument(0);
166#if ENABLE(MEDIA_STREAM)
167 if (distinguishingArg.isObject() && asObject(distinguishingArg)->inherits<JSMediaStream>(vm))
168 return constructJSMediaStream2(state);
169#endif
170#if ENABLE(MEDIA_STREAM)
171 if (hasIteratorMethod(*state, distinguishingArg))
172 return constructJSMediaStream3(state);
173#endif
174 }
175 return throwVMTypeError(state, throwScope);
176}
177
178template<> JSValue JSMediaStreamConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
179{
180 return JSEventTarget::getConstructor(vm, &globalObject);
181}
182
183template<> void JSMediaStreamConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
184{
185 putDirect(vm, vm.propertyNames->prototype, JSMediaStream::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
186 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("MediaStream"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
187 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
188}
189
190template<> const ClassInfo JSMediaStreamConstructor::s_info = { "MediaStream", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaStreamConstructor) };
191
192/* Hash table for prototype */
193
194static const HashTableValue JSMediaStreamPrototypeTableValues[] =
195{
196 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamConstructor) } },
197 { "id", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamId), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
198 { "active", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamActive), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
199 { "onaddtrack", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamOnaddtrack), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamOnaddtrack) } },
200 { "onremovetrack", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsMediaStreamOnremovetrack), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSMediaStreamOnremovetrack) } },
201 { "getAudioTracks", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaStreamPrototypeFunctionGetAudioTracks), (intptr_t) (0) } },
202 { "getVideoTracks", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaStreamPrototypeFunctionGetVideoTracks), (intptr_t) (0) } },
203 { "getTracks", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaStreamPrototypeFunctionGetTracks), (intptr_t) (0) } },
204 { "getTrackById", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaStreamPrototypeFunctionGetTrackById), (intptr_t) (1) } },
205 { "addTrack", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaStreamPrototypeFunctionAddTrack), (intptr_t) (1) } },
206 { "removeTrack", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaStreamPrototypeFunctionRemoveTrack), (intptr_t) (1) } },
207 { "clone", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsMediaStreamPrototypeFunctionClone), (intptr_t) (0) } },
208};
209
210const ClassInfo JSMediaStreamPrototype::s_info = { "MediaStreamPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaStreamPrototype) };
211
212void JSMediaStreamPrototype::finishCreation(VM& vm)
213{
214 Base::finishCreation(vm);
215 reifyStaticProperties(vm, JSMediaStream::info(), JSMediaStreamPrototypeTableValues, *this);
216 putDirect(vm, static_cast<JSVMClientData*>(vm.clientData)->builtinNames().getTracksPrivateName(), JSFunction::create(vm, globalObject(), 0, String(), jsMediaStreamPrototypeFunctionGetTracks), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
217}
218
219const ClassInfo JSMediaStream::s_info = { "MediaStream", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSMediaStream) };
220
221JSMediaStream::JSMediaStream(Structure* structure, JSDOMGlobalObject& globalObject, Ref<MediaStream>&& impl)
222 : JSEventTarget(structure, globalObject, WTFMove(impl))
223{
224}
225
226void JSMediaStream::finishCreation(VM& vm)
227{
228 Base::finishCreation(vm);
229 ASSERT(inherits(vm, info()));
230
231}
232
233JSObject* JSMediaStream::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
234{
235 return JSMediaStreamPrototype::create(vm, &globalObject, JSMediaStreamPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
236}
237
238JSObject* JSMediaStream::prototype(VM& vm, JSDOMGlobalObject& globalObject)
239{
240 return getDOMPrototype<JSMediaStream>(vm, globalObject);
241}
242
243JSValue JSMediaStream::getConstructor(VM& vm, const JSGlobalObject* globalObject)
244{
245 return getDOMConstructor<JSMediaStreamConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
246}
247
248template<> inline JSMediaStream* IDLAttribute<JSMediaStream>::cast(ExecState& state, EncodedJSValue thisValue)
249{
250 return jsDynamicCast<JSMediaStream*>(state.vm(), JSValue::decode(thisValue));
251}
252
253template<> inline JSMediaStream* IDLOperation<JSMediaStream>::cast(ExecState& state)
254{
255 return jsDynamicCast<JSMediaStream*>(state.vm(), state.thisValue());
256}
257
258EncodedJSValue jsMediaStreamConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
259{
260 VM& vm = state->vm();
261 auto throwScope = DECLARE_THROW_SCOPE(vm);
262 auto* prototype = jsDynamicCast<JSMediaStreamPrototype*>(vm, JSValue::decode(thisValue));
263 if (UNLIKELY(!prototype))
264 return throwVMTypeError(state, throwScope);
265 return JSValue::encode(JSMediaStream::getConstructor(state->vm(), prototype->globalObject()));
266}
267
268bool setJSMediaStreamConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
269{
270 VM& vm = state->vm();
271 auto throwScope = DECLARE_THROW_SCOPE(vm);
272 auto* prototype = jsDynamicCast<JSMediaStreamPrototype*>(vm, JSValue::decode(thisValue));
273 if (UNLIKELY(!prototype)) {
274 throwVMTypeError(state, throwScope);
275 return false;
276 }
277 // Shadowing a built-in constructor
278 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
279}
280
281static inline JSValue jsMediaStreamIdGetter(ExecState& state, JSMediaStream& thisObject, ThrowScope& throwScope)
282{
283 UNUSED_PARAM(throwScope);
284 UNUSED_PARAM(state);
285 auto& impl = thisObject.wrapped();
286 JSValue result = toJS<IDLDOMString>(state, throwScope, impl.id());
287 return result;
288}
289
290EncodedJSValue jsMediaStreamId(ExecState* state, EncodedJSValue thisValue, PropertyName)
291{
292 return IDLAttribute<JSMediaStream>::get<jsMediaStreamIdGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "id");
293}
294
295static inline JSValue jsMediaStreamActiveGetter(ExecState& state, JSMediaStream& thisObject, ThrowScope& throwScope)
296{
297 UNUSED_PARAM(throwScope);
298 UNUSED_PARAM(state);
299 auto& impl = thisObject.wrapped();
300 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.active());
301 return result;
302}
303
304EncodedJSValue jsMediaStreamActive(ExecState* state, EncodedJSValue thisValue, PropertyName)
305{
306 return IDLAttribute<JSMediaStream>::get<jsMediaStreamActiveGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "active");
307}
308
309static inline JSValue jsMediaStreamOnaddtrackGetter(ExecState& state, JSMediaStream& thisObject, ThrowScope& throwScope)
310{
311 UNUSED_PARAM(throwScope);
312 UNUSED_PARAM(state);
313 return eventHandlerAttribute(thisObject.wrapped(), eventNames().addtrackEvent, worldForDOMObject(thisObject));
314}
315
316EncodedJSValue jsMediaStreamOnaddtrack(ExecState* state, EncodedJSValue thisValue, PropertyName)
317{
318 return IDLAttribute<JSMediaStream>::get<jsMediaStreamOnaddtrackGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onaddtrack");
319}
320
321static inline bool setJSMediaStreamOnaddtrackSetter(ExecState& state, JSMediaStream& thisObject, JSValue value, ThrowScope& throwScope)
322{
323 UNUSED_PARAM(throwScope);
324 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().addtrackEvent, value);
325 return true;
326}
327
328bool setJSMediaStreamOnaddtrack(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
329{
330 return IDLAttribute<JSMediaStream>::set<setJSMediaStreamOnaddtrackSetter>(*state, thisValue, encodedValue, "onaddtrack");
331}
332
333static inline JSValue jsMediaStreamOnremovetrackGetter(ExecState& state, JSMediaStream& thisObject, ThrowScope& throwScope)
334{
335 UNUSED_PARAM(throwScope);
336 UNUSED_PARAM(state);
337 return eventHandlerAttribute(thisObject.wrapped(), eventNames().removetrackEvent, worldForDOMObject(thisObject));
338}
339
340EncodedJSValue jsMediaStreamOnremovetrack(ExecState* state, EncodedJSValue thisValue, PropertyName)
341{
342 return IDLAttribute<JSMediaStream>::get<jsMediaStreamOnremovetrackGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onremovetrack");
343}
344
345static inline bool setJSMediaStreamOnremovetrackSetter(ExecState& state, JSMediaStream& thisObject, JSValue value, ThrowScope& throwScope)
346{
347 UNUSED_PARAM(throwScope);
348 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().removetrackEvent, value);
349 return true;
350}
351
352bool setJSMediaStreamOnremovetrack(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
353{
354 return IDLAttribute<JSMediaStream>::set<setJSMediaStreamOnremovetrackSetter>(*state, thisValue, encodedValue, "onremovetrack");
355}
356
357static inline JSC::EncodedJSValue jsMediaStreamPrototypeFunctionGetAudioTracksBody(JSC::ExecState* state, typename IDLOperation<JSMediaStream>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
358{
359 UNUSED_PARAM(state);
360 UNUSED_PARAM(throwScope);
361 auto& impl = castedThis->wrapped();
362 return JSValue::encode(toJS<IDLSequence<IDLInterface<MediaStreamTrack>>>(*state, *castedThis->globalObject(), impl.getAudioTracks()));
363}
364
365EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetAudioTracks(ExecState* state)
366{
367 return IDLOperation<JSMediaStream>::call<jsMediaStreamPrototypeFunctionGetAudioTracksBody>(*state, "getAudioTracks");
368}
369
370static inline JSC::EncodedJSValue jsMediaStreamPrototypeFunctionGetVideoTracksBody(JSC::ExecState* state, typename IDLOperation<JSMediaStream>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
371{
372 UNUSED_PARAM(state);
373 UNUSED_PARAM(throwScope);
374 auto& impl = castedThis->wrapped();
375 return JSValue::encode(toJS<IDLSequence<IDLInterface<MediaStreamTrack>>>(*state, *castedThis->globalObject(), impl.getVideoTracks()));
376}
377
378EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetVideoTracks(ExecState* state)
379{
380 return IDLOperation<JSMediaStream>::call<jsMediaStreamPrototypeFunctionGetVideoTracksBody>(*state, "getVideoTracks");
381}
382
383static inline JSC::EncodedJSValue jsMediaStreamPrototypeFunctionGetTracksBody(JSC::ExecState* state, typename IDLOperation<JSMediaStream>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
384{
385 UNUSED_PARAM(state);
386 UNUSED_PARAM(throwScope);
387 auto& impl = castedThis->wrapped();
388 return JSValue::encode(toJS<IDLSequence<IDLInterface<MediaStreamTrack>>>(*state, *castedThis->globalObject(), impl.getTracks()));
389}
390
391EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetTracks(ExecState* state)
392{
393 return IDLOperation<JSMediaStream>::call<jsMediaStreamPrototypeFunctionGetTracksBody>(*state, "getTracks");
394}
395
396static inline JSC::EncodedJSValue jsMediaStreamPrototypeFunctionGetTrackByIdBody(JSC::ExecState* state, typename IDLOperation<JSMediaStream>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
397{
398 UNUSED_PARAM(state);
399 UNUSED_PARAM(throwScope);
400 auto& impl = castedThis->wrapped();
401 if (UNLIKELY(state->argumentCount() < 1))
402 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
403 auto trackId = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
404 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
405 return JSValue::encode(toJS<IDLInterface<MediaStreamTrack>>(*state, *castedThis->globalObject(), impl.getTrackById(WTFMove(trackId))));
406}
407
408EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionGetTrackById(ExecState* state)
409{
410 return IDLOperation<JSMediaStream>::call<jsMediaStreamPrototypeFunctionGetTrackByIdBody>(*state, "getTrackById");
411}
412
413static inline JSC::EncodedJSValue jsMediaStreamPrototypeFunctionAddTrackBody(JSC::ExecState* state, typename IDLOperation<JSMediaStream>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
414{
415 UNUSED_PARAM(state);
416 UNUSED_PARAM(throwScope);
417 auto& impl = castedThis->wrapped();
418 if (UNLIKELY(state->argumentCount() < 1))
419 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
420 auto track = convert<IDLInterface<MediaStreamTrack>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "track", "MediaStream", "addTrack", "MediaStreamTrack"); });
421 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
422 impl.addTrack(*track);
423 return JSValue::encode(jsUndefined());
424}
425
426EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionAddTrack(ExecState* state)
427{
428 return IDLOperation<JSMediaStream>::call<jsMediaStreamPrototypeFunctionAddTrackBody>(*state, "addTrack");
429}
430
431static inline JSC::EncodedJSValue jsMediaStreamPrototypeFunctionRemoveTrackBody(JSC::ExecState* state, typename IDLOperation<JSMediaStream>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
432{
433 UNUSED_PARAM(state);
434 UNUSED_PARAM(throwScope);
435 auto& impl = castedThis->wrapped();
436 if (UNLIKELY(state->argumentCount() < 1))
437 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
438 auto track = convert<IDLInterface<MediaStreamTrack>>(*state, state->uncheckedArgument(0), [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwArgumentTypeError(state, scope, 0, "track", "MediaStream", "removeTrack", "MediaStreamTrack"); });
439 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
440 impl.removeTrack(*track);
441 return JSValue::encode(jsUndefined());
442}
443
444EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionRemoveTrack(ExecState* state)
445{
446 return IDLOperation<JSMediaStream>::call<jsMediaStreamPrototypeFunctionRemoveTrackBody>(*state, "removeTrack");
447}
448
449static inline JSC::EncodedJSValue jsMediaStreamPrototypeFunctionCloneBody(JSC::ExecState* state, typename IDLOperation<JSMediaStream>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
450{
451 UNUSED_PARAM(state);
452 UNUSED_PARAM(throwScope);
453 auto& impl = castedThis->wrapped();
454 return JSValue::encode(toJS<IDLInterface<MediaStream>>(*state, *castedThis->globalObject(), impl.clone()));
455}
456
457EncodedJSValue JSC_HOST_CALL jsMediaStreamPrototypeFunctionClone(ExecState* state)
458{
459 return IDLOperation<JSMediaStream>::call<jsMediaStreamPrototypeFunctionCloneBody>(*state, "clone");
460}
461
462void JSMediaStream::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
463{
464 auto* thisObject = jsCast<JSMediaStream*>(cell);
465 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
466 if (thisObject->scriptExecutionContext())
467 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
468 Base::heapSnapshot(cell, builder);
469}
470
471bool JSMediaStreamOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
472{
473 auto* jsMediaStream = jsCast<JSMediaStream*>(handle.slot()->asCell());
474 if (jsMediaStream->wrapped().hasPendingActivity()) {
475 if (UNLIKELY(reason))
476 *reason = "ActiveDOMObject with pending activity";
477 return true;
478 }
479 if (jsMediaStream->wrapped().isFiringEventListeners()) {
480 if (UNLIKELY(reason))
481 *reason = "EventTarget firing event listeners";
482 return true;
483 }
484 UNUSED_PARAM(visitor);
485 UNUSED_PARAM(reason);
486 return false;
487}
488
489void JSMediaStreamOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
490{
491 auto* jsMediaStream = static_cast<JSMediaStream*>(handle.slot()->asCell());
492 auto& world = *static_cast<DOMWrapperWorld*>(context);
493 uncacheWrapper(world, &jsMediaStream->wrapped(), jsMediaStream);
494}
495
496#if ENABLE(BINDING_INTEGRITY)
497#if PLATFORM(WIN)
498#pragma warning(disable: 4483)
499extern "C" { extern void (*const __identifier("??_7MediaStream@WebCore@@6B@")[])(); }
500#else
501extern "C" { extern void* _ZTVN7WebCore11MediaStreamE[]; }
502#endif
503#endif
504
505JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<MediaStream>&& impl)
506{
507
508#if ENABLE(BINDING_INTEGRITY)
509 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
510#if PLATFORM(WIN)
511 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7MediaStream@WebCore@@6B@"));
512#else
513 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore11MediaStreamE[2]);
514#endif
515
516 // If this fails MediaStream does not have a vtable, so you need to add the
517 // ImplementationLacksVTable attribute to the interface definition
518 static_assert(std::is_polymorphic<MediaStream>::value, "MediaStream is not polymorphic");
519
520 // If you hit this assertion you either have a use after free bug, or
521 // MediaStream has subclasses. If MediaStream has subclasses that get passed
522 // to toJS() we currently require MediaStream you to opt out of binding hardening
523 // by adding the SkipVTableValidation attribute to the interface IDL definition
524 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
525#endif
526 return createWrapper<MediaStream>(globalObject, WTFMove(impl));
527}
528
529JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, MediaStream& impl)
530{
531 return wrap(state, globalObject, impl);
532}
533
534MediaStream* JSMediaStream::toWrapped(JSC::VM& vm, JSC::JSValue value)
535{
536 if (auto* wrapper = jsDynamicCast<JSMediaStream*>(vm, value))
537 return &wrapper->wrapped();
538 return nullptr;
539}
540
541}
542
543#endif // ENABLE(MEDIA_STREAM)
544