Add infrastructure for pointer preparation.
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedSetterThrowingException.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 "JSTestNamedSetterThrowingException.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 jsTestNamedSetterThrowingExceptionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
42 bool setJSTestNamedSetterThrowingExceptionConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
43
44 class JSTestNamedSetterThrowingExceptionPrototype : public JSC::JSNonFinalObject {
45 public:
46     using Base = JSC::JSNonFinalObject;
47     static JSTestNamedSetterThrowingExceptionPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
48     {
49         JSTestNamedSetterThrowingExceptionPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedSetterThrowingExceptionPrototype>(vm.heap)) JSTestNamedSetterThrowingExceptionPrototype(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     JSTestNamedSetterThrowingExceptionPrototype(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 JSTestNamedSetterThrowingExceptionConstructor = JSDOMConstructorNotConstructable<JSTestNamedSetterThrowingException>;
70
71 template<> JSValue JSTestNamedSetterThrowingExceptionConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
72 {
73     UNUSED_PARAM(vm);
74     return globalObject.functionPrototype();
75 }
76
77 template<> void JSTestNamedSetterThrowingExceptionConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
78 {
79     putDirect(vm, vm.propertyNames->prototype, JSTestNamedSetterThrowingException::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
80     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNamedSetterThrowingException"))), 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 JSTestNamedSetterThrowingExceptionConstructor::s_info = { "TestNamedSetterThrowingException", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterThrowingExceptionConstructor) };
85
86 /* Hash table for prototype */
87
88 static const HashTableValue JSTestNamedSetterThrowingExceptionPrototypeTableValues[] =
89 {
90     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedSetterThrowingExceptionConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedSetterThrowingExceptionConstructor) } },
91 };
92
93 const ClassInfo JSTestNamedSetterThrowingExceptionPrototype::s_info = { "TestNamedSetterThrowingExceptionPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterThrowingExceptionPrototype) };
94
95 void JSTestNamedSetterThrowingExceptionPrototype::finishCreation(VM& vm)
96 {
97     Base::finishCreation(vm);
98     reifyStaticProperties(vm, JSTestNamedSetterThrowingException::info(), JSTestNamedSetterThrowingExceptionPrototypeTableValues, *this);
99 }
100
101 const ClassInfo JSTestNamedSetterThrowingException::s_info = { "TestNamedSetterThrowingException", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterThrowingException) };
102
103 JSTestNamedSetterThrowingException::JSTestNamedSetterThrowingException(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedSetterThrowingException>&& impl)
104     : JSDOMWrapper<TestNamedSetterThrowingException>(structure, globalObject, WTFMove(impl))
105 {
106 }
107
108 void JSTestNamedSetterThrowingException::finishCreation(VM& vm)
109 {
110     Base::finishCreation(vm);
111     ASSERT(inherits(vm, info()));
112
113 }
114
115 JSObject* JSTestNamedSetterThrowingException::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
116 {
117     return JSTestNamedSetterThrowingExceptionPrototype::create(vm, &globalObject, JSTestNamedSetterThrowingExceptionPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
118 }
119
120 JSObject* JSTestNamedSetterThrowingException::prototype(VM& vm, JSDOMGlobalObject& globalObject)
121 {
122     return getDOMPrototype<JSTestNamedSetterThrowingException>(vm, globalObject);
123 }
124
125 JSValue JSTestNamedSetterThrowingException::getConstructor(VM& vm, const JSGlobalObject* globalObject)
126 {
127     return getDOMConstructor<JSTestNamedSetterThrowingExceptionConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
128 }
129
130 void JSTestNamedSetterThrowingException::destroy(JSC::JSCell* cell)
131 {
132     JSTestNamedSetterThrowingException* thisObject = static_cast<JSTestNamedSetterThrowingException*>(cell);
133     thisObject->JSTestNamedSetterThrowingException::~JSTestNamedSetterThrowingException();
134 }
135
136 bool JSTestNamedSetterThrowingException::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
137 {
138     auto* thisObject = jsCast<JSTestNamedSetterThrowingException*>(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>(0), value);
150         return true;
151     }
152     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
153 }
154
155 bool JSTestNamedSetterThrowingException::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
156 {
157     auto* thisObject = jsCast<JSTestNamedSetterThrowingException*>(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>(0), value);
170         return true;
171     }
172     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
173 }
174
175 void JSTestNamedSetterThrowingException::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
176 {
177     auto* thisObject = jsCast<JSTestNamedSetterThrowingException*>(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 JSTestNamedSetterThrowingException::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot)
185 {
186     auto* thisObject = jsCast<JSTestNamedSetterThrowingException*>(cell);
187     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
188
189     if (!propertyName.isSymbol()) {
190         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
191         JSValue prototype = thisObject->getPrototypeDirect(state->vm());
192         if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
193             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
194             auto nativeValue = convert<IDLDOMString>(*state, value);
195             RETURN_IF_EXCEPTION(throwScope, true);
196             propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue)));
197             return true;
198         }
199     }
200
201     return JSObject::put(thisObject, state, propertyName, value, putPropertySlot);
202 }
203
204 bool JSTestNamedSetterThrowingException::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool shouldThrow)
205 {
206     auto* thisObject = jsCast<JSTestNamedSetterThrowingException*>(cell);
207     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
208
209     auto propertyName = Identifier::from(state, index);
210     PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
211     JSValue prototype = thisObject->getPrototypeDirect(state->vm());
212     if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
213         auto throwScope = DECLARE_THROW_SCOPE(state->vm());
214         auto nativeValue = convert<IDLDOMString>(*state, value);
215         RETURN_IF_EXCEPTION(throwScope, true);
216         propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue)));
217         return true;
218     }
219
220     return JSObject::putByIndex(cell, state, index, value, shouldThrow);
221 }
222
223 bool JSTestNamedSetterThrowingException::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow)
224 {
225     auto* thisObject = jsCast<JSTestNamedSetterThrowingException*>(object);
226     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
227
228     if (!propertyName.isSymbol()) {
229         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
230         if (!JSObject::getOwnPropertySlot(thisObject, state, propertyName, slot)) {
231             if (!propertyDescriptor.isDataDescriptor())
232                 return false;
233             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
234             auto nativeValue = convert<IDLDOMString>(*state, propertyDescriptor.value());
235             RETURN_IF_EXCEPTION(throwScope, true);
236             propagateException(*state, throwScope, thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue)));
237             return true;
238         }
239     }
240
241     PropertyDescriptor newPropertyDescriptor = propertyDescriptor;
242     newPropertyDescriptor.setConfigurable(true);
243     return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow);
244 }
245
246 EncodedJSValue jsTestNamedSetterThrowingExceptionConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
247 {
248     VM& vm = state->vm();
249     auto throwScope = DECLARE_THROW_SCOPE(vm);
250     auto* prototype = jsDynamicDowncast<JSTestNamedSetterThrowingExceptionPrototype*>(vm, JSValue::decode(thisValue));
251     if (UNLIKELY(!prototype))
252         return throwVMTypeError(state, throwScope);
253     return JSValue::encode(JSTestNamedSetterThrowingException::getConstructor(state->vm(), prototype->globalObject()));
254 }
255
256 bool setJSTestNamedSetterThrowingExceptionConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
257 {
258     VM& vm = state->vm();
259     auto throwScope = DECLARE_THROW_SCOPE(vm);
260     auto* prototype = jsDynamicDowncast<JSTestNamedSetterThrowingExceptionPrototype*>(vm, JSValue::decode(thisValue));
261     if (UNLIKELY(!prototype)) {
262         throwVMTypeError(state, throwScope);
263         return false;
264     }
265     // Shadowing a built-in constructor
266     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
267 }
268
269 bool JSTestNamedSetterThrowingExceptionOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
270 {
271     UNUSED_PARAM(handle);
272     UNUSED_PARAM(visitor);
273     return false;
274 }
275
276 void JSTestNamedSetterThrowingExceptionOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
277 {
278     auto* jsTestNamedSetterThrowingException = static_cast<JSTestNamedSetterThrowingException*>(handle.slot()->asCell());
279     auto& world = *static_cast<DOMWrapperWorld*>(context);
280     uncacheWrapper(world, &jsTestNamedSetterThrowingException->wrapped(), jsTestNamedSetterThrowingException);
281 }
282
283 #if ENABLE(BINDING_INTEGRITY)
284 #if PLATFORM(WIN)
285 #pragma warning(disable: 4483)
286 extern "C" { extern void (*const __identifier("??_7TestNamedSetterThrowingException@WebCore@@6B@")[])(); }
287 #else
288 extern "C" { extern void* _ZTVN7WebCore32TestNamedSetterThrowingExceptionE[]; }
289 #endif
290 #endif
291
292 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedSetterThrowingException>&& impl)
293 {
294
295 #if ENABLE(BINDING_INTEGRITY)
296     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
297 #if PLATFORM(WIN)
298     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedSetterThrowingException@WebCore@@6B@"));
299 #else
300     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore32TestNamedSetterThrowingExceptionE[2]);
301 #endif
302
303     // If this fails TestNamedSetterThrowingException does not have a vtable, so you need to add the
304     // ImplementationLacksVTable attribute to the interface definition
305     static_assert(std::is_polymorphic<TestNamedSetterThrowingException>::value, "TestNamedSetterThrowingException is not polymorphic");
306
307     // If you hit this assertion you either have a use after free bug, or
308     // TestNamedSetterThrowingException has subclasses. If TestNamedSetterThrowingException has subclasses that get passed
309     // to toJS() we currently require TestNamedSetterThrowingException you to opt out of binding hardening
310     // by adding the SkipVTableValidation attribute to the interface IDL definition
311     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
312 #endif
313     return createWrapper<TestNamedSetterThrowingException>(globalObject, WTFMove(impl));
314 }
315
316 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedSetterThrowingException& impl)
317 {
318     return wrap(state, globalObject, impl);
319 }
320
321 TestNamedSetterThrowingException* JSTestNamedSetterThrowingException::toWrapped(JSC::VM& vm, JSC::JSValue value)
322 {
323     if (auto* wrapper = jsDynamicDowncast<JSTestNamedSetterThrowingException*>(vm, value))
324         return &wrapper->wrapped();
325     return nullptr;
326 }
327
328 }