Add support for dumping GC heap snapshots, and a viewer
[WebKit.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 "URL.h"
32 #include <JavaScriptCore/FunctionPrototype.h>
33 #include <JavaScriptCore/HeapSnapshotBuilder.h>
34 #include <JavaScriptCore/JSCInlines.h>
35 #include <wtf/GetPtr.h>
36 #include <wtf/PointerPreparations.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) -> std::optional<typename GetterIDLType::ImplementationType> {
145         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
146         if (!GetterIDLType::isNullValue(result))
147             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
148         return std::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     auto* thisObject = jsCast<JSTestNamedSetterWithOverrideBuiltins*>(object);
161     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
162     auto propertyName = Identifier::from(state, index);
163     using GetterIDLType = IDLDOMString;
164     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> std::optional<typename GetterIDLType::ImplementationType> {
165         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
166         if (!GetterIDLType::isNullValue(result))
167             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
168         return std::nullopt;
169     };
170     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::Yes>(*state, *thisObject, propertyName, getterFunctor)) {
171         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
172         slot.setValue(thisObject, static_cast<unsigned>(0), value);
173         return true;
174     }
175     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
176 }
177
178 void JSTestNamedSetterWithOverrideBuiltins::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
179 {
180     auto* thisObject = jsCast<JSTestNamedSetterWithOverrideBuiltins*>(object);
181     ASSERT_GC_OBJECT_INHERITS(object, info());
182     for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
183         propertyNames.add(Identifier::fromString(state, propertyName));
184     JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
185 }
186
187 bool JSTestNamedSetterWithOverrideBuiltins::put(JSCell* cell, ExecState* state, PropertyName propertyName, JSValue value, PutPropertySlot& putPropertySlot)
188 {
189     auto* thisObject = jsCast<JSTestNamedSetterWithOverrideBuiltins*>(cell);
190     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
191
192     if (!propertyName.isSymbol()) {
193         auto throwScope = DECLARE_THROW_SCOPE(state->vm());
194         auto nativeValue = convert<IDLDOMString>(*state, value);
195         RETURN_IF_EXCEPTION(throwScope, true);
196         thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue));
197         return true;
198     }
199
200     return JSObject::put(thisObject, state, propertyName, value, putPropertySlot);
201 }
202
203 bool JSTestNamedSetterWithOverrideBuiltins::putByIndex(JSCell* cell, ExecState* state, unsigned index, JSValue value, bool)
204 {
205     auto* thisObject = jsCast<JSTestNamedSetterWithOverrideBuiltins*>(cell);
206     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
207
208     auto propertyName = Identifier::from(state, index);
209     auto throwScope = DECLARE_THROW_SCOPE(state->vm());
210     auto nativeValue = convert<IDLDOMString>(*state, value);
211     RETURN_IF_EXCEPTION(throwScope, true);
212     thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue));
213     return true;
214 }
215
216 bool JSTestNamedSetterWithOverrideBuiltins::defineOwnProperty(JSObject* object, ExecState* state, PropertyName propertyName, const PropertyDescriptor& propertyDescriptor, bool shouldThrow)
217 {
218     auto* thisObject = jsCast<JSTestNamedSetterWithOverrideBuiltins*>(object);
219     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
220
221     if (!propertyName.isSymbol()) {
222         if (!propertyDescriptor.isDataDescriptor())
223             return false;
224         auto throwScope = DECLARE_THROW_SCOPE(state->vm());
225         auto nativeValue = convert<IDLDOMString>(*state, propertyDescriptor.value());
226         RETURN_IF_EXCEPTION(throwScope, true);
227         thisObject->wrapped().setNamedItem(propertyNameToString(propertyName), WTFMove(nativeValue));
228         return true;
229     }
230
231     PropertyDescriptor newPropertyDescriptor = propertyDescriptor;
232     newPropertyDescriptor.setConfigurable(true);
233     return JSObject::defineOwnProperty(object, state, propertyName, newPropertyDescriptor, shouldThrow);
234 }
235
236 EncodedJSValue jsTestNamedSetterWithOverrideBuiltinsConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
237 {
238     VM& vm = state->vm();
239     auto throwScope = DECLARE_THROW_SCOPE(vm);
240     auto* prototype = jsDynamicCast<JSTestNamedSetterWithOverrideBuiltinsPrototype*>(vm, JSValue::decode(thisValue));
241     if (UNLIKELY(!prototype))
242         return throwVMTypeError(state, throwScope);
243     return JSValue::encode(JSTestNamedSetterWithOverrideBuiltins::getConstructor(state->vm(), prototype->globalObject()));
244 }
245
246 bool setJSTestNamedSetterWithOverrideBuiltinsConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
247 {
248     VM& vm = state->vm();
249     auto throwScope = DECLARE_THROW_SCOPE(vm);
250     auto* prototype = jsDynamicCast<JSTestNamedSetterWithOverrideBuiltinsPrototype*>(vm, JSValue::decode(thisValue));
251     if (UNLIKELY(!prototype)) {
252         throwVMTypeError(state, throwScope);
253         return false;
254     }
255     // Shadowing a built-in constructor
256     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
257 }
258
259 void JSTestNamedSetterWithOverrideBuiltins::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
260 {
261     auto* thisObject = jsCast<JSTestNamedSetterWithOverrideBuiltins*>(cell);
262     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
263     if (thisObject->scriptExecutionContext())
264         builder.setLabelForCell(cell, String::format("url %s", thisObject->scriptExecutionContext()->url().string().utf8().data()));
265     Base::heapSnapshot(cell, builder);
266 }
267
268 bool JSTestNamedSetterWithOverrideBuiltinsOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
269 {
270     UNUSED_PARAM(handle);
271     UNUSED_PARAM(visitor);
272     UNUSED_PARAM(reason);
273     return false;
274 }
275
276 void JSTestNamedSetterWithOverrideBuiltinsOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
277 {
278     auto* jsTestNamedSetterWithOverrideBuiltins = static_cast<JSTestNamedSetterWithOverrideBuiltins*>(handle.slot()->asCell());
279     auto& world = *static_cast<DOMWrapperWorld*>(context);
280     uncacheWrapper(world, &jsTestNamedSetterWithOverrideBuiltins->wrapped(), jsTestNamedSetterWithOverrideBuiltins);
281 }
282
283 #if ENABLE(BINDING_INTEGRITY)
284 #if PLATFORM(WIN)
285 #pragma warning(disable: 4483)
286 extern "C" { extern void (*const __identifier("??_7TestNamedSetterWithOverrideBuiltins@WebCore@@6B@")[])(); }
287 #else
288 extern "C" { extern void* _ZTVN7WebCore35TestNamedSetterWithOverrideBuiltinsE[]; }
289 #endif
290 #endif
291
292 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedSetterWithOverrideBuiltins>&& impl)
293 {
294
295 #if ENABLE(BINDING_INTEGRITY)
296     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
297 #if PLATFORM(WIN)
298     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedSetterWithOverrideBuiltins@WebCore@@6B@"));
299 #else
300     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore35TestNamedSetterWithOverrideBuiltinsE[2]);
301 #endif
302
303     // If this fails TestNamedSetterWithOverrideBuiltins does not have a vtable, so you need to add the
304     // ImplementationLacksVTable attribute to the interface definition
305     static_assert(std::is_polymorphic<TestNamedSetterWithOverrideBuiltins>::value, "TestNamedSetterWithOverrideBuiltins is not polymorphic");
306
307     // If you hit this assertion you either have a use after free bug, or
308     // TestNamedSetterWithOverrideBuiltins has subclasses. If TestNamedSetterWithOverrideBuiltins has subclasses that get passed
309     // to toJS() we currently require TestNamedSetterWithOverrideBuiltins you to opt out of binding hardening
310     // by adding the SkipVTableValidation attribute to the interface IDL definition
311     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
312 #endif
313     return createWrapper<TestNamedSetterWithOverrideBuiltins>(globalObject, WTFMove(impl));
314 }
315
316 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedSetterWithOverrideBuiltins& impl)
317 {
318     return wrap(state, globalObject, impl);
319 }
320
321 TestNamedSetterWithOverrideBuiltins* JSTestNamedSetterWithOverrideBuiltins::toWrapped(JSC::VM& vm, JSC::JSValue value)
322 {
323     if (auto* wrapper = jsDynamicCast<JSTestNamedSetterWithOverrideBuiltins*>(vm, value))
324         return &wrapper->wrapped();
325     return nullptr;
326 }
327
328 }