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