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