Move URL from WebCore to WTF
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedDeleterThrowingException.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 "JSTestNamedDeleterThrowingException.h"
23
24 #include "JSDOMAbstractOperations.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructorNotConstructable.h"
27 #include "JSDOMConvertStrings.h"
28 #include "JSDOMExceptionHandling.h"
29 #include "JSDOMWrapperCache.h"
30 #include "ScriptExecutionContext.h"
31 #include <JavaScriptCore/FunctionPrototype.h>
32 #include <JavaScriptCore/HeapSnapshotBuilder.h>
33 #include <JavaScriptCore/JSCInlines.h>
34 #include <wtf/GetPtr.h>
35 #include <wtf/PointerPreparations.h>
36 #include <wtf/URL.h>
37
38
39 namespace WebCore {
40 using namespace JSC;
41
42 // Attributes
43
44 JSC::EncodedJSValue jsTestNamedDeleterThrowingExceptionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
45 bool setJSTestNamedDeleterThrowingExceptionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
46
47 class JSTestNamedDeleterThrowingExceptionPrototype : public JSC::JSNonFinalObject {
48 public:
49     using Base = JSC::JSNonFinalObject;
50     static JSTestNamedDeleterThrowingExceptionPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
51     {
52         JSTestNamedDeleterThrowingExceptionPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedDeleterThrowingExceptionPrototype>(vm.heap)) JSTestNamedDeleterThrowingExceptionPrototype(vm, globalObject, structure);
53         ptr->finishCreation(vm);
54         return ptr;
55     }
56
57     DECLARE_INFO;
58     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
59     {
60         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
61     }
62
63 private:
64     JSTestNamedDeleterThrowingExceptionPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
65         : JSC::JSNonFinalObject(vm, structure)
66     {
67     }
68
69     void finishCreation(JSC::VM&);
70 };
71
72 using JSTestNamedDeleterThrowingExceptionConstructor = JSDOMConstructorNotConstructable<JSTestNamedDeleterThrowingException>;
73
74 template<> JSValue JSTestNamedDeleterThrowingExceptionConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
75 {
76     UNUSED_PARAM(vm);
77     return globalObject.functionPrototype();
78 }
79
80 template<> void JSTestNamedDeleterThrowingExceptionConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
81 {
82     putDirect(vm, vm.propertyNames->prototype, JSTestNamedDeleterThrowingException::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
83     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestNamedDeleterThrowingException"_s)), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
84     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
85 }
86
87 template<> const ClassInfo JSTestNamedDeleterThrowingExceptionConstructor::s_info = { "TestNamedDeleterThrowingException", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedDeleterThrowingExceptionConstructor) };
88
89 /* Hash table for prototype */
90
91 static const HashTableValue JSTestNamedDeleterThrowingExceptionPrototypeTableValues[] =
92 {
93     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedDeleterThrowingExceptionConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedDeleterThrowingExceptionConstructor) } },
94 };
95
96 const ClassInfo JSTestNamedDeleterThrowingExceptionPrototype::s_info = { "TestNamedDeleterThrowingExceptionPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedDeleterThrowingExceptionPrototype) };
97
98 void JSTestNamedDeleterThrowingExceptionPrototype::finishCreation(VM& vm)
99 {
100     Base::finishCreation(vm);
101     reifyStaticProperties(vm, JSTestNamedDeleterThrowingException::info(), JSTestNamedDeleterThrowingExceptionPrototypeTableValues, *this);
102 }
103
104 const ClassInfo JSTestNamedDeleterThrowingException::s_info = { "TestNamedDeleterThrowingException", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedDeleterThrowingException) };
105
106 JSTestNamedDeleterThrowingException::JSTestNamedDeleterThrowingException(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedDeleterThrowingException>&& impl)
107     : JSDOMWrapper<TestNamedDeleterThrowingException>(structure, globalObject, WTFMove(impl))
108 {
109 }
110
111 void JSTestNamedDeleterThrowingException::finishCreation(VM& vm)
112 {
113     Base::finishCreation(vm);
114     ASSERT(inherits(vm, info()));
115
116 }
117
118 JSObject* JSTestNamedDeleterThrowingException::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
119 {
120     return JSTestNamedDeleterThrowingExceptionPrototype::create(vm, &globalObject, JSTestNamedDeleterThrowingExceptionPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
121 }
122
123 JSObject* JSTestNamedDeleterThrowingException::prototype(VM& vm, JSDOMGlobalObject& globalObject)
124 {
125     return getDOMPrototype<JSTestNamedDeleterThrowingException>(vm, globalObject);
126 }
127
128 JSValue JSTestNamedDeleterThrowingException::getConstructor(VM& vm, const JSGlobalObject* globalObject)
129 {
130     return getDOMConstructor<JSTestNamedDeleterThrowingExceptionConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
131 }
132
133 void JSTestNamedDeleterThrowingException::destroy(JSC::JSCell* cell)
134 {
135     JSTestNamedDeleterThrowingException* thisObject = static_cast<JSTestNamedDeleterThrowingException*>(cell);
136     thisObject->JSTestNamedDeleterThrowingException::~JSTestNamedDeleterThrowingException();
137 }
138
139 bool JSTestNamedDeleterThrowingException::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
140 {
141     auto* thisObject = jsCast<JSTestNamedDeleterThrowingException*>(object);
142     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
143     using GetterIDLType = IDLDOMString;
144     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> std::optional<typename GetterIDLType::ImplementationType> {
145         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
146         if (!GetterIDLType::isNullValue(result))
147             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
148         return std::nullopt;
149     };
150     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
151         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
152         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
153         return true;
154     }
155     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
156 }
157
158 bool JSTestNamedDeleterThrowingException::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
159 {
160     auto* thisObject = jsCast<JSTestNamedDeleterThrowingException*>(object);
161     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
162     auto propertyName = Identifier::from(state, index);
163     using GetterIDLType = IDLDOMString;
164     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> std::optional<typename GetterIDLType::ImplementationType> {
165         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
166         if (!GetterIDLType::isNullValue(result))
167             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
168         return std::nullopt;
169     };
170     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
171         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
172         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
173         return true;
174     }
175     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
176 }
177
178 void JSTestNamedDeleterThrowingException::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
179 {
180     auto* thisObject = jsCast<JSTestNamedDeleterThrowingException*>(object);
181     ASSERT_GC_OBJECT_INHERITS(object, info());
182     for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
183         propertyNames.add(Identifier::fromString(state, propertyName));
184     JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
185 }
186
187 bool JSTestNamedDeleterThrowingException::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName)
188 {
189     auto& thisObject = *jsCast<JSTestNamedDeleterThrowingException*>(cell);
190     auto& impl = thisObject.wrapped();
191     if (isVisibleNamedProperty<OverrideBuiltins::No>(*state, thisObject, propertyName)) {
192         auto result = impl.deleteNamedProperty(propertyNameToString(propertyName));
193         if (result.hasException()) {
194             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
195             propagateException(*state, throwScope, result.releaseException());
196             return true;
197         }
198
199         return result.releaseReturnValue();
200     }
201     return JSObject::deleteProperty(cell, state, propertyName);
202 }
203
204 bool JSTestNamedDeleterThrowingException::deletePropertyByIndex(JSCell* cell, ExecState* state, unsigned index)
205 {
206     auto& thisObject = *jsCast<JSTestNamedDeleterThrowingException*>(cell);
207     auto& impl = thisObject.wrapped();
208     auto propertyName = Identifier::from(state, index);
209     if (isVisibleNamedProperty<OverrideBuiltins::No>(*state, thisObject, propertyName)) {
210         auto result = impl.deleteNamedProperty(propertyNameToString(propertyName));
211         if (result.hasException()) {
212             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
213             propagateException(*state, throwScope, result.releaseException());
214             return true;
215         }
216
217         return result.releaseReturnValue();
218     }
219     return JSObject::deletePropertyByIndex(cell, state, index);
220 }
221
222 EncodedJSValue jsTestNamedDeleterThrowingExceptionConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
223 {
224     VM& vm = state->vm();
225     auto throwScope = DECLARE_THROW_SCOPE(vm);
226     auto* prototype = jsDynamicCast<JSTestNamedDeleterThrowingExceptionPrototype*>(vm, JSValue::decode(thisValue));
227     if (UNLIKELY(!prototype))
228         return throwVMTypeError(state, throwScope);
229     return JSValue::encode(JSTestNamedDeleterThrowingException::getConstructor(state->vm(), prototype->globalObject()));
230 }
231
232 bool setJSTestNamedDeleterThrowingExceptionConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
233 {
234     VM& vm = state->vm();
235     auto throwScope = DECLARE_THROW_SCOPE(vm);
236     auto* prototype = jsDynamicCast<JSTestNamedDeleterThrowingExceptionPrototype*>(vm, JSValue::decode(thisValue));
237     if (UNLIKELY(!prototype)) {
238         throwVMTypeError(state, throwScope);
239         return false;
240     }
241     // Shadowing a built-in constructor
242     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
243 }
244
245 void JSTestNamedDeleterThrowingException::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
246 {
247     auto* thisObject = jsCast<JSTestNamedDeleterThrowingException*>(cell);
248     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
249     if (thisObject->scriptExecutionContext())
250         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
251     Base::heapSnapshot(cell, builder);
252 }
253
254 bool JSTestNamedDeleterThrowingExceptionOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
255 {
256     UNUSED_PARAM(handle);
257     UNUSED_PARAM(visitor);
258     UNUSED_PARAM(reason);
259     return false;
260 }
261
262 void JSTestNamedDeleterThrowingExceptionOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
263 {
264     auto* jsTestNamedDeleterThrowingException = static_cast<JSTestNamedDeleterThrowingException*>(handle.slot()->asCell());
265     auto& world = *static_cast<DOMWrapperWorld*>(context);
266     uncacheWrapper(world, &jsTestNamedDeleterThrowingException->wrapped(), jsTestNamedDeleterThrowingException);
267 }
268
269 #if ENABLE(BINDING_INTEGRITY)
270 #if PLATFORM(WIN)
271 #pragma warning(disable: 4483)
272 extern "C" { extern void (*const __identifier("??_7TestNamedDeleterThrowingException@WebCore@@6B@")[])(); }
273 #else
274 extern "C" { extern void* _ZTVN7WebCore33TestNamedDeleterThrowingExceptionE[]; }
275 #endif
276 #endif
277
278 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedDeleterThrowingException>&& impl)
279 {
280
281 #if ENABLE(BINDING_INTEGRITY)
282     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
283 #if PLATFORM(WIN)
284     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedDeleterThrowingException@WebCore@@6B@"));
285 #else
286     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore33TestNamedDeleterThrowingExceptionE[2]);
287 #endif
288
289     // If this fails TestNamedDeleterThrowingException does not have a vtable, so you need to add the
290     // ImplementationLacksVTable attribute to the interface definition
291     static_assert(std::is_polymorphic<TestNamedDeleterThrowingException>::value, "TestNamedDeleterThrowingException is not polymorphic");
292
293     // If you hit this assertion you either have a use after free bug, or
294     // TestNamedDeleterThrowingException has subclasses. If TestNamedDeleterThrowingException has subclasses that get passed
295     // to toJS() we currently require TestNamedDeleterThrowingException you to opt out of binding hardening
296     // by adding the SkipVTableValidation attribute to the interface IDL definition
297     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
298 #endif
299     return createWrapper<TestNamedDeleterThrowingException>(globalObject, WTFMove(impl));
300 }
301
302 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedDeleterThrowingException& impl)
303 {
304     return wrap(state, globalObject, impl);
305 }
306
307 TestNamedDeleterThrowingException* JSTestNamedDeleterThrowingException::toWrapped(JSC::VM& vm, JSC::JSValue value)
308 {
309     if (auto* wrapper = jsDynamicCast<JSTestNamedDeleterThrowingException*>(vm, value))
310         return &wrapper->wrapped();
311     return nullptr;
312 }
313
314 }