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