Add infrastructure for pointer preparation.
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedSetterWithIdentifier.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 "JSTestNamedSetterWithIdentifier.h"
23
24 #include "JSDOMAbstractOperations.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructorNotConstructable.h"
27 #include "JSDOMConvertStrings.h"
28 #include "JSDOMExceptionHandling.h"
29 #include "JSDOMOperation.h"
30 #include "JSDOMWrapperCache.h"
31 #include <runtime/FunctionPrototype.h>
32 #include <runtime/JSCInlines.h>
33 #include <wtf/GetPtr.h>
34 #include <wtf/PointerPreparations.h>
35
36
37 namespace WebCore {
38 using namespace JSC;
39
40 // Functions
41
42 JSC::EncodedJSValue JSC_HOST_CALL jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter(JSC::ExecState*);
43
44 // Attributes
45
46 JSC::EncodedJSValue jsTestNamedSetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
47 bool setJSTestNamedSetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
48
49 class JSTestNamedSetterWithIdentifierPrototype : public JSC::JSNonFinalObject {
50 public:
51     using Base = JSC::JSNonFinalObject;
52     static JSTestNamedSetterWithIdentifierPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
53     {
54         JSTestNamedSetterWithIdentifierPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedSetterWithIdentifierPrototype>(vm.heap)) JSTestNamedSetterWithIdentifierPrototype(vm, globalObject, structure);
55         ptr->finishCreation(vm);
56         return ptr;
57     }
58
59     DECLARE_INFO;
60     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
61     {
62         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
63     }
64
65 private:
66     JSTestNamedSetterWithIdentifierPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
67         : JSC::JSNonFinalObject(vm, structure)
68     {
69     }
70
71     void finishCreation(JSC::VM&);
72 };
73
74 using JSTestNamedSetterWithIdentifierConstructor = JSDOMConstructorNotConstructable<JSTestNamedSetterWithIdentifier>;
75
76 template<> JSValue JSTestNamedSetterWithIdentifierConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
77 {
78     UNUSED_PARAM(vm);
79     return globalObject.functionPrototype();
80 }
81
82 template<> void JSTestNamedSetterWithIdentifierConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
83 {
84     putDirect(vm, vm.propertyNames->prototype, JSTestNamedSetterWithIdentifier::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
85     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNamedSetterWithIdentifier"))), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
86     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
87 }
88
89 template<> const ClassInfo JSTestNamedSetterWithIdentifierConstructor::s_info = { "TestNamedSetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifierConstructor) };
90
91 /* Hash table for prototype */
92
93 static const HashTableValue JSTestNamedSetterWithIdentifierPrototypeTableValues[] =
94 {
95     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedSetterWithIdentifierConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedSetterWithIdentifierConstructor) } },
96     { "namedSetter", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<NativeFunction>(jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter), (intptr_t) (2) } },
97 };
98
99 const ClassInfo JSTestNamedSetterWithIdentifierPrototype::s_info = { "TestNamedSetterWithIdentifierPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifierPrototype) };
100
101 void JSTestNamedSetterWithIdentifierPrototype::finishCreation(VM& vm)
102 {
103     Base::finishCreation(vm);
104     reifyStaticProperties(vm, JSTestNamedSetterWithIdentifier::info(), JSTestNamedSetterWithIdentifierPrototypeTableValues, *this);
105 }
106
107 const ClassInfo JSTestNamedSetterWithIdentifier::s_info = { "TestNamedSetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifier) };
108
109 JSTestNamedSetterWithIdentifier::JSTestNamedSetterWithIdentifier(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedSetterWithIdentifier>&& impl)
110     : JSDOMWrapper<TestNamedSetterWithIdentifier>(structure, globalObject, WTFMove(impl))
111 {
112 }
113
114 void JSTestNamedSetterWithIdentifier::finishCreation(VM& vm)
115 {
116     Base::finishCreation(vm);
117     ASSERT(inherits(vm, info()));
118
119 }
120
121 JSObject* JSTestNamedSetterWithIdentifier::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
122 {
123     return JSTestNamedSetterWithIdentifierPrototype::create(vm, &globalObject, JSTestNamedSetterWithIdentifierPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
124 }
125
126 JSObject* JSTestNamedSetterWithIdentifier::prototype(VM& vm, JSDOMGlobalObject& globalObject)
127 {
128     return getDOMPrototype<JSTestNamedSetterWithIdentifier>(vm, globalObject);
129 }
130
131 JSValue JSTestNamedSetterWithIdentifier::getConstructor(VM& vm, const JSGlobalObject* globalObject)
132 {
133     return getDOMConstructor<JSTestNamedSetterWithIdentifierConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
134 }
135
136 void JSTestNamedSetterWithIdentifier::destroy(JSC::JSCell* cell)
137 {
138     JSTestNamedSetterWithIdentifier* thisObject = static_cast<JSTestNamedSetterWithIdentifier*>(cell);
139     thisObject->JSTestNamedSetterWithIdentifier::~JSTestNamedSetterWithIdentifier();
140 }
141
142 bool JSTestNamedSetterWithIdentifier::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
143 {
144     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
145     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
146     using GetterIDLType = IDLDOMString;
147     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> std::optional<typename GetterIDLType::ImplementationType> {
148         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
149         if (!GetterIDLType::isNullValue(result))
150             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
151         return std::nullopt;
152     };
153     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
154         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
155         slot.setValue(thisObject, static_cast<unsigned>(0), value);
156         return true;
157     }
158     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
159 }
160
161 bool JSTestNamedSetterWithIdentifier::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
162 {
163     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
164     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
165     auto propertyName = Identifier::from(state, index);
166     using GetterIDLType = IDLDOMString;
167     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> std::optional<typename GetterIDLType::ImplementationType> {
168         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
169         if (!GetterIDLType::isNullValue(result))
170             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
171         return std::nullopt;
172     };
173     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
174         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
175         slot.setValue(thisObject, static_cast<unsigned>(0), value);
176         return true;
177     }
178     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
179 }
180
181 void JSTestNamedSetterWithIdentifier::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
182 {
183     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
184     ASSERT_GC_OBJECT_INHERITS(object, info());
185     for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
186         propertyNames.add(Identifier::fromString(state, propertyName));
187     JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
188 }
189
190 bool JSTestNamedSetterWithIdentifier::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot)
191 {
192     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
193     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
194
195     if (!propertyName.isSymbol()) {
196         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
197         JSValue prototype = thisObject->getPrototypeDirect(state->vm());
198         if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
199             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
200             auto nativeValue = convert<IDLDOMString>(*state, value);
201             RETURN_IF_EXCEPTION(throwScope, true);
202             thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
203             return true;
204         }
205     }
206
207     return JSObject::put(thisObject, state, propertyName, value, putPropertySlot);
208 }
209
210 bool JSTestNamedSetterWithIdentifier::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool shouldThrow)
211 {
212     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
213     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
214
215     auto propertyName = Identifier::from(state, index);
216     PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
217     JSValue prototype = thisObject->getPrototypeDirect(state->vm());
218     if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
219         auto throwScope = DECLARE_THROW_SCOPE(state->vm());
220         auto nativeValue = convert<IDLDOMString>(*state, value);
221         RETURN_IF_EXCEPTION(throwScope, true);
222         thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
223         return true;
224     }
225
226     return JSObject::putByIndex(cell, state, index, value, shouldThrow);
227 }
228
229 bool JSTestNamedSetterWithIdentifier::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow)
230 {
231     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
232     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
233
234     if (!propertyName.isSymbol()) {
235         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
236         if (!JSObject::getOwnPropertySlot(thisObject, state, propertyName, slot)) {
237             if (!propertyDescriptor.isDataDescriptor())
238                 return false;
239             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
240             auto nativeValue = convert<IDLDOMString>(*state, propertyDescriptor.value());
241             RETURN_IF_EXCEPTION(throwScope, true);
242             thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
243             return true;
244         }
245     }
246
247     PropertyDescriptor newPropertyDescriptor = propertyDescriptor;
248     newPropertyDescriptor.setConfigurable(true);
249     return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow);
250 }
251
252 template<> inline JSTestNamedSetterWithIdentifier* IDLOperation<JSTestNamedSetterWithIdentifier>::cast(ExecState& state)
253 {
254     return jsDynamicDowncast<JSTestNamedSetterWithIdentifier*>(state.vm(), state.thisValue());
255 }
256
257 EncodedJSValue jsTestNamedSetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
258 {
259     VM& vm = state->vm();
260     auto throwScope = DECLARE_THROW_SCOPE(vm);
261     auto* prototype = jsDynamicDowncast<JSTestNamedSetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
262     if (UNLIKELY(!prototype))
263         return throwVMTypeError(state, throwScope);
264     return JSValue::encode(JSTestNamedSetterWithIdentifier::getConstructor(state->vm(), prototype->globalObject()));
265 }
266
267 bool setJSTestNamedSetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
268 {
269     VM& vm = state->vm();
270     auto throwScope = DECLARE_THROW_SCOPE(vm);
271     auto* prototype = jsDynamicDowncast<JSTestNamedSetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
272     if (UNLIKELY(!prototype)) {
273         throwVMTypeError(state, throwScope);
274         return false;
275     }
276     // Shadowing a built-in constructor
277     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
278 }
279
280 static inline JSC::EncodedJSValue jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetterBody(JSC::ExecState* state, typename IDLOperation<JSTestNamedSetterWithIdentifier>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
281 {
282     UNUSED_PARAM(state);
283     UNUSED_PARAM(throwScope);
284     auto& impl = castedThis->wrapped();
285     if (UNLIKELY(state->argumentCount() < 2))
286         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
287     auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
288     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
289     auto value = convert<IDLDOMString>(*state, state->uncheckedArgument(1));
290     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
291     impl.namedSetter(WTFMove(name), WTFMove(value));
292     return JSValue::encode(jsUndefined());
293 }
294
295 EncodedJSValue JSC_HOST_CALL jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter(ExecState* state)
296 {
297     return IDLOperation<JSTestNamedSetterWithIdentifier>::call<jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetterBody>(*state, "namedSetter");
298 }
299
300 bool JSTestNamedSetterWithIdentifierOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
301 {
302     UNUSED_PARAM(handle);
303     UNUSED_PARAM(visitor);
304     return false;
305 }
306
307 void JSTestNamedSetterWithIdentifierOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
308 {
309     auto* jsTestNamedSetterWithIdentifier = static_cast<JSTestNamedSetterWithIdentifier*>(handle.slot()->asCell());
310     auto& world = *static_cast<DOMWrapperWorld*>(context);
311     uncacheWrapper(world, &jsTestNamedSetterWithIdentifier->wrapped(), jsTestNamedSetterWithIdentifier);
312 }
313
314 #if ENABLE(BINDING_INTEGRITY)
315 #if PLATFORM(WIN)
316 #pragma warning(disable: 4483)
317 extern "C" { extern void (*const __identifier("??_7TestNamedSetterWithIdentifier@WebCore@@6B@")[])(); }
318 #else
319 extern "C" { extern void* _ZTVN7WebCore29TestNamedSetterWithIdentifierE[]; }
320 #endif
321 #endif
322
323 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedSetterWithIdentifier>&& impl)
324 {
325
326 #if ENABLE(BINDING_INTEGRITY)
327     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
328 #if PLATFORM(WIN)
329     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedSetterWithIdentifier@WebCore@@6B@"));
330 #else
331     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore29TestNamedSetterWithIdentifierE[2]);
332 #endif
333
334     // If this fails TestNamedSetterWithIdentifier does not have a vtable, so you need to add the
335     // ImplementationLacksVTable attribute to the interface definition
336     static_assert(std::is_polymorphic<TestNamedSetterWithIdentifier>::value, "TestNamedSetterWithIdentifier is not polymorphic");
337
338     // If you hit this assertion you either have a use after free bug, or
339     // TestNamedSetterWithIdentifier has subclasses. If TestNamedSetterWithIdentifier has subclasses that get passed
340     // to toJS() we currently require TestNamedSetterWithIdentifier you to opt out of binding hardening
341     // by adding the SkipVTableValidation attribute to the interface IDL definition
342     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
343 #endif
344     return createWrapper<TestNamedSetterWithIdentifier>(globalObject, WTFMove(impl));
345 }
346
347 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedSetterWithIdentifier& impl)
348 {
349     return wrap(state, globalObject, impl);
350 }
351
352 TestNamedSetterWithIdentifier* JSTestNamedSetterWithIdentifier::toWrapped(JSC::VM& vm, JSC::JSValue value)
353 {
354     if (auto* wrapper = jsDynamicDowncast<JSTestNamedSetterWithIdentifier*>(vm, value))
355         return &wrapper->wrapped();
356     return nullptr;
357 }
358
359 }