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