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