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