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