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