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(WEB_AUDIO)
24
25#include "JSAudioBuffer.h"
26
27#include "JSDOMAttribute.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructorNotConstructable.h"
30#include "JSDOMConvertBufferSource.h"
31#include "JSDOMConvertNumbers.h"
32#include "JSDOMExceptionHandling.h"
33#include "JSDOMGlobalObject.h"
34#include "JSDOMOperation.h"
35#include "JSDOMWrapperCache.h"
36#include "ScriptExecutionContext.h"
37#include <JavaScriptCore/FunctionPrototype.h>
38#include <JavaScriptCore/HeapSnapshotBuilder.h>
39#include <JavaScriptCore/JSCInlines.h>
40#include <wtf/GetPtr.h>
41#include <wtf/PointerPreparations.h>
42#include <wtf/URL.h>
43
44
45namespace WebCore {
46using namespace JSC;
47
48// Functions
49
50JSC::EncodedJSValue JSC_HOST_CALL jsAudioBufferPrototypeFunctionGetChannelData(JSC::ExecState*);
51
52// Attributes
53
54JSC::EncodedJSValue jsAudioBufferConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
55bool setJSAudioBufferConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
56JSC::EncodedJSValue jsAudioBufferLength(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
57JSC::EncodedJSValue jsAudioBufferDuration(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
58JSC::EncodedJSValue jsAudioBufferSampleRate(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
59JSC::EncodedJSValue jsAudioBufferGain(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
60bool setJSAudioBufferGain(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
61JSC::EncodedJSValue jsAudioBufferNumberOfChannels(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
62
63class JSAudioBufferPrototype : public JSC::JSNonFinalObject {
64public:
65 using Base = JSC::JSNonFinalObject;
66 static JSAudioBufferPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
67 {
68 JSAudioBufferPrototype* ptr = new (NotNull, JSC::allocateCell<JSAudioBufferPrototype>(vm.heap)) JSAudioBufferPrototype(vm, globalObject, structure);
69 ptr->finishCreation(vm);
70 return ptr;
71 }
72
73 DECLARE_INFO;
74 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
75 {
76 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
77 }
78
79private:
80 JSAudioBufferPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
81 : JSC::JSNonFinalObject(vm, structure)
82 {
83 }
84
85 void finishCreation(JSC::VM&);
86};
87
88using JSAudioBufferConstructor = JSDOMConstructorNotConstructable<JSAudioBuffer>;
89
90template<> JSValue JSAudioBufferConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
91{
92 UNUSED_PARAM(vm);
93 return globalObject.functionPrototype();
94}
95
96template<> void JSAudioBufferConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
97{
98 putDirect(vm, vm.propertyNames->prototype, JSAudioBuffer::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
99 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("AudioBuffer"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
100 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
101}
102
103template<> const ClassInfo JSAudioBufferConstructor::s_info = { "AudioBuffer", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAudioBufferConstructor) };
104
105/* Hash table for prototype */
106
107static const HashTableValue JSAudioBufferPrototypeTableValues[] =
108{
109 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAudioBufferConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAudioBufferConstructor) } },
110 { "length", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAudioBufferLength), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
111 { "duration", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAudioBufferDuration), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
112 { "sampleRate", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAudioBufferSampleRate), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
113 { "gain", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAudioBufferGain), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSAudioBufferGain) } },
114 { "numberOfChannels", static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsAudioBufferNumberOfChannels), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
115 { "getChannelData", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsAudioBufferPrototypeFunctionGetChannelData), (intptr_t) (1) } },
116};
117
118const ClassInfo JSAudioBufferPrototype::s_info = { "AudioBufferPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAudioBufferPrototype) };
119
120void JSAudioBufferPrototype::finishCreation(VM& vm)
121{
122 Base::finishCreation(vm);
123 reifyStaticProperties(vm, JSAudioBuffer::info(), JSAudioBufferPrototypeTableValues, *this);
124}
125
126const ClassInfo JSAudioBuffer::s_info = { "AudioBuffer", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSAudioBuffer) };
127
128JSAudioBuffer::JSAudioBuffer(Structure* structure, JSDOMGlobalObject& globalObject, Ref<AudioBuffer>&& impl)
129 : JSDOMWrapper<AudioBuffer>(structure, globalObject, WTFMove(impl))
130{
131}
132
133void JSAudioBuffer::finishCreation(VM& vm)
134{
135 Base::finishCreation(vm);
136 ASSERT(inherits(vm, info()));
137
138}
139
140JSObject* JSAudioBuffer::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
141{
142 return JSAudioBufferPrototype::create(vm, &globalObject, JSAudioBufferPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
143}
144
145JSObject* JSAudioBuffer::prototype(VM& vm, JSDOMGlobalObject& globalObject)
146{
147 return getDOMPrototype<JSAudioBuffer>(vm, globalObject);
148}
149
150JSValue JSAudioBuffer::getConstructor(VM& vm, const JSGlobalObject* globalObject)
151{
152 return getDOMConstructor<JSAudioBufferConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
153}
154
155void JSAudioBuffer::destroy(JSC::JSCell* cell)
156{
157 JSAudioBuffer* thisObject = static_cast<JSAudioBuffer*>(cell);
158 thisObject->JSAudioBuffer::~JSAudioBuffer();
159}
160
161template<> inline JSAudioBuffer* IDLAttribute<JSAudioBuffer>::cast(ExecState& state, EncodedJSValue thisValue)
162{
163 return jsDynamicCast<JSAudioBuffer*>(state.vm(), JSValue::decode(thisValue));
164}
165
166template<> inline JSAudioBuffer* IDLOperation<JSAudioBuffer>::cast(ExecState& state)
167{
168 return jsDynamicCast<JSAudioBuffer*>(state.vm(), state.thisValue());
169}
170
171EncodedJSValue jsAudioBufferConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
172{
173 VM& vm = state->vm();
174 auto throwScope = DECLARE_THROW_SCOPE(vm);
175 auto* prototype = jsDynamicCast<JSAudioBufferPrototype*>(vm, JSValue::decode(thisValue));
176 if (UNLIKELY(!prototype))
177 return throwVMTypeError(state, throwScope);
178 return JSValue::encode(JSAudioBuffer::getConstructor(state->vm(), prototype->globalObject()));
179}
180
181bool setJSAudioBufferConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
182{
183 VM& vm = state->vm();
184 auto throwScope = DECLARE_THROW_SCOPE(vm);
185 auto* prototype = jsDynamicCast<JSAudioBufferPrototype*>(vm, JSValue::decode(thisValue));
186 if (UNLIKELY(!prototype)) {
187 throwVMTypeError(state, throwScope);
188 return false;
189 }
190 // Shadowing a built-in constructor
191 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
192}
193
194static inline JSValue jsAudioBufferLengthGetter(ExecState& state, JSAudioBuffer& thisObject, ThrowScope& throwScope)
195{
196 UNUSED_PARAM(throwScope);
197 UNUSED_PARAM(state);
198 auto& impl = thisObject.wrapped();
199 JSValue result = toJS<IDLLong>(state, throwScope, impl.length());
200 return result;
201}
202
203EncodedJSValue jsAudioBufferLength(ExecState* state, EncodedJSValue thisValue, PropertyName)
204{
205 return IDLAttribute<JSAudioBuffer>::get<jsAudioBufferLengthGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "length");
206}
207
208static inline JSValue jsAudioBufferDurationGetter(ExecState& state, JSAudioBuffer& thisObject, ThrowScope& throwScope)
209{
210 UNUSED_PARAM(throwScope);
211 UNUSED_PARAM(state);
212 auto& impl = thisObject.wrapped();
213 JSValue result = toJS<IDLUnrestrictedFloat>(state, throwScope, impl.duration());
214 return result;
215}
216
217EncodedJSValue jsAudioBufferDuration(ExecState* state, EncodedJSValue thisValue, PropertyName)
218{
219 return IDLAttribute<JSAudioBuffer>::get<jsAudioBufferDurationGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "duration");
220}
221
222static inline JSValue jsAudioBufferSampleRateGetter(ExecState& state, JSAudioBuffer& thisObject, ThrowScope& throwScope)
223{
224 UNUSED_PARAM(throwScope);
225 UNUSED_PARAM(state);
226 auto& impl = thisObject.wrapped();
227 JSValue result = toJS<IDLUnrestrictedFloat>(state, throwScope, impl.sampleRate());
228 return result;
229}
230
231EncodedJSValue jsAudioBufferSampleRate(ExecState* state, EncodedJSValue thisValue, PropertyName)
232{
233 return IDLAttribute<JSAudioBuffer>::get<jsAudioBufferSampleRateGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "sampleRate");
234}
235
236static inline JSValue jsAudioBufferGainGetter(ExecState& state, JSAudioBuffer& thisObject, ThrowScope& throwScope)
237{
238 UNUSED_PARAM(throwScope);
239 UNUSED_PARAM(state);
240 auto& impl = thisObject.wrapped();
241 JSValue result = toJS<IDLUnrestrictedFloat>(state, throwScope, impl.gain());
242 return result;
243}
244
245EncodedJSValue jsAudioBufferGain(ExecState* state, EncodedJSValue thisValue, PropertyName)
246{
247 return IDLAttribute<JSAudioBuffer>::get<jsAudioBufferGainGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "gain");
248}
249
250static inline bool setJSAudioBufferGainSetter(ExecState& state, JSAudioBuffer& thisObject, JSValue value, ThrowScope& throwScope)
251{
252 UNUSED_PARAM(throwScope);
253 auto& impl = thisObject.wrapped();
254 auto nativeValue = convert<IDLUnrestrictedFloat>(state, value);
255 RETURN_IF_EXCEPTION(throwScope, false);
256 AttributeSetter::call(state, throwScope, [&] {
257 return impl.setGain(WTFMove(nativeValue));
258 });
259 return true;
260}
261
262bool setJSAudioBufferGain(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
263{
264 return IDLAttribute<JSAudioBuffer>::set<setJSAudioBufferGainSetter>(*state, thisValue, encodedValue, "gain");
265}
266
267static inline JSValue jsAudioBufferNumberOfChannelsGetter(ExecState& state, JSAudioBuffer& thisObject, ThrowScope& throwScope)
268{
269 UNUSED_PARAM(throwScope);
270 UNUSED_PARAM(state);
271 auto& impl = thisObject.wrapped();
272 JSValue result = toJS<IDLUnsignedLong>(state, throwScope, impl.numberOfChannels());
273 return result;
274}
275
276EncodedJSValue jsAudioBufferNumberOfChannels(ExecState* state, EncodedJSValue thisValue, PropertyName)
277{
278 return IDLAttribute<JSAudioBuffer>::get<jsAudioBufferNumberOfChannelsGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "numberOfChannels");
279}
280
281static inline JSC::EncodedJSValue jsAudioBufferPrototypeFunctionGetChannelDataBody(JSC::ExecState* state, typename IDLOperation<JSAudioBuffer>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
282{
283 UNUSED_PARAM(state);
284 UNUSED_PARAM(throwScope);
285 auto& impl = castedThis->wrapped();
286 if (UNLIKELY(state->argumentCount() < 1))
287 return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
288 auto channelIndex = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
289 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
290 return JSValue::encode(toJS<IDLFloat32Array>(*state, *castedThis->globalObject(), throwScope, impl.getChannelData(WTFMove(channelIndex))));
291}
292
293EncodedJSValue JSC_HOST_CALL jsAudioBufferPrototypeFunctionGetChannelData(ExecState* state)
294{
295 return IDLOperation<JSAudioBuffer>::call<jsAudioBufferPrototypeFunctionGetChannelDataBody>(*state, "getChannelData");
296}
297
298void JSAudioBuffer::visitChildren(JSCell* cell, SlotVisitor& visitor)
299{
300 auto* thisObject = jsCast<JSAudioBuffer*>(cell);
301 ASSERT_GC_OBJECT_INHERITS(thisObject, info());
302 Base::visitChildren(thisObject, visitor);
303 visitor.reportExtraMemoryVisited(thisObject->wrapped().memoryCost());
304}
305
306size_t JSAudioBuffer::estimatedSize(JSCell* cell, VM& vm)
307{
308 auto* thisObject = jsCast<JSAudioBuffer*>(cell);
309 return Base::estimatedSize(thisObject, vm) + thisObject->wrapped().memoryCost();
310}
311
312void JSAudioBuffer::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
313{
314 auto* thisObject = jsCast<JSAudioBuffer*>(cell);
315 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
316 if (thisObject->scriptExecutionContext())
317 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
318 Base::heapSnapshot(cell, builder);
319}
320
321bool JSAudioBufferOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
322{
323 UNUSED_PARAM(handle);
324 UNUSED_PARAM(visitor);
325 UNUSED_PARAM(reason);
326 return false;
327}
328
329void JSAudioBufferOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
330{
331 auto* jsAudioBuffer = static_cast<JSAudioBuffer*>(handle.slot()->asCell());
332 auto& world = *static_cast<DOMWrapperWorld*>(context);
333 uncacheWrapper(world, &jsAudioBuffer->wrapped(), jsAudioBuffer);
334}
335
336JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<AudioBuffer>&& impl)
337{
338 // If you hit this failure the interface definition has the ImplementationLacksVTable
339 // attribute. You should remove that attribute. If the class has subclasses
340 // that may be passed through this toJS() function you should use the SkipVTableValidation
341 // attribute to AudioBuffer.
342 static_assert(!std::is_polymorphic<AudioBuffer>::value, "AudioBuffer is polymorphic but the IDL claims it is not");
343 globalObject->vm().heap.reportExtraMemoryAllocated(impl->memoryCost());
344 return createWrapper<AudioBuffer>(globalObject, WTFMove(impl));
345}
346
347JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, AudioBuffer& impl)
348{
349 return wrap(state, globalObject, impl);
350}
351
352AudioBuffer* JSAudioBuffer::toWrapped(JSC::VM& vm, JSC::JSValue value)
353{
354 if (auto* wrapper = jsDynamicCast<JSAudioBuffer*>(vm, value))
355 return &wrapper->wrapped();
356 return nullptr;
357}
358
359}
360
361#endif // ENABLE(WEB_AUDIO)
362