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 "JSSourceBuffer.h"
26
27#include "Document.h"
28#include "EventNames.h"
29#include "JSDOMAttribute.h"
30#include "JSDOMBinding.h"
31#include "JSDOMConstructorNotConstructable.h"
32#include "JSDOMConvertBoolean.h"
33#include "JSDOMConvertBufferSource.h"
34#include "JSDOMConvertInterface.h"
35#include "JSDOMConvertNumbers.h"
36#include "JSDOMConvertStrings.h"
37#include "JSDOMConvertUnion.h"
38#include "JSDOMExceptionHandling.h"
39#include "JSDOMGlobalObject.h"
40#include "JSDOMOperation.h"
41#include "JSDOMWrapperCache.h"
42#include "JSEventListener.h"
43#include "JSTimeRanges.h"
44#include "ScriptExecutionContext.h"
45#include "Settings.h"
46#include <JavaScriptCore/HeapSnapshotBuilder.h>
47#include <JavaScriptCore/JSCInlines.h>
48#include <JavaScriptCore/JSString.h>
49#include <wtf/GetPtr.h>
50#include <wtf/PointerPreparations.h>
51#include <wtf/URL.h>
52#include <wtf/Variant.h>
53
54#if ENABLE(VIDEO_TRACK)
55#include "JSAudioTrackList.h"
56#include "JSTextTrackList.h"
57#include "JSVideoTrackList.h"
58#endif
59
60
61namespace WebCore {
62using namespace JSC;
63
64#if ENABLE(MEDIA_SOURCE)
65
66String convertEnumerationToString(SourceBuffer::AppendMode enumerationValue)
67{
68 static const NeverDestroyed<String> values[] = {
69 MAKE_STATIC_STRING_IMPL("segments"),
70 MAKE_STATIC_STRING_IMPL("sequence"),
71 };
72 static_assert(static_cast<size_t>(SourceBuffer::AppendMode::Segments) == 0, "SourceBuffer::AppendMode::Segments is not 0 as expected");
73 static_assert(static_cast<size_t>(SourceBuffer::AppendMode::Sequence) == 1, "SourceBuffer::AppendMode::Sequence is not 1 as expected");
74 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
75 return values[static_cast<size_t>(enumerationValue)];
76}
77
78template<> JSString* convertEnumerationToJS(ExecState& state, SourceBuffer::AppendMode enumerationValue)
79{
80 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
81}
82
83template<> Optional<SourceBuffer::AppendMode> parseEnumeration<SourceBuffer::AppendMode>(ExecState& state, JSValue value)
84{
85 auto stringValue = value.toWTFString(&state);
86 if (stringValue == "segments")
87 return SourceBuffer::AppendMode::Segments;
88 if (stringValue == "sequence")
89 return SourceBuffer::AppendMode::Sequence;
90 return WTF::nullopt;
91}
92
93template<> const char* expectedEnumerationValues<SourceBuffer::AppendMode>()
94{
95 return "\"segments\", \"sequence\"";
96}
97
98#endif
99
100// Functions
101
102JSC::EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionAppendBuffer(JSC::ExecState*);
103JSC::EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionAbort(JSC::ExecState*);
104JSC::EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionRemove(JSC::ExecState*);
105JSC::EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionChangeType(JSC::ExecState*);
106
107// Attributes
108
109JSC::EncodedJSValue jsSourceBufferConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
110bool setJSSourceBufferConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
111JSC::EncodedJSValue jsSourceBufferMode(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
112bool setJSSourceBufferMode(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
113JSC::EncodedJSValue jsSourceBufferUpdating(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
114JSC::EncodedJSValue jsSourceBufferBuffered(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
115JSC::EncodedJSValue jsSourceBufferTimestampOffset(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
116bool setJSSourceBufferTimestampOffset(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
117#if ENABLE(VIDEO_TRACK)
118JSC::EncodedJSValue jsSourceBufferAudioTracks(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
119#endif
120#if ENABLE(VIDEO_TRACK)
121JSC::EncodedJSValue jsSourceBufferVideoTracks(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
122#endif
123#if ENABLE(VIDEO_TRACK)
124JSC::EncodedJSValue jsSourceBufferTextTracks(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
125#endif
126JSC::EncodedJSValue jsSourceBufferAppendWindowStart(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
127bool setJSSourceBufferAppendWindowStart(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
128JSC::EncodedJSValue jsSourceBufferAppendWindowEnd(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
129bool setJSSourceBufferAppendWindowEnd(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
130JSC::EncodedJSValue jsSourceBufferOnupdatestart(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
131bool setJSSourceBufferOnupdatestart(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
132JSC::EncodedJSValue jsSourceBufferOnupdate(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
133bool setJSSourceBufferOnupdate(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
134JSC::EncodedJSValue jsSourceBufferOnupdateend(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
135bool setJSSourceBufferOnupdateend(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
136JSC::EncodedJSValue jsSourceBufferOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
137bool setJSSourceBufferOnerror(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
138JSC::EncodedJSValue jsSourceBufferOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
139bool setJSSourceBufferOnabort(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
140
141class JSSourceBufferPrototype : public JSC::JSNonFinalObject {
142public:
143 using Base = JSC::JSNonFinalObject;
144 static JSSourceBufferPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
145 {
146 JSSourceBufferPrototype* ptr = new (NotNull, JSC::allocateCell<JSSourceBufferPrototype>(vm.heap)) JSSourceBufferPrototype(vm, globalObject, structure);
147 ptr->finishCreation(vm);
148 return ptr;
149 }
150
151 DECLARE_INFO;
152 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
153 {
154 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
155 }
156
157private:
158 JSSourceBufferPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
159 : JSC::JSNonFinalObject(vm, structure)
160 {
161 }
162
163 void finishCreation(JSC::VM&);
164};
165
166using JSSourceBufferConstructor = JSDOMConstructorNotConstructable<JSSourceBuffer>;
167
168template<> JSValue JSSourceBufferConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
169{
170 return JSEventTarget::getConstructor(vm, &globalObject);
171}
172
173template<> void JSSourceBufferConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
174{
175 putDirect(vm, vm.propertyNames->prototype, JSSourceBuffer::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
176 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("SourceBuffer"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
177 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
178}
179
180template<> const ClassInfo JSSourceBufferConstructor::s_info = { "SourceBuffer", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSourceBufferConstructor) };
181
182/* Hash table for prototype */
183
184static const HashTableValue JSSourceBufferPrototypeTableValues[] =
185{
186 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferConstructor) } },
187 { "mode", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferMode), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferMode) } },
188 { "updating", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferUpdating), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
189 { "buffered", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferBuffered), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
190 { "timestampOffset", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferTimestampOffset), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferTimestampOffset) } },
191#if ENABLE(VIDEO_TRACK)
192 { "audioTracks", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferAudioTracks), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
193#else
194 { 0, 0, NoIntrinsic, { 0, 0 } },
195#endif
196#if ENABLE(VIDEO_TRACK)
197 { "videoTracks", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferVideoTracks), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
198#else
199 { 0, 0, NoIntrinsic, { 0, 0 } },
200#endif
201#if ENABLE(VIDEO_TRACK)
202 { "textTracks", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferTextTracks), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
203#else
204 { 0, 0, NoIntrinsic, { 0, 0 } },
205#endif
206 { "appendWindowStart", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferAppendWindowStart), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferAppendWindowStart) } },
207 { "appendWindowEnd", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferAppendWindowEnd), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferAppendWindowEnd) } },
208 { "onupdatestart", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferOnupdatestart), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferOnupdatestart) } },
209 { "onupdate", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferOnupdate), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferOnupdate) } },
210 { "onupdateend", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferOnupdateend), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferOnupdateend) } },
211 { "onerror", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferOnerror), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferOnerror) } },
212 { "onabort", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsSourceBufferOnabort), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSSourceBufferOnabort) } },
213 { "appendBuffer", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSourceBufferPrototypeFunctionAppendBuffer), (intptr_t) (1) } },
214 { "abort", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSourceBufferPrototypeFunctionAbort), (intptr_t) (0) } },
215 { "remove", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSourceBufferPrototypeFunctionRemove), (intptr_t) (2) } },
216 { "changeType", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsSourceBufferPrototypeFunctionChangeType), (intptr_t) (1) } },
217};
218
219const ClassInfo JSSourceBufferPrototype::s_info = { "SourceBufferPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSourceBufferPrototype) };
220
221void JSSourceBufferPrototype::finishCreation(VM& vm)
222{
223 Base::finishCreation(vm);
224 reifyStaticProperties(vm, JSSourceBuffer::info(), JSSourceBufferPrototypeTableValues, *this);
225 bool hasDisabledRuntimeProperties = false;
226 if (!downcast<Document>(jsCast<JSDOMGlobalObject*>(globalObject())->scriptExecutionContext())->settings().sourceBufferChangeTypeEnabled()) {
227 hasDisabledRuntimeProperties = true;
228 auto propertyName = Identifier::fromString(&vm, reinterpret_cast<const LChar*>("changeType"), strlen("changeType"));
229 VM::DeletePropertyModeScope scope(vm, VM::DeletePropertyMode::IgnoreConfigurable);
230 JSObject::deleteProperty(this, globalObject()->globalExec(), propertyName);
231 }
232 if (hasDisabledRuntimeProperties && structure()->isDictionary())
233 flattenDictionaryObject(vm);
234}
235
236const ClassInfo JSSourceBuffer::s_info = { "SourceBuffer", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSSourceBuffer) };
237
238JSSourceBuffer::JSSourceBuffer(Structure* structure, JSDOMGlobalObject& globalObject, Ref<SourceBuffer>&& impl)
239 : JSEventTarget(structure, globalObject, WTFMove(impl))
240{
241}
242
243void JSSourceBuffer::finishCreation(VM& vm)
244{
245 Base::finishCreation(vm);
246 ASSERT(inherits(vm, info()));
247
248}
249
250JSObject* JSSourceBuffer::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
251{
252 return JSSourceBufferPrototype::create(vm, &globalObject, JSSourceBufferPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
253}
254
255JSObject* JSSourceBuffer::prototype(VM& vm, JSDOMGlobalObject& globalObject)
256{
257 return getDOMPrototype<JSSourceBuffer>(vm, globalObject);
258}
259
260JSValue JSSourceBuffer::getConstructor(VM& vm, const JSGlobalObject* globalObject)
261{
262 return getDOMConstructor<JSSourceBufferConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
263}
264
265template<> inline JSSourceBuffer* IDLAttribute<JSSourceBuffer>::cast(ExecState& state, EncodedJSValue thisValue)
266{
267 return jsDynamicCast<JSSourceBuffer*>(state.vm(), JSValue::decode(thisValue));
268}
269
270template<> inline JSSourceBuffer* IDLOperation<JSSourceBuffer>::cast(ExecState& state)
271{
272 return jsDynamicCast<JSSourceBuffer*>(state.vm(), state.thisValue());
273}
274
275EncodedJSValue jsSourceBufferConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
276{
277 VM& vm = state->vm();
278 auto throwScope = DECLARE_THROW_SCOPE(vm);
279 auto* prototype = jsDynamicCast<JSSourceBufferPrototype*>(vm, JSValue::decode(thisValue));
280 if (UNLIKELY(!prototype))
281 return throwVMTypeError(state, throwScope);
282 return JSValue::encode(JSSourceBuffer::getConstructor(state->vm(), prototype->globalObject()));
283}
284
285bool setJSSourceBufferConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
286{
287 VM& vm = state->vm();
288 auto throwScope = DECLARE_THROW_SCOPE(vm);
289 auto* prototype = jsDynamicCast<JSSourceBufferPrototype*>(vm, JSValue::decode(thisValue));
290 if (UNLIKELY(!prototype)) {
291 throwVMTypeError(state, throwScope);
292 return false;
293 }
294 // Shadowing a built-in constructor
295 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
296}
297
298static inline JSValue jsSourceBufferModeGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
299{
300 UNUSED_PARAM(throwScope);
301 UNUSED_PARAM(state);
302 auto& impl = thisObject.wrapped();
303 JSValue result = toJS<IDLEnumeration<SourceBuffer::AppendMode>>(state, throwScope, impl.mode());
304 return result;
305}
306
307EncodedJSValue jsSourceBufferMode(ExecState* state, EncodedJSValue thisValue, PropertyName)
308{
309 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferModeGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "mode");
310}
311
312static inline bool setJSSourceBufferModeSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
313{
314 UNUSED_PARAM(throwScope);
315 auto& impl = thisObject.wrapped();
316 auto optionalNativeValue = parseEnumeration<SourceBuffer::AppendMode>(state, value);
317 RETURN_IF_EXCEPTION(throwScope, false);
318 if (UNLIKELY(!optionalNativeValue))
319 return false;
320 auto nativeValue = optionalNativeValue.value();
321 AttributeSetter::call(state, throwScope, [&] {
322 return impl.setMode(WTFMove(nativeValue));
323 });
324 return true;
325}
326
327bool setJSSourceBufferMode(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
328{
329 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferModeSetter>(*state, thisValue, encodedValue, "mode");
330}
331
332static inline JSValue jsSourceBufferUpdatingGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
333{
334 UNUSED_PARAM(throwScope);
335 UNUSED_PARAM(state);
336 auto& impl = thisObject.wrapped();
337 JSValue result = toJS<IDLBoolean>(state, throwScope, impl.updating());
338 return result;
339}
340
341EncodedJSValue jsSourceBufferUpdating(ExecState* state, EncodedJSValue thisValue, PropertyName)
342{
343 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferUpdatingGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "updating");
344}
345
346static inline JSValue jsSourceBufferBufferedGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
347{
348 UNUSED_PARAM(throwScope);
349 UNUSED_PARAM(state);
350 auto& impl = thisObject.wrapped();
351 JSValue result = toJS<IDLInterface<TimeRanges>>(state, *thisObject.globalObject(), throwScope, impl.buffered());
352 return result;
353}
354
355EncodedJSValue jsSourceBufferBuffered(ExecState* state, EncodedJSValue thisValue, PropertyName)
356{
357 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferBufferedGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "buffered");
358}
359
360static inline JSValue jsSourceBufferTimestampOffsetGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
361{
362 UNUSED_PARAM(throwScope);
363 UNUSED_PARAM(state);
364 auto& impl = thisObject.wrapped();
365 JSValue result = toJS<IDLDouble>(state, throwScope, impl.timestampOffset());
366 return result;
367}
368
369EncodedJSValue jsSourceBufferTimestampOffset(ExecState* state, EncodedJSValue thisValue, PropertyName)
370{
371 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferTimestampOffsetGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "timestampOffset");
372}
373
374static inline bool setJSSourceBufferTimestampOffsetSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
375{
376 UNUSED_PARAM(throwScope);
377 auto& impl = thisObject.wrapped();
378 auto nativeValue = convert<IDLDouble>(state, value);
379 RETURN_IF_EXCEPTION(throwScope, false);
380 AttributeSetter::call(state, throwScope, [&] {
381 return impl.setTimestampOffset(WTFMove(nativeValue));
382 });
383 return true;
384}
385
386bool setJSSourceBufferTimestampOffset(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
387{
388 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferTimestampOffsetSetter>(*state, thisValue, encodedValue, "timestampOffset");
389}
390
391#if ENABLE(VIDEO_TRACK)
392static inline JSValue jsSourceBufferAudioTracksGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
393{
394 UNUSED_PARAM(throwScope);
395 UNUSED_PARAM(state);
396 auto& impl = thisObject.wrapped();
397 JSValue result = toJS<IDLInterface<AudioTrackList>>(state, *thisObject.globalObject(), throwScope, impl.audioTracks());
398 return result;
399}
400
401EncodedJSValue jsSourceBufferAudioTracks(ExecState* state, EncodedJSValue thisValue, PropertyName)
402{
403 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferAudioTracksGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "audioTracks");
404}
405
406#endif
407
408#if ENABLE(VIDEO_TRACK)
409static inline JSValue jsSourceBufferVideoTracksGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
410{
411 UNUSED_PARAM(throwScope);
412 UNUSED_PARAM(state);
413 auto& impl = thisObject.wrapped();
414 JSValue result = toJS<IDLInterface<VideoTrackList>>(state, *thisObject.globalObject(), throwScope, impl.videoTracks());
415 return result;
416}
417
418EncodedJSValue jsSourceBufferVideoTracks(ExecState* state, EncodedJSValue thisValue, PropertyName)
419{
420 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferVideoTracksGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "videoTracks");
421}
422
423#endif
424
425#if ENABLE(VIDEO_TRACK)
426static inline JSValue jsSourceBufferTextTracksGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
427{
428 UNUSED_PARAM(throwScope);
429 UNUSED_PARAM(state);
430 auto& impl = thisObject.wrapped();
431 JSValue result = toJS<IDLInterface<TextTrackList>>(state, *thisObject.globalObject(), throwScope, impl.textTracks());
432 return result;
433}
434
435EncodedJSValue jsSourceBufferTextTracks(ExecState* state, EncodedJSValue thisValue, PropertyName)
436{
437 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferTextTracksGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "textTracks");
438}
439
440#endif
441
442static inline JSValue jsSourceBufferAppendWindowStartGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
443{
444 UNUSED_PARAM(throwScope);
445 UNUSED_PARAM(state);
446 auto& impl = thisObject.wrapped();
447 JSValue result = toJS<IDLDouble>(state, throwScope, impl.appendWindowStart());
448 return result;
449}
450
451EncodedJSValue jsSourceBufferAppendWindowStart(ExecState* state, EncodedJSValue thisValue, PropertyName)
452{
453 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferAppendWindowStartGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "appendWindowStart");
454}
455
456static inline bool setJSSourceBufferAppendWindowStartSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
457{
458 UNUSED_PARAM(throwScope);
459 auto& impl = thisObject.wrapped();
460 auto nativeValue = convert<IDLDouble>(state, value);
461 RETURN_IF_EXCEPTION(throwScope, false);
462 AttributeSetter::call(state, throwScope, [&] {
463 return impl.setAppendWindowStart(WTFMove(nativeValue));
464 });
465 return true;
466}
467
468bool setJSSourceBufferAppendWindowStart(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
469{
470 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferAppendWindowStartSetter>(*state, thisValue, encodedValue, "appendWindowStart");
471}
472
473static inline JSValue jsSourceBufferAppendWindowEndGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
474{
475 UNUSED_PARAM(throwScope);
476 UNUSED_PARAM(state);
477 auto& impl = thisObject.wrapped();
478 JSValue result = toJS<IDLUnrestrictedDouble>(state, throwScope, impl.appendWindowEnd());
479 return result;
480}
481
482EncodedJSValue jsSourceBufferAppendWindowEnd(ExecState* state, EncodedJSValue thisValue, PropertyName)
483{
484 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferAppendWindowEndGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "appendWindowEnd");
485}
486
487static inline bool setJSSourceBufferAppendWindowEndSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
488{
489 UNUSED_PARAM(throwScope);
490 auto& impl = thisObject.wrapped();
491 auto nativeValue = convert<IDLUnrestrictedDouble>(state, value);
492 RETURN_IF_EXCEPTION(throwScope, false);
493 AttributeSetter::call(state, throwScope, [&] {
494 return impl.setAppendWindowEnd(WTFMove(nativeValue));
495 });
496 return true;
497}
498
499bool setJSSourceBufferAppendWindowEnd(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
500{
501 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferAppendWindowEndSetter>(*state, thisValue, encodedValue, "appendWindowEnd");
502}
503
504static inline JSValue jsSourceBufferOnupdatestartGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
505{
506 UNUSED_PARAM(throwScope);
507 UNUSED_PARAM(state);
508 return eventHandlerAttribute(thisObject.wrapped(), eventNames().updatestartEvent, worldForDOMObject(thisObject));
509}
510
511EncodedJSValue jsSourceBufferOnupdatestart(ExecState* state, EncodedJSValue thisValue, PropertyName)
512{
513 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferOnupdatestartGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onupdatestart");
514}
515
516static inline bool setJSSourceBufferOnupdatestartSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
517{
518 UNUSED_PARAM(throwScope);
519 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().updatestartEvent, value);
520 return true;
521}
522
523bool setJSSourceBufferOnupdatestart(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
524{
525 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferOnupdatestartSetter>(*state, thisValue, encodedValue, "onupdatestart");
526}
527
528static inline JSValue jsSourceBufferOnupdateGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
529{
530 UNUSED_PARAM(throwScope);
531 UNUSED_PARAM(state);
532 return eventHandlerAttribute(thisObject.wrapped(), eventNames().updateEvent, worldForDOMObject(thisObject));
533}
534
535EncodedJSValue jsSourceBufferOnupdate(ExecState* state, EncodedJSValue thisValue, PropertyName)
536{
537 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferOnupdateGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onupdate");
538}
539
540static inline bool setJSSourceBufferOnupdateSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
541{
542 UNUSED_PARAM(throwScope);
543 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().updateEvent, value);
544 return true;
545}
546
547bool setJSSourceBufferOnupdate(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
548{
549 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferOnupdateSetter>(*state, thisValue, encodedValue, "onupdate");
550}
551
552static inline JSValue jsSourceBufferOnupdateendGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
553{
554 UNUSED_PARAM(throwScope);
555 UNUSED_PARAM(state);
556 return eventHandlerAttribute(thisObject.wrapped(), eventNames().updateendEvent, worldForDOMObject(thisObject));
557}
558
559EncodedJSValue jsSourceBufferOnupdateend(ExecState* state, EncodedJSValue thisValue, PropertyName)
560{
561 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferOnupdateendGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onupdateend");
562}
563
564static inline bool setJSSourceBufferOnupdateendSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
565{
566 UNUSED_PARAM(throwScope);
567 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().updateendEvent, value);
568 return true;
569}
570
571bool setJSSourceBufferOnupdateend(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
572{
573 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferOnupdateendSetter>(*state, thisValue, encodedValue, "onupdateend");
574}
575
576static inline JSValue jsSourceBufferOnerrorGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
577{
578 UNUSED_PARAM(throwScope);
579 UNUSED_PARAM(state);
580 return eventHandlerAttribute(thisObject.wrapped(), eventNames().errorEvent, worldForDOMObject(thisObject));
581}
582
583EncodedJSValue jsSourceBufferOnerror(ExecState* state, EncodedJSValue thisValue, PropertyName)
584{
585 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferOnerrorGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onerror");
586}
587
588static inline bool setJSSourceBufferOnerrorSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
589{
590 UNUSED_PARAM(throwScope);
591 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().errorEvent, value);
592 return true;
593}
594
595bool setJSSourceBufferOnerror(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
596{
597 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferOnerrorSetter>(*state, thisValue, encodedValue, "onerror");
598}
599
600static inline JSValue jsSourceBufferOnabortGetter(ExecState& state, JSSourceBuffer& thisObject, ThrowScope& throwScope)
601{
602 UNUSED_PARAM(throwScope);
603 UNUSED_PARAM(state);
604 return eventHandlerAttribute(thisObject.wrapped(), eventNames().abortEvent, worldForDOMObject(thisObject));
605}
606
607EncodedJSValue jsSourceBufferOnabort(ExecState* state, EncodedJSValue thisValue, PropertyName)
608{
609 return IDLAttribute<JSSourceBuffer>::get<jsSourceBufferOnabortGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "onabort");
610}
611
612static inline bool setJSSourceBufferOnabortSetter(ExecState& state, JSSourceBuffer& thisObject, JSValue value, ThrowScope& throwScope)
613{
614 UNUSED_PARAM(throwScope);
615 setEventHandlerAttribute(state, thisObject, thisObject.wrapped(), eventNames().abortEvent, value);
616 return true;
617}
618
619bool setJSSourceBufferOnabort(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
620{
621 return IDLAttribute<JSSourceBuffer>::set<setJSSourceBufferOnabortSetter>(*state, thisValue, encodedValue, "onabort");
622}
623
624static inline JSC::EncodedJSValue jsSourceBufferPrototypeFunctionAppendBufferBody(JSC::ExecState* state, typename IDLOperation<JSSourceBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
625{
626 UNUSED_PARAM(state);
627 UNUSED_PARAM(throwScope);
628 auto& impl = castedThis->wrapped();
629 if (UNLIKELY(state->argumentCount() < 1))
630 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
631 auto data = convert<IDLUnion<IDLArrayBufferView, IDLArrayBuffer>>(*state, state->uncheckedArgument(0));
632 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
633 propagateException(*state, throwScope, impl.appendBuffer(WTFMove(data)));
634 return JSValue::encode(jsUndefined());
635}
636
637EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionAppendBuffer(ExecState* state)
638{
639 return IDLOperation<JSSourceBuffer>::call<jsSourceBufferPrototypeFunctionAppendBufferBody>(*state, "appendBuffer");
640}
641
642static inline JSC::EncodedJSValue jsSourceBufferPrototypeFunctionAbortBody(JSC::ExecState* state, typename IDLOperation<JSSourceBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
643{
644 UNUSED_PARAM(state);
645 UNUSED_PARAM(throwScope);
646 auto& impl = castedThis->wrapped();
647 propagateException(*state, throwScope, impl.abort());
648 return JSValue::encode(jsUndefined());
649}
650
651EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionAbort(ExecState* state)
652{
653 return IDLOperation<JSSourceBuffer>::call<jsSourceBufferPrototypeFunctionAbortBody>(*state, "abort");
654}
655
656static inline JSC::EncodedJSValue jsSourceBufferPrototypeFunctionRemoveBody(JSC::ExecState* state, typename IDLOperation<JSSourceBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
657{
658 UNUSED_PARAM(state);
659 UNUSED_PARAM(throwScope);
660 auto& impl = castedThis->wrapped();
661 if (UNLIKELY(state->argumentCount() < 2))
662 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
663 auto start = convert<IDLDouble>(*state, state->uncheckedArgument(0));
664 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
665 auto end = convert<IDLUnrestrictedDouble>(*state, state->uncheckedArgument(1));
666 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
667 propagateException(*state, throwScope, impl.remove(WTFMove(start), WTFMove(end)));
668 return JSValue::encode(jsUndefined());
669}
670
671EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionRemove(ExecState* state)
672{
673 return IDLOperation<JSSourceBuffer>::call<jsSourceBufferPrototypeFunctionRemoveBody>(*state, "remove");
674}
675
676static inline JSC::EncodedJSValue jsSourceBufferPrototypeFunctionChangeTypeBody(JSC::ExecState* state, typename IDLOperation<JSSourceBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
677{
678 UNUSED_PARAM(state);
679 UNUSED_PARAM(throwScope);
680 auto& impl = castedThis->wrapped();
681 if (UNLIKELY(state->argumentCount() < 1))
682 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
683 auto type = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
684 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
685 propagateException(*state, throwScope, impl.changeType(WTFMove(type)));
686 return JSValue::encode(jsUndefined());
687}
688
689EncodedJSValue JSC_HOST_CALL jsSourceBufferPrototypeFunctionChangeType(ExecState* state)
690{
691 return IDLOperation<JSSourceBuffer>::call<jsSourceBufferPrototypeFunctionChangeTypeBody>(*state, "changeType");
692}
693
694void JSSourceBuffer::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
695{
696 auto* thisObject = jsCast<JSSourceBuffer*>(cell);
697 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
698 if (thisObject->scriptExecutionContext())
699 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
700 Base::heapSnapshot(cell, builder);
701}
702
703bool JSSourceBufferOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
704{
705 auto* jsSourceBuffer = jsCast<JSSourceBuffer*>(handle.slot()->asCell());
706 if (jsSourceBuffer->wrapped().hasPendingActivity()) {
707 if (UNLIKELY(reason))
708 *reason = "ActiveDOMObject with pending activity";
709 return true;
710 }
711 if (jsSourceBuffer->wrapped().isFiringEventListeners()) {
712 if (UNLIKELY(reason))
713 *reason = "EventTarget firing event listeners";
714 return true;
715 }
716 UNUSED_PARAM(visitor);
717 UNUSED_PARAM(reason);
718 return false;
719}
720
721void JSSourceBufferOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
722{
723 auto* jsSourceBuffer = static_cast<JSSourceBuffer*>(handle.slot()->asCell());
724 auto& world = *static_cast<DOMWrapperWorld*>(context);
725 uncacheWrapper(world, &jsSourceBuffer->wrapped(), jsSourceBuffer);
726}
727
728#if ENABLE(BINDING_INTEGRITY)
729#if PLATFORM(WIN)
730#pragma warning(disable: 4483)
731extern "C" { extern void (*const __identifier("??_7SourceBuffer@WebCore@@6B@")[])(); }
732#else
733extern "C" { extern void* _ZTVN7WebCore12SourceBufferE[]; }
734#endif
735#endif
736
737JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<SourceBuffer>&& impl)
738{
739
740#if ENABLE(BINDING_INTEGRITY)
741 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
742#if PLATFORM(WIN)
743 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7SourceBuffer@WebCore@@6B@"));
744#else
745 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore12SourceBufferE[2]);
746#endif
747
748 // If this fails SourceBuffer does not have a vtable, so you need to add the
749 // ImplementationLacksVTable attribute to the interface definition
750 static_assert(std::is_polymorphic<SourceBuffer>::value, "SourceBuffer is not polymorphic");
751
752 // If you hit this assertion you either have a use after free bug, or
753 // SourceBuffer has subclasses. If SourceBuffer has subclasses that get passed
754 // to toJS() we currently require SourceBuffer you to opt out of binding hardening
755 // by adding the SkipVTableValidation attribute to the interface IDL definition
756 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
757#endif
758 return createWrapper<SourceBuffer>(globalObject, WTFMove(impl));
759}
760
761JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, SourceBuffer& impl)
762{
763 return wrap(state, globalObject, impl);
764}
765
766SourceBuffer* JSSourceBuffer::toWrapped(JSC::VM& vm, JSC::JSValue value)
767{
768 if (auto* wrapper = jsDynamicCast<JSSourceBuffer*>(vm, value))
769 return &wrapper->wrapped();
770 return nullptr;
771}
772
773}
774
775#endif // ENABLE(MEDIA_SOURCE)
776