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