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