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