All prototypes should call didBecomePrototype()
[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 "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         didBecomePrototype();
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(ExecState* state)
93 {
94     VM& vm = state->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 }
154
155 JSObject* JSTestNamedConstructor::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
156 {
157     return JSTestNamedConstructorPrototype::create(vm, &globalObject, JSTestNamedConstructorPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
158 }
159
160 JSObject* JSTestNamedConstructor::prototype(VM& vm, JSDOMGlobalObject& globalObject)
161 {
162     return getDOMPrototype<JSTestNamedConstructor>(vm, globalObject);
163 }
164
165 JSValue JSTestNamedConstructor::getConstructor(VM& vm, const JSGlobalObject* globalObject)
166 {
167     return getDOMConstructor<JSTestNamedConstructorConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
168 }
169
170 JSValue JSTestNamedConstructor::getNamedConstructor(VM& vm, JSGlobalObject* globalObject)
171 {
172     return getDOMConstructor<JSTestNamedConstructorNamedConstructor>(vm, *jsCast<JSDOMGlobalObject*>(globalObject));
173 }
174
175 void JSTestNamedConstructor::destroy(JSC::JSCell* cell)
176 {
177     JSTestNamedConstructor* thisObject = static_cast<JSTestNamedConstructor*>(cell);
178     thisObject->JSTestNamedConstructor::~JSTestNamedConstructor();
179 }
180
181 EncodedJSValue jsTestNamedConstructorConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
182 {
183     VM& vm = state->vm();
184     auto throwScope = DECLARE_THROW_SCOPE(vm);
185     auto* prototype = jsDynamicCast<JSTestNamedConstructorPrototype*>(vm, JSValue::decode(thisValue));
186     if (UNLIKELY(!prototype))
187         return throwVMTypeError(state, throwScope);
188     return JSValue::encode(JSTestNamedConstructor::getConstructor(state->vm(), prototype->globalObject()));
189 }
190
191 bool setJSTestNamedConstructorConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
192 {
193     VM& vm = state->vm();
194     auto throwScope = DECLARE_THROW_SCOPE(vm);
195     auto* prototype = jsDynamicCast<JSTestNamedConstructorPrototype*>(vm, JSValue::decode(thisValue));
196     if (UNLIKELY(!prototype)) {
197         throwVMTypeError(state, throwScope);
198         return false;
199     }
200     // Shadowing a built-in constructor
201     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
202 }
203
204 void JSTestNamedConstructor::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
205 {
206     auto* thisObject = jsCast<JSTestNamedConstructor*>(cell);
207     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
208     if (thisObject->scriptExecutionContext())
209         builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
210     Base::heapSnapshot(cell, builder);
211 }
212
213 bool JSTestNamedConstructorOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
214 {
215     auto* jsTestNamedConstructor = jsCast<JSTestNamedConstructor*>(handle.slot()->asCell());
216     if (jsTestNamedConstructor->wrapped().hasPendingActivity()) {
217         if (UNLIKELY(reason))
218             *reason = "ActiveDOMObject with pending activity";
219         return true;
220      }
221     UNUSED_PARAM(visitor);
222     UNUSED_PARAM(reason);
223     return false;
224 }
225
226 void JSTestNamedConstructorOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
227 {
228     auto* jsTestNamedConstructor = static_cast<JSTestNamedConstructor*>(handle.slot()->asCell());
229     auto& world = *static_cast<DOMWrapperWorld*>(context);
230     uncacheWrapper(world, &jsTestNamedConstructor->wrapped(), jsTestNamedConstructor);
231 }
232
233 #if ENABLE(BINDING_INTEGRITY)
234 #if PLATFORM(WIN)
235 #pragma warning(disable: 4483)
236 extern "C" { extern void (*const __identifier("??_7TestNamedConstructor@WebCore@@6B@")[])(); }
237 #else
238 extern "C" { extern void* _ZTVN7WebCore20TestNamedConstructorE[]; }
239 #endif
240 #endif
241
242 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedConstructor>&& impl)
243 {
244
245 #if ENABLE(BINDING_INTEGRITY)
246     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
247 #if PLATFORM(WIN)
248     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedConstructor@WebCore@@6B@"));
249 #else
250     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore20TestNamedConstructorE[2]);
251 #endif
252
253     // If this fails TestNamedConstructor does not have a vtable, so you need to add the
254     // ImplementationLacksVTable attribute to the interface definition
255     static_assert(std::is_polymorphic<TestNamedConstructor>::value, "TestNamedConstructor is not polymorphic");
256
257     // If you hit this assertion you either have a use after free bug, or
258     // TestNamedConstructor has subclasses. If TestNamedConstructor has subclasses that get passed
259     // to toJS() we currently require TestNamedConstructor you to opt out of binding hardening
260     // by adding the SkipVTableValidation attribute to the interface IDL definition
261     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
262 #endif
263     return createWrapper<TestNamedConstructor>(globalObject, WTFMove(impl));
264 }
265
266 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedConstructor& impl)
267 {
268     return wrap(state, globalObject, impl);
269 }
270
271 TestNamedConstructor* JSTestNamedConstructor::toWrapped(JSC::VM& vm, JSC::JSValue value)
272 {
273     if (auto* wrapper = jsDynamicCast<JSTestNamedConstructor*>(vm, value))
274         return &wrapper->wrapped();
275     return nullptr;
276 }
277
278 }