c18f46eafe3281a0e8f882f9b6a36883f49cf572
[WebKit.git] / Source / WebCore / bindings / scripts / test / JS / JSTestNamedGetterCallWith.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 "JSTestNamedGetterCallWith.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 <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 jsTestNamedGetterCallWithConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
45 bool setJSTestNamedGetterCallWithConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
46
47 class JSTestNamedGetterCallWithPrototype : public JSC::JSNonFinalObject {
48 public:
49     using Base = JSC::JSNonFinalObject;
50     static JSTestNamedGetterCallWithPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
51     {
52         JSTestNamedGetterCallWithPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestNamedGetterCallWithPrototype>(vm.heap)) JSTestNamedGetterCallWithPrototype(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     JSTestNamedGetterCallWithPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
65         : JSC::JSNonFinalObject(vm, structure)
66     {
67         didBecomePrototype();
68     }
69
70     void finishCreation(JSC::VM&);
71 };
72
73 using JSTestNamedGetterCallWithConstructor = JSDOMConstructorNotConstructable<JSTestNamedGetterCallWith>;
74
75 template<> JSValue JSTestNamedGetterCallWithConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
76 {
77     UNUSED_PARAM(vm);
78     return globalObject.functionPrototype();
79 }
80
81 template<> void JSTestNamedGetterCallWithConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
82 {
83     putDirect(vm, vm.propertyNames->prototype, JSTestNamedGetterCallWith::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
84     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String("TestNamedGetterCallWith"_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 JSTestNamedGetterCallWithConstructor::s_info = { "TestNamedGetterCallWith", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterCallWithConstructor) };
89
90 /* Hash table for prototype */
91
92 static const HashTableValue JSTestNamedGetterCallWithPrototypeTableValues[] =
93 {
94     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestNamedGetterCallWithConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestNamedGetterCallWithConstructor) } },
95 };
96
97 const ClassInfo JSTestNamedGetterCallWithPrototype::s_info = { "TestNamedGetterCallWithPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterCallWithPrototype) };
98
99 void JSTestNamedGetterCallWithPrototype::finishCreation(VM& vm)
100 {
101     Base::finishCreation(vm);
102     reifyStaticProperties(vm, JSTestNamedGetterCallWith::info(), JSTestNamedGetterCallWithPrototypeTableValues, *this);
103 }
104
105 const ClassInfo JSTestNamedGetterCallWith::s_info = { "TestNamedGetterCallWith", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestNamedGetterCallWith) };
106
107 JSTestNamedGetterCallWith::JSTestNamedGetterCallWith(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestNamedGetterCallWith>&& impl)
108     : JSDOMWrapper<TestNamedGetterCallWith>(structure, globalObject, WTFMove(impl))
109 {
110 }
111
112 void JSTestNamedGetterCallWith::finishCreation(VM& vm)
113 {
114     Base::finishCreation(vm);
115     ASSERT(inherits(vm, info()));
116
117 }
118
119 JSObject* JSTestNamedGetterCallWith::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
120 {
121     return JSTestNamedGetterCallWithPrototype::create(vm, &globalObject, JSTestNamedGetterCallWithPrototype::createStructure(vm, &globalObject, globalObject.objectPrototype()));
122 }
123
124 JSObject* JSTestNamedGetterCallWith::prototype(VM& vm, JSDOMGlobalObject& globalObject)
125 {
126     return getDOMPrototype<JSTestNamedGetterCallWith>(vm, globalObject);
127 }
128
129 JSValue JSTestNamedGetterCallWith::getConstructor(VM& vm, const JSGlobalObject* globalObject)
130 {
131     return getDOMConstructor<JSTestNamedGetterCallWithConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
132 }
133
134 void JSTestNamedGetterCallWith::destroy(JSC::JSCell* cell)
135 {
136     JSTestNamedGetterCallWith* thisObject = static_cast<JSTestNamedGetterCallWith*>(cell);
137     thisObject->JSTestNamedGetterCallWith::~JSTestNamedGetterCallWith();
138 }
139
140 bool JSTestNamedGetterCallWith::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
141 {
142     auto* thisObject = jsCast<JSTestNamedGetterCallWith*>(object);
143     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
144     using GetterIDLType = IDLDOMString;
145     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
146         auto result = thisObject.wrapped().namedItem(worldForDOMObject(thisObject), propertyNameToAtomicString(propertyName));
147         if (!GetterIDLType::isNullValue(result))
148             return typename GetterIDLType::ImplementationType { GetterIDLType::extractValueFromNullable(result) };
149         return WTF::nullopt;
150     };
151     if (auto namedProperty = accessVisibleNamedProperty<OverrideBuiltins::No>(*state, *thisObject, propertyName, getterFunctor)) {
152         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
153         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
154         return true;
155     }
156     return JSObject::getOwnPropertySlot(object, state, propertyName, slot);
157 }
158
159 bool JSTestNamedGetterCallWith::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
160 {
161     auto* thisObject = jsCast<JSTestNamedGetterCallWith*>(object);
162     ASSERT_GC_OBJECT_INHERITS(thisObject, info());
163     auto propertyName = Identifier::from(state, index);
164     using GetterIDLType = IDLDOMString;
165     auto getterFunctor = [] (auto& thisObject, auto propertyName) -> Optional<typename GetterIDLType::ImplementationType> {
166         auto result = thisObject.wrapped().namedItem(worldForDOMObject(thisObject), propertyNameToAtomicString(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::No>(*state, *thisObject, propertyName, getterFunctor)) {
172         auto value = toJS<IDLDOMString>(*state, WTFMove(namedProperty.value()));
173         slot.setValue(thisObject, static_cast<unsigned>(JSC::PropertyAttribute::ReadOnly), value);
174         return true;
175     }
176     return JSObject::getOwnPropertySlotByIndex(object, state, index, slot);
177 }
178
179 void JSTestNamedGetterCallWith::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
180 {
181     auto* thisObject = jsCast<JSTestNamedGetterCallWith*>(object);
182     ASSERT_GC_OBJECT_INHERITS(object, info());
183     for (auto& propertyName : thisObject->wrapped().supportedPropertyNames())
184         propertyNames.add(Identifier::fromString(state, propertyName));
185     JSObject::getOwnPropertyNames(object, state, propertyNames, mode);
186 }
187
188 EncodedJSValue jsTestNamedGetterCallWithConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
189 {
190     VM& vm = state->vm();
191     auto throwScope = DECLARE_THROW_SCOPE(vm);
192     auto* prototype = jsDynamicCast<JSTestNamedGetterCallWithPrototype*>(vm, JSValue::decode(thisValue));
193     if (UNLIKELY(!prototype))
194         return throwVMTypeError(state, throwScope);
195     return JSValue::encode(JSTestNamedGetterCallWith::getConstructor(state->vm(), prototype->globalObject()));
196 }
197
198 bool setJSTestNamedGetterCallWithConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
199 {
200     VM& vm = state->vm();
201     auto throwScope = DECLARE_THROW_SCOPE(vm);
202     auto* prototype = jsDynamicCast<JSTestNamedGetterCallWithPrototype*>(vm, JSValue::decode(thisValue));
203     if (UNLIKELY(!prototype)) {
204         throwVMTypeError(state, throwScope);
205         return false;
206     }
207     // Shadowing a built-in constructor
208     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
209 }
210
211 void JSTestNamedGetterCallWith::heapSnapshot(JSCell* cell, HeapSnapshotBuilder& builder)
212 {
213     auto* thisObject = jsCast<JSTestNamedGetterCallWith*>(cell);
214     builder.setWrappedObjectForCell(cell, &thisObject->wrapped());
215     if (thisObject->scriptExecutionContext())
216         builder.setLabelForCell(cell, "url " + thisObject->scriptExecutionContext()->url().string());
217     Base::heapSnapshot(cell, builder);
218 }
219
220 bool JSTestNamedGetterCallWithOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor, const char** reason)
221 {
222     UNUSED_PARAM(handle);
223     UNUSED_PARAM(visitor);
224     UNUSED_PARAM(reason);
225     return false;
226 }
227
228 void JSTestNamedGetterCallWithOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
229 {
230     auto* jsTestNamedGetterCallWith = static_cast<JSTestNamedGetterCallWith*>(handle.slot()->asCell());
231     auto& world = *static_cast<DOMWrapperWorld*>(context);
232     uncacheWrapper(world, &jsTestNamedGetterCallWith->wrapped(), jsTestNamedGetterCallWith);
233 }
234
235 #if ENABLE(BINDING_INTEGRITY)
236 #if PLATFORM(WIN)
237 #pragma warning(disable: 4483)
238 extern "C" { extern void (*const __identifier("??_7TestNamedGetterCallWith@WebCore@@6B@")[])(); }
239 #else
240 extern "C" { extern void* _ZTVN7WebCore23TestNamedGetterCallWithE[]; }
241 #endif
242 #endif
243
244 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestNamedGetterCallWith>&& impl)
245 {
246
247 #if ENABLE(BINDING_INTEGRITY)
248     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
249 #if PLATFORM(WIN)
250     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestNamedGetterCallWith@WebCore@@6B@"));
251 #else
252     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore23TestNamedGetterCallWithE[2]);
253 #endif
254
255     // If this fails TestNamedGetterCallWith does not have a vtable, so you need to add the
256     // ImplementationLacksVTable attribute to the interface definition
257     static_assert(std::is_polymorphic<TestNamedGetterCallWith>::value, "TestNamedGetterCallWith is not polymorphic");
258
259     // If you hit this assertion you either have a use after free bug, or
260     // TestNamedGetterCallWith has subclasses. If TestNamedGetterCallWith has subclasses that get passed
261     // to toJS() we currently require TestNamedGetterCallWith you to opt out of binding hardening
262     // by adding the SkipVTableValidation attribute to the interface IDL definition
263     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
264 #endif
265     return createWrapper<TestNamedGetterCallWith>(globalObject, WTFMove(impl));
266 }
267
268 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestNamedGetterCallWith& impl)
269 {
270     return wrap(state, globalObject, impl);
271 }
272
273 TestNamedGetterCallWith* JSTestNamedGetterCallWith::toWrapped(JSC::VM& vm, JSC::JSValue value)
274 {
275     if (auto* wrapper = jsDynamicCast<JSTestNamedGetterCallWith*>(vm, value))
276         return &wrapper->wrapped();
277     return nullptr;
278 }
279
280 }