[JSC][WebCore] Extend jsDynamicCast for WebCore types in WebCore and remove jsDynamic...
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedDeleterWithIndexedGetter.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 "JSTestNamedDeleterWithIndexedGetter.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 "URL.h"
31 #include <JavaScriptCore/FunctionPrototype.h>
32 #include <JavaScriptCore/JSCInlines.h>
33 #include <JavaScriptCore/PropertyNameArray.h>
34 #include <wtf/GetPtr.h>
35 #include <wtf/PointerPreparations.h>
36
37
38 namespace WebCore {
39 using namespace JSC;
40
41 // Attributes
42
43 JSC::EncodedJSValue jsTestNamedDeleterWithIndexedGetterConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
44 bool setJSTestNamedDeleterWithIndexedGetterConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
45
46 class JSTestNamedDeleterWithIndexedGetterPrototype : public JSC::JSNonFinalObject {
47 public:
48     using Base = JSC::JSNonFinalObject;
49     static JSTestNamedDeleterWithIndexedGetterPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
50     {
51         JSTestNamedDeleterWithIndexedGetterPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedDeleterWithIndexedGetterPrototype>(vm.heap)) JSTestNamedDeleterWithIndexedGetterPrototype(vm, globalObject, structure);
52         ptr->finishCreation(vm);
53         return ptr;
54     }
55
56     DECLARE_INFO;
57     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
58     {
59         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
60     }
61
62 private:
63     JSTestNamedDeleterWithIndexedGetterPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
64         : JSC::JSNonFinalObject(vm, structure)
65     {
66     }
67
68     void finishCreation(JSC::VM&);
69 };
70
71 using JSTestNamedDeleterWithIndexedGetterConstructor = JSDOMConstructorNotConstructable<JSTestNamedDeleterWithIndexedGetter>;
72
73 template<> JSValue JSTestNamedDeleterWithIndexedGetterConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
74 {
75     UNUSED_PARAM(vm);
76     return globalObject.functionPrototype();
77 }
78
79 template<> void JSTestNamedDeleterWithIndexedGetterConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
80 {
81     putDirect(vm, vm.propertyNames->prototype, JSTestNamedDeleterWithIndexedGetter::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
82     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestNamedDeleterWithIndexedGetter"))), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
83     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
84 }
85
86 template<> const ClassInfo JSTestNamedDeleterWithIndexedGetterConstructor::s_info = { "TestNamedDeleterWithIndexedGetter", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedDeleterWithIndexedGetterConstructor) };
87
88 /* Hash table for prototype */
89
90 static const HashTableValue JSTestNamedDeleterWithIndexedGetterPrototypeTableValues[] =
91 {
92     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedDeleterWithIndexedGetterConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedDeleterWithIndexedGetterConstructor) } },
93 };
94
95 const ClassInfo JSTestNamedDeleterWithIndexedGetterPrototype::s_info = { "TestNamedDeleterWithIndexedGetterPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedDeleterWithIndexedGetterPrototype) };
96
97 void JSTestNamedDeleterWithIndexedGetterPrototype::finishCreation(VM& vm)
98 {
99     Base::finishCreation(vm);
100     reifyStaticProperties(vm, JSTestNamedDeleterWithIndexedGetter::info(), JSTestNamedDeleterWithIndexedGetterPrototypeTableValues, *this);
101 }
102
103 const ClassInfo JSTestNamedDeleterWithIndexedGetter::s_info = { "TestNamedDeleterWithIndexedGetter", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedDeleterWithIndexedGetter) };
104
105 JSTestNamedDeleterWithIndexedGetter::JSTestNamedDeleterWithIndexedGetter(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedDeleterWithIndexedGetter>&& impl)
106     : JSDOMWrapper<TestNamedDeleterWithIndexedGetter>(structure, globalObject, WTFMove(impl))
107 {
108 }
109
110 void JSTestNamedDeleterWithIndexedGetter::finishCreation(VM& vm)
111 {
112     Base::finishCreation(vm);
113     ASSERT(inherits(vm, info()));
114
115 }
116
117 JSObject* JSTestNamedDeleterWithIndexedGetter::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
118 {
119     return JSTestNamedDeleterWithIndexedGetterPrototype::create(vm, &globalObject, JSTestNamedDeleterWithIndexedGetterPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
120 }
121
122 JSObject* JSTestNamedDeleterWithIndexedGetter::prototype(VM& vm, JSDOMGlobalObject& globalObject)
123 {
124     return getDOMPrototype<JSTestNamedDeleterWithIndexedGetter>(vm, globalObject);
125 }
126
127 JSValue JSTestNamedDeleterWithIndexedGetter::getConstructor(VM& vm, const JSGlobalObject* globalObject)
128 {
129     return getDOMConstructor<JSTestNamedDeleterWithIndexedGetterConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
130 }
131
132 void JSTestNamedDeleterWithIndexedGetter::destroy(JSC::JSCell* cell)
133 {
134     JSTestNamedDeleterWithIndexedGetter* thisObject = static_cast<JSTestNamedDeleterWithIndexedGetter*>(cell);
135     thisObject->JSTestNamedDeleterWithIndexedGetter::~JSTestNamedDeleterWithIndexedGetter();
136 }
137
138 bool JSTestNamedDeleterWithIndexedGetter::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
139 {
140     auto* thisObject = jsCast<JSTestNamedDeleterWithIndexedGetter*>(object);
141     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
142     if (auto index = parseIndex(propertyName)) {
143         if (index.value() < thisObject->wrapped().length()) {
144             auto value = toJS<IDLDOMString>(*state, thisObject->wrapped().item(index.value()));
145             slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
146             return true;
147         }
148         return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
149     }
150     using GetterIDLType = IDLDOMString;
151     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> std::optional<typename GetterIDLType::ImplementationType> {
152         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
153         if (!GetterIDLType::isNullValue(result))
154             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
155         return std::nullopt;
156     };
157     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
158         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
159         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
160         return true;
161     }
162     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
163 }
164
165 bool JSTestNamedDeleterWithIndexedGetter::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
166 {
167     auto* thisObject = jsCast<JSTestNamedDeleterWithIndexedGetter*>(object);
168     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
169     if (LIKELY(index <= MAX_ARRAY_INDEX)) {
170         if (index < thisObject->wrapped().length()) {
171             auto value = toJS<IDLDOMString>(*state, thisObject->wrapped().item(index));
172             slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
173             return true;
174         }
175         return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
176     }
177     auto propertyName = Identifier::from(state, index);
178     using GetterIDLType = IDLDOMString;
179     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> std::optional<typename GetterIDLType::ImplementationType> {
180         auto result = thisObject.wrapped().namedItem(propertyNameToAtomicString(propertyName));
181         if (!GetterIDLType::isNullValue(result))
182             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
183         return std::nullopt;
184     };
185     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
186         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
187         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
188         return true;
189     }
190     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
191 }
192
193 void JSTestNamedDeleterWithIndexedGetter::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
194 {
195     auto* thisObject = jsCast<JSTestNamedDeleterWithIndexedGetter*>(object);
196     ASSERT_GC_OBJECT_INHERITS(object, info());
197     for (unsigned i = 0, count = thisObject->wrapped().length(); i < count; ++i)
198         propertyNames.add(Identifier::from(state, i));
199     for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
200         propertyNames.add(Identifier::fromString(state, propertyName));
201     JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
202 }
203
204 bool JSTestNamedDeleterWithIndexedGetter::deleteProperty(JSCell* cell, ExecState* state, PropertyName propertyName)
205 {
206     auto& thisObject = *jsCast<JSTestNamedDeleterWithIndexedGetter*>(cell);
207     auto& impl = thisObject.wrapped();
208     if (auto index = parseIndex(propertyName))
209         return !impl.isSupportedPropertyIndex(index.value());
210     if (isVisibleNamedProperty<OverrideBuiltins::No>(*state, thisObject, propertyName)) {
211         return impl.deleteNamedProperty(propertyNameToString(propertyName));
212     }
213     return JSObject::deleteProperty(cell, state, propertyName);
214 }
215
216 bool JSTestNamedDeleterWithIndexedGetter::deletePropertyByIndex(JSCell* cell, ExecState* state, unsigned index)
217 {
218     auto& thisObject = *jsCast<JSTestNamedDeleterWithIndexedGetter*>(cell);
219     auto& impl = thisObject.wrapped();
220     return !impl.isSupportedPropertyIndex(index);
221 }
222
223 EncodedJSValue jsTestNamedDeleterWithIndexedGetterConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
224 {
225     VM& vm = state->vm();
226     auto throwScope = DECLARE_THROW_SCOPE(vm);
227     auto* prototype = jsDynamicCast<JSTestNamedDeleterWithIndexedGetterPrototype*>(vm, JSValue::decode(thisValue));
228     if (UNLIKELY(!prototype))
229         return throwVMTypeError(state, throwScope);
230     return JSValue::encode(JSTestNamedDeleterWithIndexedGetter::getConstructor(state->vm(), prototype->globalObject()));
231 }
232
233 bool setJSTestNamedDeleterWithIndexedGetterConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
234 {
235     VM& vm = state->vm();
236     auto throwScope = DECLARE_THROW_SCOPE(vm);
237     auto* prototype = jsDynamicCast<JSTestNamedDeleterWithIndexedGetterPrototype*>(vm, JSValue::decode(thisValue));
238     if (UNLIKELY(!prototype)) {
239         throwVMTypeError(state, throwScope);
240         return false;
241     }
242     // Shadowing a built-in constructor
243     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
244 }
245
246 bool JSTestNamedDeleterWithIndexedGetterOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
247 {
248     UNUSED_PARAM(handle);
249     UNUSED_PARAM(visitor);
250     return false;
251 }
252
253 void JSTestNamedDeleterWithIndexedGetterOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
254 {
255     auto* jsTestNamedDeleterWithIndexedGetter = static_cast<JSTestNamedDeleterWithIndexedGetter*>(handle.slot()->asCell());
256     auto& world = *static_cast<DOMWrapperWorld*>(context);
257     uncacheWrapper(world, &jsTestNamedDeleterWithIndexedGetter->wrapped(), jsTestNamedDeleterWithIndexedGetter);
258 }
259
260 #if ENABLE(BINDING_INTEGRITY)
261 #if PLATFORM(WIN)
262 #pragma warning(disable: 4483)
263 extern "C" { extern void (*const __identifier("??_7TestNamedDeleterWithIndexedGetter@WebCore@@6B@")[])(); }
264 #else
265 extern "C" { extern void* _ZTVN7WebCore33TestNamedDeleterWithIndexedGetterE[]; }
266 #endif
267 #endif
268
269 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedDeleterWithIndexedGetter>&& impl)
270 {
271
272 #if ENABLE(BINDING_INTEGRITY)
273     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
274 #if PLATFORM(WIN)
275     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedDeleterWithIndexedGetter@WebCore@@6B@"));
276 #else
277     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore33TestNamedDeleterWithIndexedGetterE[2]);
278 #endif
279
280     // If this fails TestNamedDeleterWithIndexedGetter does not have a vtable, so you need to add the
281     // ImplementationLacksVTable attribute to the interface definition
282     static_assert(std::is_polymorphic<TestNamedDeleterWithIndexedGetter>::value, "TestNamedDeleterWithIndexedGetter is not polymorphic");
283
284     // If you hit this assertion you either have a use after free bug, or
285     // TestNamedDeleterWithIndexedGetter has subclasses. If TestNamedDeleterWithIndexedGetter has subclasses that get passed
286     // to toJS() we currently require TestNamedDeleterWithIndexedGetter you to opt out of binding hardening
287     // by adding the SkipVTableValidation attribute to the interface IDL definition
288     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
289 #endif
290     return createWrapper<TestNamedDeleterWithIndexedGetter>(globalObject, WTFMove(impl));
291 }
292
293 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedDeleterWithIndexedGetter& impl)
294 {
295     return wrap(state, globalObject, impl);
296 }
297
298 TestNamedDeleterWithIndexedGetter* JSTestNamedDeleterWithIndexedGetter::toWrapped(JSC::VM& vm, JSC::JSValue value)
299 {
300     if (auto* wrapper = jsDynamicCast<JSTestNamedDeleterWithIndexedGetter*>(vm, value))
301         return &wrapper->wrapped();
302     return nullptr;
303 }
304
305 }