c752fd00c9a09eda75bbf498cc63d6c780f54637
[WebKit.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedGetterWithIdentifier.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 "JSTestNamedGetterWithIdentifier.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 <JavaScriptCore/FunctionPrototype.h>
32 #include <JavaScriptCore/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 jsTestNamedGetterWithIdentifierPrototypeFunctionGetterName(JSC::ExecState*);
43
44 // Attributes
45
46 JSC::EncodedJSValue jsTestNamedGetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
47 bool setJSTestNamedGetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
48
49 class JSTestNamedGetterWithIdentifierPrototype : public JSC::JSNonFinalObject {
50 public:
51     using Base = JSC::JSNonFinalObject;
52     static JSTestNamedGetterWithIdentifierPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
53     {
54         JSTestNamedGetterWithIdentifierPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedGetterWithIdentifierPrototype>(vm.heap)) JSTestNamedGetterWithIdentifierPrototype(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     JSTestNamedGetterWithIdentifierPrototype(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 JSTestNamedGetterWithIdentifierConstructor = JSDOMConstructorNotConstructable<JSTestNamedGetterWithIdentifier>;
75
76 template<> JSValue JSTestNamedGetterWithIdentifierConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
77 {
78     UNUSED_PARAM(vm);
79     return globalObject.functionPrototype();
80 }
81
82 template<> void JSTestNamedGetterWithIdentifierConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
83 {
84     putDirect(vm, vm.propertyNames->prototype, JSTestNamedGetterWithIdentifier::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
85     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestNamedGetterWithIdentifier"_s)), 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 JSTestNamedGetterWithIdentifierConstructor::s_info = { "TestNamedGetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterWithIdentifierConstructor) };
90
91 /* Hash table for prototype */
92
93 static const HashTableValue JSTestNamedGetterWithIdentifierPrototypeTableValues[] =
94 {
95     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedGetterWithIdentifierConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedGetterWithIdentifierConstructor) } },
96     { "getterName", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestNamedGetterWithIdentifierPrototypeFunctionGetterName), (intptr_t) (1) } },
97 };
98
99 const ClassInfo JSTestNamedGetterWithIdentifierPrototype::s_info = { "TestNamedGetterWithIdentifierPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterWithIdentifierPrototype) };
100
101 void JSTestNamedGetterWithIdentifierPrototype::finishCreation(VM& vm)
102 {
103     Base::finishCreation(vm);
104     reifyStaticProperties(vm, JSTestNamedGetterWithIdentifier::info(), JSTestNamedGetterWithIdentifierPrototypeTableValues, *this);
105 }
106
107 const ClassInfo JSTestNamedGetterWithIdentifier::s_info = { "TestNamedGetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterWithIdentifier) };
108
109 JSTestNamedGetterWithIdentifier::JSTestNamedGetterWithIdentifier(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedGetterWithIdentifier>&& impl)
110     : JSDOMWrapper<TestNamedGetterWithIdentifier>(structure, globalObject, WTFMove(impl))
111 {
112 }
113
114 void JSTestNamedGetterWithIdentifier::finishCreation(VM& vm)
115 {
116     Base::finishCreation(vm);
117     ASSERT(inherits(vm, info()));
118
119 }
120
121 JSObject* JSTestNamedGetterWithIdentifier::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
122 {
123     return JSTestNamedGetterWithIdentifierPrototype::create(vm, &globalObject, JSTestNamedGetterWithIdentifierPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
124 }
125
126 JSObject* JSTestNamedGetterWithIdentifier::prototype(VM& vm, JSDOMGlobalObject& globalObject)
127 {
128     return getDOMPrototype<JSTestNamedGetterWithIdentifier>(vm, globalObject);
129 }
130
131 JSValue JSTestNamedGetterWithIdentifier::getConstructor(VM& vm, const JSGlobalObject* globalObject)
132 {
133     return getDOMConstructor<JSTestNamedGetterWithIdentifierConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
134 }
135
136 void JSTestNamedGetterWithIdentifier::destroy(JSC::JSCell* cell)
137 {
138     JSTestNamedGetterWithIdentifier* thisObject = static_cast<JSTestNamedGetterWithIdentifier*>(cell);
139     thisObject->JSTestNamedGetterWithIdentifier::~JSTestNamedGetterWithIdentifier();
140 }
141
142 bool JSTestNamedGetterWithIdentifier::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
143 {
144     auto* thisObject = jsCast<JSTestNamedGetterWithIdentifier*>(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().getterName(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>(JSC::PropertyAttribute::ReadOnly), value);
156         return true;
157     }
158     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
159 }
160
161 bool JSTestNamedGetterWithIdentifier::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
162 {
163     auto* thisObject = jsCast<JSTestNamedGetterWithIdentifier*>(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().getterName(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>(JSC::PropertyAttribute::ReadOnly), value);
176         return true;
177     }
178     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
179 }
180
181 void JSTestNamedGetterWithIdentifier::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
182 {
183     auto* thisObject = jsCast<JSTestNamedGetterWithIdentifier*>(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 template<> inline JSTestNamedGetterWithIdentifier* IDLOperation<JSTestNamedGetterWithIdentifier>::cast(ExecState& state)
191 {
192     return jsDynamicCast<JSTestNamedGetterWithIdentifier*>(state.vm(), state.thisValue());
193 }
194
195 EncodedJSValue jsTestNamedGetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
196 {
197     VM& vm = state->vm();
198     auto throwScope = DECLARE_THROW_SCOPE(vm);
199     auto* prototype = jsDynamicCast<JSTestNamedGetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
200     if (UNLIKELY(!prototype))
201         return throwVMTypeError(state, throwScope);
202     return JSValue::encode(JSTestNamedGetterWithIdentifier::getConstructor(state->vm(), prototype->globalObject()));
203 }
204
205 bool setJSTestNamedGetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
206 {
207     VM& vm = state->vm();
208     auto throwScope = DECLARE_THROW_SCOPE(vm);
209     auto* prototype = jsDynamicCast<JSTestNamedGetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
210     if (UNLIKELY(!prototype)) {
211         throwVMTypeError(state, throwScope);
212         return false;
213     }
214     // Shadowing a built-in constructor
215     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
216 }
217
218 static inline JSC::EncodedJSValue jsTestNamedGetterWithIdentifierPrototypeFunctionGetterNameBody(JSC::ExecState* state, typename IDLOperation<JSTestNamedGetterWithIdentifier>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
219 {
220     UNUSED_PARAM(state);
221     UNUSED_PARAM(throwScope);
222     auto& impl = castedThis->wrapped();
223     if (UNLIKELY(state->argumentCount() < 1))
224         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
225     auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
226     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
227     return JSValue::encode(toJS<IDLDOMString>(*state, impl.getterName(WTFMove(name))));
228 }
229
230 EncodedJSValue JSC_HOST_CALL jsTestNamedGetterWithIdentifierPrototypeFunctionGetterName(ExecState* state)
231 {
232     return IDLOperation<JSTestNamedGetterWithIdentifier>::call<jsTestNamedGetterWithIdentifierPrototypeFunctionGetterNameBody>(*state, "getterName");
233 }
234
235 bool JSTestNamedGetterWithIdentifierOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
236 {
237     UNUSED_PARAM(handle);
238     UNUSED_PARAM(visitor);
239     return false;
240 }
241
242 void JSTestNamedGetterWithIdentifierOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
243 {
244     auto* jsTestNamedGetterWithIdentifier = static_cast<JSTestNamedGetterWithIdentifier*>(handle.slot()->asCell());
245     auto& world = *static_cast<DOMWrapperWorld*>(context);
246     uncacheWrapper(world, &jsTestNamedGetterWithIdentifier->wrapped(), jsTestNamedGetterWithIdentifier);
247 }
248
249 #if ENABLE(BINDING_INTEGRITY)
250 #if PLATFORM(WIN)
251 #pragma warning(disable: 4483)
252 extern "C" { extern void (*const __identifier("??_7TestNamedGetterWithIdentifier@WebCore@@6B@")[])(); }
253 #else
254 extern "C" { extern void* _ZTVN7WebCore29TestNamedGetterWithIdentifierE[]; }
255 #endif
256 #endif
257
258 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedGetterWithIdentifier>&& impl)
259 {
260
261 #if ENABLE(BINDING_INTEGRITY)
262     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
263 #if PLATFORM(WIN)
264     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedGetterWithIdentifier@WebCore@@6B@"));
265 #else
266     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore29TestNamedGetterWithIdentifierE[2]);
267 #endif
268
269     // If this fails TestNamedGetterWithIdentifier does not have a vtable, so you need to add the
270     // ImplementationLacksVTable attribute to the interface definition
271     static_assert(std::is_polymorphic<TestNamedGetterWithIdentifier>::value, "TestNamedGetterWithIdentifier is not polymorphic");
272
273     // If you hit this assertion you either have a use after free bug, or
274     // TestNamedGetterWithIdentifier has subclasses. If TestNamedGetterWithIdentifier has subclasses that get passed
275     // to toJS() we currently require TestNamedGetterWithIdentifier you to opt out of binding hardening
276     // by adding the SkipVTableValidation attribute to the interface IDL definition
277     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
278 #endif
279     return createWrapper<TestNamedGetterWithIdentifier>(globalObject, WTFMove(impl));
280 }
281
282 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedGetterWithIdentifier& impl)
283 {
284     return wrap(state, globalObject, impl);
285 }
286
287 TestNamedGetterWithIdentifier* JSTestNamedGetterWithIdentifier::toWrapped(JSC::VM& vm, JSC::JSValue value)
288 {
289     if (auto* wrapper = jsDynamicCast<JSTestNamedGetterWithIdentifier*>(vm, value))
290         return &wrapper->wrapped();
291     return nullptr;
292 }
293
294 }