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