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(VIDEO)
24
25#include "JSHTMLAudioElement.h"
26
27#include "Document.h"
28#include "JSDOMBinding.h"
29#include "JSDOMConstructorNotConstructable.h"
30#include "JSDOMConvertInterface.h"
31#include "JSDOMExceptionHandling.h"
32#include "JSDOMNamedConstructor.h"
33#include "JSDOMWrapperCache.h"
34#include "ScriptExecutionContext.h"
35#include <JavaScriptCore/FunctionPrototype.h>
36#include <JavaScriptCore/HeapSnapshotBuilder.h>
37#include <JavaScriptCore/JSCInlines.h>
38#include <wtf/GetPtr.h>
39#include <wtf/PointerPreparations.h>
40#include <wtf/URL.h>
41
42#if ENABLE(VIDEO)
43#include "JSDOMConvertStrings.h"
44#endif
45
46
47namespace WebCore {
48using namespace JSC;
49
50// Attributes
51
52JSC::EncodedJSValue jsHTMLAudioElementConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
53bool setJSHTMLAudioElementConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
54
55class JSHTMLAudioElementPrototype : public JSC::JSNonFinalObject {
56public:
57 using Base = JSC::JSNonFinalObject;
58 static JSHTMLAudioElementPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
59 {
60 JSHTMLAudioElementPrototype* ptr = new (NotNull, JSC::allocateCell<JSHTMLAudioElementPrototype>(vm.heap)) JSHTMLAudioElementPrototype(vm, globalObject, structure);
61 ptr->finishCreation(vm);
62 return ptr;
63 }
64
65 DECLARE_INFO;
66 static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
67 {
68 return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
69 }
70
71private:
72 JSHTMLAudioElementPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
73 : JSC::JSNonFinalObject(vm, structure)
74 {
75 }
76
77 void finishCreation(JSC::VM&);
78};
79
80using JSHTMLAudioElementConstructor = JSDOMConstructorNotConstructable<JSHTMLAudioElement>;
81using JSHTMLAudioElementNamedConstructor = JSDOMNamedConstructor<JSHTMLAudioElement>;
82
83template<> JSValue JSHTMLAudioElementConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
84{
85 return JSHTMLMediaElement::getConstructor(vm, &globalObject);
86}
87
88template<> void JSHTMLAudioElementConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
89{
90 putDirect(vm, vm.propertyNames->prototype, JSHTMLAudioElement::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
91 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("HTMLAudioElement"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
92 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
93}
94
95template<> const ClassInfo JSHTMLAudioElementConstructor::s_info = { "HTMLAudioElement", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLAudioElementConstructor) };
96
97template<> EncodedJSValue JSC_HOST_CALL JSHTMLAudioElementNamedConstructor::construct(ExecState* state)
98{
99 VM& vm = state->vm();
100 auto throwScope = DECLARE_THROW_SCOPE(vm);
101 UNUSED_PARAM(throwScope);
102 auto* castedThis = jsCast<JSHTMLAudioElementNamedConstructor*>(state->jsCallee());
103 ASSERT(castedThis);
104 auto* context = castedThis->scriptExecutionContext();
105 if (UNLIKELY(!context))
106 return throwConstructorScriptExecutionContextUnavailableError(*state, throwScope, "HTMLAudioElement");
107 ASSERT(context->isDocument());
108 auto& document = downcast<Document>(*context);
109 auto src = state->argument(0).isUndefined() ? nullAtom() : convert<IDLAtomicStringAdaptor<IDLDOMString>>(*state, state->uncheckedArgument(0));
110 RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
111 auto object = HTMLAudioElement::createForJSConstructor(document, WTFMove(src));
112 return JSValue::encode(toJSNewlyCreated<IDLInterface<HTMLAudioElement>>(*state, *castedThis->globalObject(), WTFMove(object)));
113}
114
115template<> JSValue JSHTMLAudioElementNamedConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
116{
117 UNUSED_PARAM(vm);
118 return globalObject.functionPrototype();
119}
120
121template<> void JSHTMLAudioElementNamedConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
122{
123 putDirect(vm, vm.propertyNames->prototype, JSHTMLAudioElement::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
124 putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("Audio"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
125 putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
126}
127
128template<> const ClassInfo JSHTMLAudioElementNamedConstructor::s_info = { "Audio", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLAudioElementNamedConstructor) };
129
130/* Hash table for prototype */
131
132static const HashTableValue JSHTMLAudioElementPrototypeTableValues[] =
133{
134 { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsHTMLAudioElementConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSHTMLAudioElementConstructor) } },
135};
136
137const ClassInfo JSHTMLAudioElementPrototype::s_info = { "HTMLAudioElementPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLAudioElementPrototype) };
138
139void JSHTMLAudioElementPrototype::finishCreation(VM& vm)
140{
141 Base::finishCreation(vm);
142 reifyStaticProperties(vm, JSHTMLAudioElement::info(), JSHTMLAudioElementPrototypeTableValues, *this);
143}
144
145const ClassInfo JSHTMLAudioElement::s_info = { "HTMLAudioElement", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSHTMLAudioElement) };
146
147JSHTMLAudioElement::JSHTMLAudioElement(Structure* structure, JSDOMGlobalObject& globalObject, Ref<HTMLAudioElement>&& impl)
148 : JSHTMLMediaElement(structure, globalObject, WTFMove(impl))
149{
150}
151
152void JSHTMLAudioElement::finishCreation(VM& vm)
153{
154 Base::finishCreation(vm);
155 ASSERT(inherits(vm, info()));
156
157}
158
159JSObject* JSHTMLAudioElement::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
160{
161 return JSHTMLAudioElementPrototype::create(vm, &globalObject, JSHTMLAudioElementPrototype::createStructure(vm, &globalObject, JSHTMLMediaElement::prototype(vm, globalObject)));
162}
163
164JSObject* JSHTMLAudioElement::prototype(VM& vm, JSDOMGlobalObject& globalObject)
165{
166 return getDOMPrototype<JSHTMLAudioElement>(vm, globalObject);
167}
168
169JSValue JSHTMLAudioElement::getConstructor(VM& vm, const JSGlobalObject* globalObject)
170{
171 return getDOMConstructor<JSHTMLAudioElementConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
172}
173
174JSValue JSHTMLAudioElement::getNamedConstructor(VM& vm, JSGlobalObject* globalObject)
175{
176 return getDOMConstructor<JSHTMLAudioElementNamedConstructor>(vm, *jsCast<JSDOMGlobalObject*>(globalObject));
177}
178
179EncodedJSValue jsHTMLAudioElementConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
180{
181 VM& vm = state->vm();
182 auto throwScope = DECLARE_THROW_SCOPE(vm);
183 auto* prototype = jsDynamicCast<JSHTMLAudioElementPrototype*>(vm, JSValue::decode(thisValue));
184 if (UNLIKELY(!prototype))
185 return throwVMTypeError(state, throwScope);
186 return JSValue::encode(JSHTMLAudioElement::getConstructor(state->vm(), prototype->globalObject()));
187}
188
189bool setJSHTMLAudioElementConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
190{
191 VM& vm = state->vm();
192 auto throwScope = DECLARE_THROW_SCOPE(vm);
193 auto* prototype = jsDynamicCast<JSHTMLAudioElementPrototype*>(vm, JSValue::decode(thisValue));
194 if (UNLIKELY(!prototype)) {
195 throwVMTypeError(state, throwScope);
196 return false;
197 }
198 // Shadowing a built-in constructor
199 return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
200}
201
202void JSHTMLAudioElement::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
203{
204 auto* thisObject = jsCast<JSHTMLAudioElement*>(cell);
205 builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
206 if (thisObject->scriptExecutionContext())
207 builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
208 Base::heapSnapshot(cell, builder);
209}
210
211bool JSHTMLAudioElementOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
212{
213 auto* jsHTMLAudioElement = jsCast<JSHTMLAudioElement*>(handle.slot()->asCell());
214 if (jsHTMLAudioElement->wrapped().hasPendingActivity()) {
215 if (UNLIKELY(reason))
216 *reason = "ActiveDOMObject with pending activity";
217 return true;
218 }
219 if (jsHTMLAudioElement->wrapped().isFiringEventListeners()) {
220 if (UNLIKELY(reason))
221 *reason = "EventTarget firing event listeners";
222 return true;
223 }
224 if (JSNodeOwner::isReachableFromOpaqueRoots(handle, 0, visitor, reason))
225 return true;
226 UNUSED_PARAM(visitor);
227 UNUSED_PARAM(reason);
228 return false;
229}
230
231void JSHTMLAudioElementOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
232{
233 auto* jsHTMLAudioElement = static_cast<JSHTMLAudioElement*>(handle.slot()->asCell());
234 auto& world = *static_cast<DOMWrapperWorld*>(context);
235 uncacheWrapper(world, &jsHTMLAudioElement->wrapped(), jsHTMLAudioElement);
236}
237
238#if ENABLE(BINDING_INTEGRITY)
239#if PLATFORM(WIN)
240#pragma warning(disable: 4483)
241extern "C" { extern void (*const __identifier("??_7HTMLAudioElement@WebCore@@6B@")[])(); }
242#else
243extern "C" { extern void* _ZTVN7WebCore16HTMLAudioElementE[]; }
244#endif
245#endif
246
247JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<HTMLAudioElement>&& impl)
248{
249
250#if ENABLE(BINDING_INTEGRITY)
251 void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
252#if PLATFORM(WIN)
253 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7HTMLAudioElement@WebCore@@6B@"));
254#else
255 void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore16HTMLAudioElementE[2]);
256#endif
257
258 // If this fails HTMLAudioElement does not have a vtable, so you need to add the
259 // ImplementationLacksVTable attribute to the interface definition
260 static_assert(std::is_polymorphic<HTMLAudioElement>::value, "HTMLAudioElement is not polymorphic");
261
262 // If you hit this assertion you either have a use after free bug, or
263 // HTMLAudioElement has subclasses. If HTMLAudioElement has subclasses that get passed
264 // to toJS() we currently require HTMLAudioElement you to opt out of binding hardening
265 // by adding the SkipVTableValidation attribute to the interface IDL definition
266 RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
267#endif
268 return createWrapper<HTMLAudioElement>(globalObject, WTFMove(impl));
269}
270
271JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, HTMLAudioElement& impl)
272{
273 return wrap(state, globalObject, impl);
274}
275
276
277}
278
279#endif // ENABLE(VIDEO)
280