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