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