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