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