All prototypes should call didBecomePrototype()
[WebKit.git] / Source / WebCore / bindings / scripts / test / JS / JSTestClassWithJSBuiltinConstructor.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 "JSTestClassWithJSBuiltinConstructor.h"
23
24 #include "JSDOMBinding.h"
25 #include "JSDOMBuiltinConstructor.h"
26 #include "JSDOMExceptionHandling.h"
27 #include "JSDOMWrapperCache.h"
28 #include "ScriptExecutionContext.h"
29 #include "TestClassWithJSBuiltinConstructorBuiltins.h"
30 #include <JavaScriptCore/FunctionPrototype.h>
31 #include <JavaScriptCore/HeapSnapshotBuilder.h>
32 #include <JavaScriptCore/JSCInlines.h>
33 #include <wtf/GetPtr.h>
34 #include <wtf/PointerPreparations.h>
35 #include <wtf/URL.h>
36
37
38 namespace WebCore {
39 using namespace JSC;
40
41 // Attributes
42
43 JSC::EncodedJSValue jsTestClassWithJSBuiltinConstructorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
44 bool setJSTestClassWithJSBuiltinConstructorConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
45
46 class JSTestClassWithJSBuiltinConstructorPrototype : public JSC::JSNonFinalObject {
47 public:
48     using Base = JSC::JSNonFinalObject;
49     static JSTestClassWithJSBuiltinConstructorPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
50     {
51         JSTestClassWithJSBuiltinConstructorPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestClassWithJSBuiltinConstructorPrototype>(vm.heap)) JSTestClassWithJSBuiltinConstructorPrototype(vm, globalObject, structure);
52         ptr->finishCreation(vm);
53         return ptr;
54     }
55
56     DECLARE_INFO;
57     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
58     {
59         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
60     }
61
62 private:
63     JSTestClassWithJSBuiltinConstructorPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
64         : JSC::JSNonFinalObject(vm, structure)
65     {
66         didBecomePrototype();
67     }
68
69     void finishCreation(JSC::VM&);
70 };
71
72 using JSTestClassWithJSBuiltinConstructorConstructor = JSDOMBuiltinConstructor<JSTestClassWithJSBuiltinConstructor>;
73
74 template<> JSValue JSTestClassWithJSBuiltinConstructorConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
75 {
76     UNUSED_PARAM(vm);
77     return globalObject.functionPrototype();
78 }
79
80 template<> void JSTestClassWithJSBuiltinConstructorConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
81 {
82     putDirect(vm, vm.propertyNames->prototype, JSTestClassWithJSBuiltinConstructor::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
83     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestClassWithJSBuiltinConstructor"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
84     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
85 }
86
87 template<> FunctionExecutable* JSTestClassWithJSBuiltinConstructorConstructor::initializeExecutable(VM& vm)
88 {
89     return testClassWithJSBuiltinConstructorInitializeTestClassWithJSBuiltinConstructorCodeGenerator(vm);
90 }
91
92 template<> const ClassInfo JSTestClassWithJSBuiltinConstructorConstructor::s_info = { "TestClassWithJSBuiltinConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestClassWithJSBuiltinConstructorConstructor) };
93
94 /* Hash table for prototype */
95
96 static const HashTableValue JSTestClassWithJSBuiltinConstructorPrototypeTableValues[] =
97 {
98     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestClassWithJSBuiltinConstructorConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestClassWithJSBuiltinConstructorConstructor) } },
99 };
100
101 const ClassInfo JSTestClassWithJSBuiltinConstructorPrototype::s_info = { "TestClassWithJSBuiltinConstructorPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestClassWithJSBuiltinConstructorPrototype) };
102
103 void JSTestClassWithJSBuiltinConstructorPrototype::finishCreation(VM& vm)
104 {
105     Base::finishCreation(vm);
106     reifyStaticProperties(vm, JSTestClassWithJSBuiltinConstructor::info(), JSTestClassWithJSBuiltinConstructorPrototypeTableValues, *this);
107 }
108
109 const ClassInfo JSTestClassWithJSBuiltinConstructor::s_info = { "TestClassWithJSBuiltinConstructor", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestClassWithJSBuiltinConstructor) };
110
111 JSTestClassWithJSBuiltinConstructor::JSTestClassWithJSBuiltinConstructor(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestClassWithJSBuiltinConstructor>&& impl)
112     : JSDOMWrapper<TestClassWithJSBuiltinConstructor>(structure, globalObject, WTFMove(impl))
113 {
114 }
115
116 void JSTestClassWithJSBuiltinConstructor::finishCreation(VM& vm)
117 {
118     Base::finishCreation(vm);
119     ASSERT(inherits(vm, info()));
120
121 }
122
123 JSObject* JSTestClassWithJSBuiltinConstructor::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
124 {
125     return JSTestClassWithJSBuiltinConstructorPrototype::create(vm, &globalObject, JSTestClassWithJSBuiltinConstructorPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
126 }
127
128 JSObject* JSTestClassWithJSBuiltinConstructor::prototype(VM& vm, JSDOMGlobalObject& globalObject)
129 {
130     return getDOMPrototype<JSTestClassWithJSBuiltinConstructor>(vm, globalObject);
131 }
132
133 JSValue JSTestClassWithJSBuiltinConstructor::getConstructor(VM& vm, const JSGlobalObject* globalObject)
134 {
135     return getDOMConstructor<JSTestClassWithJSBuiltinConstructorConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
136 }
137
138 void JSTestClassWithJSBuiltinConstructor::destroy(JSC::JSCell* cell)
139 {
140     JSTestClassWithJSBuiltinConstructor* thisObject = static_cast<JSTestClassWithJSBuiltinConstructor*>(cell);
141     thisObject->JSTestClassWithJSBuiltinConstructor::~JSTestClassWithJSBuiltinConstructor();
142 }
143
144 EncodedJSValue jsTestClassWithJSBuiltinConstructorConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
145 {
146     VM& vm = state->vm();
147     auto throwScope = DECLARE_THROW_SCOPE(vm);
148     auto* prototype = jsDynamicCast<JSTestClassWithJSBuiltinConstructorPrototype*>(vm, JSValue::decode(thisValue));
149     if (UNLIKELY(!prototype))
150         return throwVMTypeError(state, throwScope);
151     return JSValue::encode(JSTestClassWithJSBuiltinConstructor::getConstructor(state->vm(), prototype->globalObject()));
152 }
153
154 bool setJSTestClassWithJSBuiltinConstructorConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
155 {
156     VM& vm = state->vm();
157     auto throwScope = DECLARE_THROW_SCOPE(vm);
158     auto* prototype = jsDynamicCast<JSTestClassWithJSBuiltinConstructorPrototype*>(vm, JSValue::decode(thisValue));
159     if (UNLIKELY(!prototype)) {
160         throwVMTypeError(state, throwScope);
161         return false;
162     }
163     // Shadowing a built-in constructor
164     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
165 }
166
167 void JSTestClassWithJSBuiltinConstructor::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
168 {
169     auto* thisObject = jsCast<JSTestClassWithJSBuiltinConstructor*>(cell);
170     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
171     if (thisObject->scriptExecutionContext())
172         builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
173     Base::heapSnapshot(cell, builder);
174 }
175
176 bool JSTestClassWithJSBuiltinConstructorOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
177 {
178     UNUSED_PARAM(handle);
179     UNUSED_PARAM(visitor);
180     UNUSED_PARAM(reason);
181     return false;
182 }
183
184 void JSTestClassWithJSBuiltinConstructorOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
185 {
186     auto* jsTestClassWithJSBuiltinConstructor = static_cast<JSTestClassWithJSBuiltinConstructor*>(handle.slot()->asCell());
187     auto& world = *static_cast<DOMWrapperWorld*>(context);
188     uncacheWrapper(world, &jsTestClassWithJSBuiltinConstructor->wrapped(), jsTestClassWithJSBuiltinConstructor);
189 }
190
191 #if ENABLE(BINDING_INTEGRITY)
192 #if PLATFORM(WIN)
193 #pragma warning(disable: 4483)
194 extern "C" { extern void (*const __identifier("??_7TestClassWithJSBuiltinConstructor@WebCore@@6B@")[])(); }
195 #else
196 extern "C" { extern void* _ZTVN7WebCore33TestClassWithJSBuiltinConstructorE[]; }
197 #endif
198 #endif
199
200 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestClassWithJSBuiltinConstructor>&& impl)
201 {
202
203 #if ENABLE(BINDING_INTEGRITY)
204     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
205 #if PLATFORM(WIN)
206     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestClassWithJSBuiltinConstructor@WebCore@@6B@"));
207 #else
208     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore33TestClassWithJSBuiltinConstructorE[2]);
209 #endif
210
211     // If this fails TestClassWithJSBuiltinConstructor does not have a vtable, so you need to add the
212     // ImplementationLacksVTable attribute to the interface definition
213     static_assert(std::is_polymorphic<TestClassWithJSBuiltinConstructor>::value, "TestClassWithJSBuiltinConstructor is not polymorphic");
214
215     // If you hit this assertion you either have a use after free bug, or
216     // TestClassWithJSBuiltinConstructor has subclasses. If TestClassWithJSBuiltinConstructor has subclasses that get passed
217     // to toJS() we currently require TestClassWithJSBuiltinConstructor you to opt out of binding hardening
218     // by adding the SkipVTableValidation attribute to the interface IDL definition
219     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
220 #endif
221     return createWrapper<TestClassWithJSBuiltinConstructor>(globalObject, WTFMove(impl));
222 }
223
224 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestClassWithJSBuiltinConstructor& impl)
225 {
226     return wrap(state, globalObject, impl);
227 }
228
229 TestClassWithJSBuiltinConstructor* JSTestClassWithJSBuiltinConstructor::toWrapped(JSC::VM& vm, JSC::JSValue value)
230 {
231     if (auto* wrapper = jsDynamicCast<JSTestClassWithJSBuiltinConstructor*>(vm, value))
232         return &wrapper->wrapped();
233     return nullptr;
234 }
235
236 }