Move URL from WebCore to WTF
[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 "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 jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter(JSC::ExecState*);
46
47 // Attributes
48
49 JSC::EncodedJSValue jsTestNamedSetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
50 bool setJSTestNamedSetterWithIdentifierConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
51
52 class JSTestNamedSetterWithIdentifierPrototype : public JSC::JSNonFinalObject {
53 public:
54     using Base = JSC::JSNonFinalObject;
55     static JSTestNamedSetterWithIdentifierPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
56     {
57         JSTestNamedSetterWithIdentifierPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedSetterWithIdentifierPrototype>(vm.heap)) JSTestNamedSetterWithIdentifierPrototype(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     JSTestNamedSetterWithIdentifierPrototype(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 JSTestNamedSetterWithIdentifierConstructor = JSDOMConstructorNotConstructable<JSTestNamedSetterWithIdentifier>;
78
79 template<> JSValue JSTestNamedSetterWithIdentifierConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
80 {
81     UNUSED_PARAM(vm);
82     return globalObject.functionPrototype();
83 }
84
85 template<> void JSTestNamedSetterWithIdentifierConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
86 {
87     putDirect(vm, vm.propertyNames->prototype, JSTestNamedSetterWithIdentifier::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
88     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestNamedSetterWithIdentifier"_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 JSTestNamedSetterWithIdentifierConstructor::s_info = { "TestNamedSetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifierConstructor) };
93
94 /* Hash table for prototype */
95
96 static const HashTableValue JSTestNamedSetterWithIdentifierPrototypeTableValues[] =
97 {
98     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedSetterWithIdentifierConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedSetterWithIdentifierConstructor) } },
99     { "namedSetter", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter), (intptr_t) (2) } },
100 };
101
102 const ClassInfo JSTestNamedSetterWithIdentifierPrototype::s_info = { "TestNamedSetterWithIdentifierPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifierPrototype) };
103
104 void JSTestNamedSetterWithIdentifierPrototype::finishCreation(VM& vm)
105 {
106     Base::finishCreation(vm);
107     reifyStaticProperties(vm, JSTestNamedSetterWithIdentifier::info(), JSTestNamedSetterWithIdentifierPrototypeTableValues, *this);
108 }
109
110 const ClassInfo JSTestNamedSetterWithIdentifier::s_info = { "TestNamedSetterWithIdentifier", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedSetterWithIdentifier) };
111
112 JSTestNamedSetterWithIdentifier::JSTestNamedSetterWithIdentifier(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedSetterWithIdentifier>&& impl)
113     : JSDOMWrapper<TestNamedSetterWithIdentifier>(structure, globalObject, WTFMove(impl))
114 {
115 }
116
117 void JSTestNamedSetterWithIdentifier::finishCreation(VM& vm)
118 {
119     Base::finishCreation(vm);
120     ASSERT(inherits(vm, info()));
121
122 }
123
124 JSObject* JSTestNamedSetterWithIdentifier::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
125 {
126     return JSTestNamedSetterWithIdentifierPrototype::create(vm, &globalObject, JSTestNamedSetterWithIdentifierPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
127 }
128
129 JSObject* JSTestNamedSetterWithIdentifier::prototype(VM& vm, JSDOMGlobalObject& globalObject)
130 {
131     return getDOMPrototype<JSTestNamedSetterWithIdentifier>(vm, globalObject);
132 }
133
134 JSValue JSTestNamedSetterWithIdentifier::getConstructor(VM& vm, const JSGlobalObject* globalObject)
135 {
136     return getDOMConstructor<JSTestNamedSetterWithIdentifierConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
137 }
138
139 void JSTestNamedSetterWithIdentifier::destroy(JSC::JSCell* cell)
140 {
141     JSTestNamedSetterWithIdentifier* thisObject = static_cast<JSTestNamedSetterWithIdentifier*>(cell);
142     thisObject->JSTestNamedSetterWithIdentifier::~JSTestNamedSetterWithIdentifier();
143 }
144
145 bool JSTestNamedSetterWithIdentifier::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
146 {
147     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(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().namedItem(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>(0), value);
159         return true;
160     }
161     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
162 }
163
164 bool JSTestNamedSetterWithIdentifier::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
165 {
166     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(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().namedItem(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>(0), value);
179         return true;
180     }
181     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
182 }
183
184 void JSTestNamedSetterWithIdentifier::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
185 {
186     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(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 bool JSTestNamedSetterWithIdentifier::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot)
194 {
195     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
196     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
197
198     if (!propertyName.isSymbol()) {
199         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
200         JSValue prototype = thisObject->getPrototypeDirect(state->vm());
201         if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
202             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
203             auto nativeValue = convert<IDLDOMString>(*state, value);
204             RETURN_IF_EXCEPTION(throwScope, true);
205             thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
206             return true;
207         }
208     }
209
210     return JSObject::put(thisObject, state, propertyName, value, putPropertySlot);
211 }
212
213 bool JSTestNamedSetterWithIdentifier::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool shouldThrow)
214 {
215     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
216     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
217
218     auto propertyName = Identifier::from(state, index);
219     PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
220     JSValue prototype = thisObject->getPrototypeDirect(state->vm());
221     if (!(prototype.isObject() && asObject(prototype)->getPropertySlot(state, propertyName, slot))) {
222         auto throwScope = DECLARE_THROW_SCOPE(state->vm());
223         auto nativeValue = convert<IDLDOMString>(*state, value);
224         RETURN_IF_EXCEPTION(throwScope, true);
225         thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
226         return true;
227     }
228
229     return JSObject::putByIndex(cell, state, index, value, shouldThrow);
230 }
231
232 bool JSTestNamedSetterWithIdentifier::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow)
233 {
234     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(object);
235     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
236
237     if (!propertyName.isSymbol()) {
238         PropertySlot slot { thisObject, PropertySlot::InternalMethodType::VMInquiry };
239         if (!JSObject::getOwnPropertySlot(thisObject, state, propertyName, slot)) {
240             if (!propertyDescriptor.isDataDescriptor())
241                 return false;
242             auto throwScope = DECLARE_THROW_SCOPE(state->vm());
243             auto nativeValue = convert<IDLDOMString>(*state, propertyDescriptor.value());
244             RETURN_IF_EXCEPTION(throwScope, true);
245             thisObject->wrapped().namedSetter(propertyNameToString(propertyName), WTFMove(nativeValue));
246             return true;
247         }
248     }
249
250     PropertyDescriptor newPropertyDescriptor = propertyDescriptor;
251     newPropertyDescriptor.setConfigurable(true);
252     return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow);
253 }
254
255 template<> inline JSTestNamedSetterWithIdentifier* IDLOperation<JSTestNamedSetterWithIdentifier>::cast(ExecState& state)
256 {
257     return jsDynamicCast<JSTestNamedSetterWithIdentifier*>(state.vm(), state.thisValue());
258 }
259
260 EncodedJSValue jsTestNamedSetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
261 {
262     VM& vm = state->vm();
263     auto throwScope = DECLARE_THROW_SCOPE(vm);
264     auto* prototype = jsDynamicCast<JSTestNamedSetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
265     if (UNLIKELY(!prototype))
266         return throwVMTypeError(state, throwScope);
267     return JSValue::encode(JSTestNamedSetterWithIdentifier::getConstructor(state->vm(), prototype->globalObject()));
268 }
269
270 bool setJSTestNamedSetterWithIdentifierConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
271 {
272     VM& vm = state->vm();
273     auto throwScope = DECLARE_THROW_SCOPE(vm);
274     auto* prototype = jsDynamicCast<JSTestNamedSetterWithIdentifierPrototype*>(vm, JSValue::decode(thisValue));
275     if (UNLIKELY(!prototype)) {
276         throwVMTypeError(state, throwScope);
277         return false;
278     }
279     // Shadowing a built-in constructor
280     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
281 }
282
283 static inline JSC::EncodedJSValue jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetterBody(JSC::ExecState* state, typename IDLOperation<JSTestNamedSetterWithIdentifier>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
284 {
285     UNUSED_PARAM(state);
286     UNUSED_PARAM(throwScope);
287     auto& impl = castedThis->wrapped();
288     if (UNLIKELY(state->argumentCount() < 2))
289         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
290     auto name = convert<IDLDOMString>(*state, state->uncheckedArgument(0));
291     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
292     auto value = convert<IDLDOMString>(*state, state->uncheckedArgument(1));
293     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
294     impl.namedSetter(WTFMove(name), WTFMove(value));
295     return JSValue::encode(jsUndefined());
296 }
297
298 EncodedJSValue JSC_HOST_CALL jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetter(ExecState* state)
299 {
300     return IDLOperation<JSTestNamedSetterWithIdentifier>::call<jsTestNamedSetterWithIdentifierPrototypeFunctionNamedSetterBody>(*state, "namedSetter");
301 }
302
303 void JSTestNamedSetterWithIdentifier::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
304 {
305     auto* thisObject = jsCast<JSTestNamedSetterWithIdentifier*>(cell);
306     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
307     if (thisObject->scriptExecutionContext())
308         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
309     Base::heapSnapshot(cell, builder);
310 }
311
312 bool JSTestNamedSetterWithIdentifierOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
313 {
314     UNUSED_PARAM(handle);
315     UNUSED_PARAM(visitor);
316     UNUSED_PARAM(reason);
317     return false;
318 }
319
320 void JSTestNamedSetterWithIdentifierOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
321 {
322     auto* jsTestNamedSetterWithIdentifier = static_cast<JSTestNamedSetterWithIdentifier*>(handle.slot()->asCell());
323     auto& world = *static_cast<DOMWrapperWorld*>(context);
324     uncacheWrapper(world, &jsTestNamedSetterWithIdentifier->wrapped(), jsTestNamedSetterWithIdentifier);
325 }
326
327 #if ENABLE(BINDING_INTEGRITY)
328 #if PLATFORM(WIN)
329 #pragma warning(disable: 4483)
330 extern "C" { extern void (*const __identifier("??_7TestNamedSetterWithIdentifier@WebCore@@6B@")[])(); }
331 #else
332 extern "C" { extern void* _ZTVN7WebCore29TestNamedSetterWithIdentifierE[]; }
333 #endif
334 #endif
335
336 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedSetterWithIdentifier>&& impl)
337 {
338
339 #if ENABLE(BINDING_INTEGRITY)
340     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
341 #if PLATFORM(WIN)
342     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedSetterWithIdentifier@WebCore@@6B@"));
343 #else
344     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore29TestNamedSetterWithIdentifierE[2]);
345 #endif
346
347     // If this fails TestNamedSetterWithIdentifier does not have a vtable, so you need to add the
348     // ImplementationLacksVTable attribute to the interface definition
349     static_assert(std::is_polymorphic<TestNamedSetterWithIdentifier>::value, "TestNamedSetterWithIdentifier is not polymorphic");
350
351     // If you hit this assertion you either have a use after free bug, or
352     // TestNamedSetterWithIdentifier has subclasses. If TestNamedSetterWithIdentifier has subclasses that get passed
353     // to toJS() we currently require TestNamedSetterWithIdentifier you to opt out of binding hardening
354     // by adding the SkipVTableValidation attribute to the interface IDL definition
355     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
356 #endif
357     return createWrapper<TestNamedSetterWithIdentifier>(globalObject, WTFMove(impl));
358 }
359
360 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedSetterWithIdentifier& impl)
361 {
362     return wrap(state, globalObject, impl);
363 }
364
365 TestNamedSetterWithIdentifier* JSTestNamedSetterWithIdentifier::toWrapped(JSC::VM& vm, JSC::JSValue value)
366 {
367     if (auto* wrapper = jsDynamicCast<JSTestNamedSetterWithIdentifier*>(vm, value))
368         return &wrapper->wrapped();
369     return nullptr;
370 }
371
372 }