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