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