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 "JSWaveShaperNode.h"
26
27#include "JSDOMAttribute.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructorNotConstructable.h"
30#include "JSDOMConvertBufferSource.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMGlobalObject.h"
33#include "JSDOMWrapperCache.h"
34#include "ScriptExecutionContext.h"
35#include <JavaScriptCore/HeapSnapshotBuilder.h>
36#include <JavaScriptCore/JSCInlines.h>
37#include <JavaScriptCore/JSString.h>
38#include <wtf/GetPtr.h>
39#include <wtf/NeverDestroyed.h>
40#include <wtf/PointerPreparations.h>
41#include <wtf/URL.h>
42
43
44namespace WebCore {
45using namespace JSC;
46
47String convertEnumerationToString(WaveShaperNode::OverSampleType enumerationValue)
48{
49 static const NeverDestroyed<String> values[] = {
50 MAKE_STATIC_STRING_IMPL("none"),
51 MAKE_STATIC_STRING_IMPL("2x"),
52 MAKE_STATIC_STRING_IMPL("4x"),
53 };
54 static_assert(static_cast<size_t>(WaveShaperNode::OverSampleType::None) == 0, "WaveShaperNode::OverSampleType::None is not 0 as expected");
55 static_assert(static_cast<size_t>(WaveShaperNode::OverSampleType::_2x) == 1, "WaveShaperNode::OverSampleType::_2x is not 1 as expected");
56 static_assert(static_cast<size_t>(WaveShaperNode::OverSampleType::_4x) == 2, "WaveShaperNode::OverSampleType::_4x is not 2 as expected");
57 ASSERT(static_cast<size_t>(enumerationValue) < WTF_ARRAY_LENGTH(values));
58 return values[static_cast<size_t>(enumerationValue)];
59}
60
61template<> JSString* convertEnumerationToJS(ExecState& state, WaveShaperNode::OverSampleType enumerationValue)
62{
63 return jsStringWithCache(&state, convertEnumerationToString(enumerationValue));
64}
65
66template<> Optional<WaveShaperNode::OverSampleType> parseEnumeration<WaveShaperNode::OverSampleType>(ExecState& state, JSValue value)
67{
68 auto stringValue = value.toWTFString(&state);
69 if (stringValue == "none")
70 return WaveShaperNode::OverSampleType::None;
71 if (stringValue == "2x")
72 return WaveShaperNode::OverSampleType::_2x;
73 if (stringValue == "4x")
74 return WaveShaperNode::OverSampleType::_4x;
75 return WTF::nullopt;
76}
77
78template<> const char* expectedEnumerationValues<WaveShaperNode::OverSampleType>()
79{
80 return "\"none\", \"2x\", \"4x\"";
81}
82
83// Attributes
84
85JSC::EncodedJSValue jsWaveShaperNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
86bool setJSWaveShaperNodeConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
87JSC::EncodedJSValue jsWaveShaperNodeCurve(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
88bool setJSWaveShaperNodeCurve(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
89JSC::EncodedJSValue jsWaveShaperNodeOversample(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
90bool setJSWaveShaperNodeOversample(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
91
92class JSWaveShaperNodePrototype : public JSC::JSNonFinalObject {
93public:
94 using Base = JSC::JSNonFinalObject;
95 static JSWaveShaperNodePrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
96 {
97 JSWaveShaperNodePrototype* ptr = new (NotNull, JSC::allocateCell<JSWaveShaperNodePrototype>(vm.heap)) JSWaveShaperNodePrototype(vm, globalObject, structure);
98 ptr->finishCreation(vm);
99 return ptr;
100 }
101
102 DECLARE_INFO;
103 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
104 {
105 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
106 }
107
108private:
109 JSWaveShaperNodePrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
110 : JSC::JSNonFinalObject(vm, structure)
111 {
112 }
113
114 void finishCreation(JSC::VM&);
115};
116
117using JSWaveShaperNodeConstructor = JSDOMConstructorNotConstructable<JSWaveShaperNode>;
118
119template<> JSValue JSWaveShaperNodeConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
120{
121 return JSAudioNode::getConstructor(vm, &globalObject);
122}
123
124template<> void JSWaveShaperNodeConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
125{
126 putDirect(vm, vm.propertyNames->prototype, JSWaveShaperNode::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
127 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("WaveShaperNode"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
128 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
129}
130
131template<> const ClassInfo JSWaveShaperNodeConstructor::s_info = { "WaveShaperNode", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWaveShaperNodeConstructor) };
132
133/* Hash table for prototype */
134
135static const HashTableValue JSWaveShaperNodePrototypeTableValues[] =
136{
137 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsWaveShaperNodeConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWaveShaperNodeConstructor) } },
138 { "curve", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsWaveShaperNodeCurve), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWaveShaperNodeCurve) } },
139 { "oversample", static_cast<unsigned>(JSC::PropertyAttribute::CustomAccessor | JSC::PropertyAttribute::DOMAttribute), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsWaveShaperNodeOversample), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSWaveShaperNodeOversample) } },
140};
141
142const ClassInfo JSWaveShaperNodePrototype::s_info = { "WaveShaperNodePrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWaveShaperNodePrototype) };
143
144void JSWaveShaperNodePrototype::finishCreation(VM& vm)
145{
146 Base::finishCreation(vm);
147 reifyStaticProperties(vm, JSWaveShaperNode::info(), JSWaveShaperNodePrototypeTableValues, *this);
148}
149
150const ClassInfo JSWaveShaperNode::s_info = { "WaveShaperNode", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSWaveShaperNode) };
151
152JSWaveShaperNode::JSWaveShaperNode(Structure* structure, JSDOMGlobalObject& globalObject, Ref<WaveShaperNode>&& impl)
153 : JSAudioNode(structure, globalObject, WTFMove(impl))
154{
155}
156
157void JSWaveShaperNode::finishCreation(VM& vm)
158{
159 Base::finishCreation(vm);
160 ASSERT(inherits(vm, info()));
161
162}
163
164JSObject* JSWaveShaperNode::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
165{
166 return JSWaveShaperNodePrototype::create(vm, &globalObject, JSWaveShaperNodePrototype::createStructure(vm, &globalObject, JSAudioNode::prototype(vm, globalObject)));
167}
168
169JSObject* JSWaveShaperNode::prototype(VM& vm, JSDOMGlobalObject& globalObject)
170{
171 return getDOMPrototype<JSWaveShaperNode>(vm, globalObject);
172}
173
174JSValue JSWaveShaperNode::getConstructor(VM& vm, const JSGlobalObject* globalObject)
175{
176 return getDOMConstructor<JSWaveShaperNodeConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
177}
178
179template<> inline JSWaveShaperNode* IDLAttribute<JSWaveShaperNode>::cast(ExecState& state, EncodedJSValue thisValue)
180{
181 return jsDynamicCast<JSWaveShaperNode*>(state.vm(), JSValue::decode(thisValue));
182}
183
184EncodedJSValue jsWaveShaperNodeConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
185{
186 VM& vm = state->vm();
187 auto throwScope = DECLARE_THROW_SCOPE(vm);
188 auto* prototype = jsDynamicCast<JSWaveShaperNodePrototype*>(vm, JSValue::decode(thisValue));
189 if (UNLIKELY(!prototype))
190 return throwVMTypeError(state, throwScope);
191 return JSValue::encode(JSWaveShaperNode::getConstructor(state->vm(), prototype->globalObject()));
192}
193
194bool setJSWaveShaperNodeConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
195{
196 VM& vm = state->vm();
197 auto throwScope = DECLARE_THROW_SCOPE(vm);
198 auto* prototype = jsDynamicCast<JSWaveShaperNodePrototype*>(vm, JSValue::decode(thisValue));
199 if (UNLIKELY(!prototype)) {
200 throwVMTypeError(state, throwScope);
201 return false;
202 }
203 // Shadowing a built-in constructor
204 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
205}
206
207static inline JSValue jsWaveShaperNodeCurveGetter(ExecState& state, JSWaveShaperNode& thisObject, ThrowScope& throwScope)
208{
209 UNUSED_PARAM(throwScope);
210 UNUSED_PARAM(state);
211 auto& impl = thisObject.wrapped();
212 JSValue result = toJS<IDLFloat32Array>(state, *thisObject.globalObject(), throwScope, impl.curve());
213 return result;
214}
215
216EncodedJSValue jsWaveShaperNodeCurve(ExecState* state, EncodedJSValue thisValue, PropertyName)
217{
218 return IDLAttribute<JSWaveShaperNode>::get<jsWaveShaperNodeCurveGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "curve");
219}
220
221static inline bool setJSWaveShaperNodeCurveSetter(ExecState& state, JSWaveShaperNode& thisObject, JSValue value, ThrowScope& throwScope)
222{
223 UNUSED_PARAM(throwScope);
224 auto& impl = thisObject.wrapped();
225 auto nativeValue = convert<IDLFloat32Array>(state, value, [](JSC::ExecState& state, JSC::ThrowScope& scope) { throwAttributeTypeError(state, scope, "WaveShaperNode", "curve", "Float32Array"); });
226 RETURN_IF_EXCEPTION(throwScope, false);
227 AttributeSetter::call(state, throwScope, [&] {
228 return impl.setCurve(nativeValue.releaseNonNull());
229 });
230 return true;
231}
232
233bool setJSWaveShaperNodeCurve(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
234{
235 return IDLAttribute<JSWaveShaperNode>::set<setJSWaveShaperNodeCurveSetter>(*state, thisValue, encodedValue, "curve");
236}
237
238static inline JSValue jsWaveShaperNodeOversampleGetter(ExecState& state, JSWaveShaperNode& thisObject, ThrowScope& throwScope)
239{
240 UNUSED_PARAM(throwScope);
241 UNUSED_PARAM(state);
242 auto& impl = thisObject.wrapped();
243 JSValue result = toJS<IDLEnumeration<WaveShaperNode::OverSampleType>>(state, throwScope, impl.oversample());
244 return result;
245}
246
247EncodedJSValue jsWaveShaperNodeOversample(ExecState* state, EncodedJSValue thisValue, PropertyName)
248{
249 return IDLAttribute<JSWaveShaperNode>::get<jsWaveShaperNodeOversampleGetter, CastedThisErrorBehavior::Assert>(*state, thisValue, "oversample");
250}
251
252static inline bool setJSWaveShaperNodeOversampleSetter(ExecState& state, JSWaveShaperNode& thisObject, JSValue value, ThrowScope& throwScope)
253{
254 UNUSED_PARAM(throwScope);
255 auto& impl = thisObject.wrapped();
256 auto optionalNativeValue = parseEnumeration<WaveShaperNode::OverSampleType>(state, value);
257 RETURN_IF_EXCEPTION(throwScope, false);
258 if (UNLIKELY(!optionalNativeValue))
259 return false;
260 auto nativeValue = optionalNativeValue.value();
261 AttributeSetter::call(state, throwScope, [&] {
262 return impl.setOversample(WTFMove(nativeValue));
263 });
264 return true;
265}
266
267bool setJSWaveShaperNodeOversample(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
268{
269 return IDLAttribute<JSWaveShaperNode>::set<setJSWaveShaperNodeOversampleSetter>(*state, thisValue, encodedValue, "oversample");
270}
271
272void JSWaveShaperNode::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
273{
274 auto* thisObject = jsCast<JSWaveShaperNode*>(cell);
275 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
276 if (thisObject->scriptExecutionContext())
277 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
278 Base::heapSnapshot(cell, builder);
279}
280
281#if ENABLE(BINDING_INTEGRITY)
282#if PLATFORM(WIN)
283#pragma warning(disable: 4483)
284extern "C" { extern void (*const __identifier("??_7WaveShaperNode@WebCore@@6B@")[])(); }
285#else
286extern "C" { extern void* _ZTVN7WebCore14WaveShaperNodeE[]; }
287#endif
288#endif
289
290JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<WaveShaperNode>&& impl)
291{
292
293#if ENABLE(BINDING_INTEGRITY)
294 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
295#if PLATFORM(WIN)
296 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7WaveShaperNode@WebCore@@6B@"));
297#else
298 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore14WaveShaperNodeE[2]);
299#endif
300
301 // If this fails WaveShaperNode does not have a vtable, so you need to add the
302 // ImplementationLacksVTable attribute to the interface definition
303 static_assert(std::is_polymorphic<WaveShaperNode>::value, "WaveShaperNode is not polymorphic");
304
305 // If you hit this assertion you either have a use after free bug, or
306 // WaveShaperNode has subclasses. If WaveShaperNode has subclasses that get passed
307 // to toJS() we currently require WaveShaperNode you to opt out of binding hardening
308 // by adding the SkipVTableValidation attribute to the interface IDL definition
309 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
310#endif
311 return createWrapper<WaveShaperNode>(globalObject, WTFMove(impl));
312}
313
314JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, WaveShaperNode& impl)
315{
316 return wrap(state, globalObject, impl);
317}
318
319
320}
321
322#endif // ENABLE(WEB_AUDIO)
323