[WebIDL] Replace general inclusion of JSDOMConvert.h with inclusion of individual...
[WebKit.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedConstructor.cpp
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 #include "JSTestNamedConstructor.h"
23
24 #include "JSDOMBinding.h"
25 #include "JSDOMConstructorNotConstructable.h"
26 #include "JSDOMConvertInterface.h"
27 #include "JSDOMConvertStrings.h"
28 #include "JSDOMExceptionHandling.h"
29 #include "JSDOMNamedConstructor.h"
30 #include "JSDOMWrapperCache.h"
31 #include <runtime/FunctionPrototype.h>
32 #include <runtime/JSCInlines.h>
33 #include <wtf/GetPtr.h>
34
35 using namespace JSC;
36
37 namespace WebCore {
38
39 // Attributes
40
41 JSC::EncodedJSValue jsTestNamedConstructorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
42 bool setJSTestNamedConstructorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
43
44 class JSTestNamedConstructorPrototype : public JSC::JSNonFinalObject {
45 public:
46     using Base = JSC::JSNonFinalObject;
47     static JSTestNamedConstructorPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
48     {
49         JSTestNamedConstructorPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedConstructorPrototype>(vm.heap)) JSTestNamedConstructorPrototype(vm, globalObject, structure);
50         ptr->finishCreation(vm);
51         return ptr;
52     }
53
54     DECLARE_INFO;
55     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
56     {
57         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
58     }
59
60 private:
61     JSTestNamedConstructorPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
62         : JSC::JSNonFinalObject(vm, structure)
63     {
64     }
65
66     void finishCreation(JSC::VM&);
67 };
68
69 using JSTestNamedConstructorConstructor = JSDOMConstructorNotConstructable<JSTestNamedConstructor>;
70 using JSTestNamedConstructorNamedConstructor = JSDOMNamedConstructor<JSTestNamedConstructor>;
71
72 template<> JSValue JSTestNamedConstructorConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
73 {
74     UNUSED_PARAM(vm);
75     return globalObject.functionPrototype();
76 }
77
78 template<> void JSTestNamedConstructorConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
79 {
80     putDirect(vm, vm.propertyNames->prototype, JSTestNamedConstructor::prototype(vm, globalObject), DontDelete | ReadOnly | DontEnum);
81     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNamedConstructor"))), ReadOnly | DontEnum);
82     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
83 }
84
85 template<> const ClassInfo JSTestNamedConstructorConstructor::s_info = { "TestNamedConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedConstructorConstructor) };
86
87 template<> EncodedJSValue JSC_HOST_CALL JSTestNamedConstructorNamedConstructor::construct(ExecState* state)
88 {
89     VM& vm = state->vm();
90     auto throwScope = DECLARE_THROW_SCOPE(vm);
91     UNUSED_PARAM(throwScope);
92     auto* castedThis = jsCast<JSTestNamedConstructorNamedConstructor*>(state->jsCallee());
93     ASSERT(castedThis);
94     if (UNLIKELY(state->argumentCount() < 1))
95         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
96     auto str1 = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
97     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
98     auto str2 = state->argument(1).isUndefined() ? ASCIILiteral("defaultString") : convert<IDLDOMString>(*state, state->uncheckedArgument(1));
99     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
100     auto str3 = state->argument(2).isUndefined() ? String() : convert<IDLDOMString>(*state, state->uncheckedArgument(2));
101     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
102     auto object = TestNamedConstructor::createForJSConstructor(WTFMove(str1), WTFMove(str2), WTFMove(str3));
103     return JSValue::encode(toJSNewlyCreated<IDLInterface<TestNamedConstructor>>(*state, *castedThis->globalObject(), throwScope, WTFMove(object)));
104 }
105
106 template<> JSValue JSTestNamedConstructorNamedConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
107 {
108     UNUSED_PARAM(vm);
109     return globalObject.functionPrototype();
110 }
111
112 template<> void JSTestNamedConstructorNamedConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
113 {
114     putDirect(vm, vm.propertyNames->prototype, JSTestNamedConstructor::prototype(vm, globalObject), DontDelete | ReadOnly | DontEnum);
115     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("Audio"))), ReadOnly | DontEnum);
116     putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontEnum);
117 }
118
119 template<> const ClassInfo JSTestNamedConstructorNamedConstructor::s_info = { "Audio", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedConstructorNamedConstructor) };
120
121 /* Hash table for prototype */
122
123 static const HashTableValue JSTestNamedConstructorPrototypeTableValues[] =
124 {
125     { "constructor", DontEnum, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedConstructorConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedConstructorConstructor) } },
126 };
127
128 const ClassInfo JSTestNamedConstructorPrototype::s_info = { "TestNamedConstructorPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedConstructorPrototype) };
129
130 void JSTestNamedConstructorPrototype::finishCreation(VM& vm)
131 {
132     Base::finishCreation(vm);
133     reifyStaticProperties(vm, JSTestNamedConstructorPrototypeTableValues, *this);
134 }
135
136 const ClassInfo JSTestNamedConstructor::s_info = { "TestNamedConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedConstructor) };
137
138 JSTestNamedConstructor::JSTestNamedConstructor(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedConstructor>&& impl)
139     : JSDOMWrapper<TestNamedConstructor>(structure, globalObject, WTFMove(impl))
140 {
141 }
142
143 void JSTestNamedConstructor::finishCreation(VM& vm)
144 {
145     Base::finishCreation(vm);
146     ASSERT(inherits(vm, info()));
147
148 }
149
150 JSObject* JSTestNamedConstructor::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
151 {
152     return JSTestNamedConstructorPrototype::create(vm, &globalObject, JSTestNamedConstructorPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
153 }
154
155 JSObject* JSTestNamedConstructor::prototype(VM& vm, JSDOMGlobalObject& globalObject)
156 {
157     return getDOMPrototype<JSTestNamedConstructor>(vm, globalObject);
158 }
159
160 JSValue JSTestNamedConstructor::getConstructor(VM& vm, const JSGlobalObject* globalObject)
161 {
162     return getDOMConstructor<JSTestNamedConstructorConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
163 }
164
165 JSValue JSTestNamedConstructor::getNamedConstructor(VM& vm, JSGlobalObject* globalObject)
166 {
167     return getDOMConstructor<JSTestNamedConstructorNamedConstructor>(vm, *jsCast<JSDOMGlobalObject*>(globalObject));
168 }
169
170 void JSTestNamedConstructor::destroy(JSC::JSCell* cell)
171 {
172     JSTestNamedConstructor* thisObject = static_cast<JSTestNamedConstructor*>(cell);
173     thisObject->JSTestNamedConstructor::~JSTestNamedConstructor();
174 }
175
176 EncodedJSValue jsTestNamedConstructorConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
177 {
178     VM& vm = state->vm();
179     auto throwScope = DECLARE_THROW_SCOPE(vm);
180     auto* prototype = jsDynamicDowncast<JSTestNamedConstructorPrototype*>(vm, JSValue::decode(thisValue));
181     if (UNLIKELY(!prototype))
182         return throwVMTypeError(state, throwScope);
183     return JSValue::encode(JSTestNamedConstructor::getConstructor(state->vm(), prototype->globalObject()));
184 }
185
186 bool setJSTestNamedConstructorConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
187 {
188     VM& vm = state->vm();
189     auto throwScope = DECLARE_THROW_SCOPE(vm);
190     auto* prototype = jsDynamicDowncast<JSTestNamedConstructorPrototype*>(vm, JSValue::decode(thisValue));
191     if (UNLIKELY(!prototype)) {
192         throwVMTypeError(state, throwScope);
193         return false;
194     }
195     // Shadowing a built-in constructor
196     return prototype->putDirect(state->vm(), state->propertyNames().constructor, JSValue::decode(encodedValue));
197 }
198
199 bool JSTestNamedConstructorOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
200 {
201     auto* jsTestNamedConstructor = jsCast<JSTestNamedConstructor*>(handle.slot()->asCell());
202     if (jsTestNamedConstructor->wrapped().hasPendingActivity())
203         return true;
204     UNUSED_PARAM(visitor);
205     return false;
206 }
207
208 void JSTestNamedConstructorOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
209 {
210     auto* jsTestNamedConstructor = static_cast<JSTestNamedConstructor*>(handle.slot()->asCell());
211     auto& world = *static_cast<DOMWrapperWorld*>(context);
212     uncacheWrapper(world, &jsTestNamedConstructor->wrapped(), jsTestNamedConstructor);
213 }
214
215 #if ENABLE(BINDING_INTEGRITY)
216 #if PLATFORM(WIN)
217 #pragma warning(disable: 4483)
218 extern "C" { extern void (*const __identifier("??_7TestNamedConstructor@WebCore@@6B@")[])(); }
219 #else
220 extern "C" { extern void* _ZTVN7WebCore20TestNamedConstructorE[]; }
221 #endif
222 #endif
223
224 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedConstructor>&& impl)
225 {
226
227 #if ENABLE(BINDING_INTEGRITY)
228     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
229 #if PLATFORM(WIN)
230     void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestNamedConstructor@WebCore@@6B@"));
231 #else
232     void* expectedVTablePointer = &_ZTVN7WebCore20TestNamedConstructorE[2];
233 #if COMPILER(CLANG)
234     // If this fails TestNamedConstructor does not have a vtable, so you need to add the
235     // ImplementationLacksVTable attribute to the interface definition
236     static_assert(__is_polymorphic(TestNamedConstructor), "TestNamedConstructor is not polymorphic");
237 #endif
238 #endif
239     // If you hit this assertion you either have a use after free bug, or
240     // TestNamedConstructor has subclasses. If TestNamedConstructor has subclasses that get passed
241     // to toJS() we currently require TestNamedConstructor you to opt out of binding hardening
242     // by adding the SkipVTableValidation attribute to the interface IDL definition
243     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
244 #endif
245     return createWrapper<TestNamedConstructor>(globalObject, WTFMove(impl));
246 }
247
248 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedConstructor& impl)
249 {
250     return wrap(state, globalObject, impl);
251 }
252
253 TestNamedConstructor* JSTestNamedConstructor::toWrapped(JSC::VM& vm, JSC::JSValue value)
254 {
255     if (auto* wrapper = jsDynamicDowncast<JSTestNamedConstructor*>(vm, value))
256         return &wrapper->wrapped();
257     return nullptr;
258 }
259
260 }