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