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