Make a NativeFunction into a class to support pointer profiling.
[WebKit-https.git] / Source / WebCore / bindings / scripts / test / JS / JSTestEventTarget.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 "JSTestEventTarget.h"
23
24 #include "JSDOMAbstractOperations.h"
25 #include "JSDOMBinding.h"
26 #include "JSDOMConstructorNotConstructable.h"
27 #include "JSDOMConvertInterface.h"
28 #include "JSDOMConvertNumbers.h"
29 #include "JSDOMExceptionHandling.h"
30 #include "JSDOMGlobalObject.h"
31 #include "JSDOMOperation.h"
32 #include "JSDOMWrapperCache.h"
33 #include "JSNode.h"
34 #include <JavaScriptCore/JSCInlines.h>
35 #include <JavaScriptCore/PropertyNameArray.h>
36 #include <wtf/GetPtr.h>
37 #include <wtf/PointerPreparations.h>
38
39
40 namespace WebCore {
41 using namespace JSC;
42
43 // Functions
44
45 JSC::EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionItem(JSC::ExecState*);
46
47 // Attributes
48
49 JSC::EncodedJSValue jsTestEventTargetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
50 bool setJSTestEventTargetConstructor(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
51
52 class JSTestEventTargetPrototype : public JSC::JSNonFinalObject {
53 public:
54     using Base = JSC::JSNonFinalObject;
55     static JSTestEventTargetPrototype* create(JSC::VM& vm, JSDOMGlobalObject* globalObject, JSC::Structure* structure)
56     {
57         JSTestEventTargetPrototype* ptr = new (NotNull, JSC::allocateCell<JSTestEventTargetPrototype>(vm.heap)) JSTestEventTargetPrototype(vm, globalObject, structure);
58         ptr->finishCreation(vm);
59         return ptr;
60     }
61
62     DECLARE_INFO;
63     static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
64     {
65         return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
66     }
67
68 private:
69     JSTestEventTargetPrototype(JSC::VM& vm, JSC::JSGlobalObject*, JSC::Structure* structure)
70         : JSC::JSNonFinalObject(vm, structure)
71     {
72     }
73
74     void finishCreation(JSC::VM&);
75 };
76
77 using JSTestEventTargetConstructor = JSDOMConstructorNotConstructable<JSTestEventTarget>;
78
79 template<> JSValue JSTestEventTargetConstructor::prototypeForStructure(JSC::VM& vm, const JSDOMGlobalObject& globalObject)
80 {
81     return JSEventTarget::getConstructor(vm, &globalObject);
82 }
83
84 template<> void JSTestEventTargetConstructor::initializeProperties(VM& vm, JSDOMGlobalObject& globalObject)
85 {
86     putDirect(vm, vm.propertyNames->prototype, JSTestEventTarget::prototype(vm, globalObject), JSC::PropertyAttribute::DontDelete | JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
87     putDirect(vm, vm.propertyNames->name, jsNontrivialString(&vm, String(ASCIILiteral("TestEventTarget"))), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
88     putDirect(vm, vm.propertyNames->length, jsNumber(0), JSC::PropertyAttribute::ReadOnly | JSC::PropertyAttribute::DontEnum);
89 }
90
91 template<> const ClassInfo JSTestEventTargetConstructor::s_info = { "TestEventTarget", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventTargetConstructor) };
92
93 /* Hash table for prototype */
94
95 static const HashTableValue JSTestEventTargetPrototypeTableValues[] =
96 {
97     { "constructor", static_cast<unsigned>(JSC::PropertyAttribute::DontEnum), NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventTargetConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestEventTargetConstructor) } },
98     { "item", static_cast<unsigned>(JSC::PropertyAttribute::Function), NoIntrinsic, { (intptr_t)static_cast<RawNativeFunction>(jsTestEventTargetPrototypeFunctionItem), (intptr_t) (1) } },
99 };
100
101 const ClassInfo JSTestEventTargetPrototype::s_info = { "TestEventTargetPrototype", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventTargetPrototype) };
102
103 void JSTestEventTargetPrototype::finishCreation(VM& vm)
104 {
105     Base::finishCreation(vm);
106     reifyStaticProperties(vm, JSTestEventTarget::info(), JSTestEventTargetPrototypeTableValues, *this);
107 }
108
109 const ClassInfo JSTestEventTarget::s_info = { "TestEventTarget", &Base::s_info, nullptr, nullptr, CREATE_METHOD_TABLE(JSTestEventTarget) };
110
111 JSTestEventTarget::JSTestEventTarget(Structure* structure, JSDOMGlobalObject& globalObject, Ref<TestEventTarget>&& impl)
112     : JSEventTarget(structure, globalObject, WTFMove(impl))
113 {
114 }
115
116 void JSTestEventTarget::finishCreation(VM& vm)
117 {
118     Base::finishCreation(vm);
119     ASSERT(inherits(vm, info()));
120
121 }
122
123 JSObject* JSTestEventTarget::createPrototype(VM& vm, JSDOMGlobalObject& globalObject)
124 {
125     return JSTestEventTargetPrototype::create(vm, &globalObject, JSTestEventTargetPrototype::createStructure(vm, &globalObject, JSEventTarget::prototype(vm, globalObject)));
126 }
127
128 JSObject* JSTestEventTarget::prototype(VM& vm, JSDOMGlobalObject& globalObject)
129 {
130     return getDOMPrototype<JSTestEventTarget>(vm, globalObject);
131 }
132
133 JSValue JSTestEventTarget::getConstructor(VM& vm, const JSGlobalObject* globalObject)
134 {
135     return getDOMConstructor<JSTestEventTargetConstructor>(vm, *jsCast<const JSDOMGlobalObject*>(globalObject));
136 }
137
138 bool JSTestEventTarget::getOwnPropertySlot(JSObject* object, ExecState* state, PropertyName propertyName, PropertySlot& slot)
139 {
140     auto* thisObject = jsCast<JSTestEventTarget*>(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<IDLInterface<Node>>(*state, *thisObject->globalObject(), 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 = IDLInterface<Node>;
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<IDLInterface<Node>>(*state, *thisObject->globalObject(), 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 JSTestEventTarget::getOwnPropertySlotByIndex(JSObject* object, ExecState* state, unsigned index, PropertySlot& slot)
166 {
167     auto* thisObject = jsCast<JSTestEventTarget*>(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<IDLInterface<Node>>(*state, *thisObject->globalObject(), 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 = IDLInterface<Node>;
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<IDLInterface<Node>>(*state, *thisObject->globalObject(), 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 JSTestEventTarget::getOwnPropertyNames(JSObject* object, ExecState* state, PropertyNameArray& propertyNames, EnumerationMode mode)
194 {
195     auto* thisObject = jsCast<JSTestEventTarget*>(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 template<> inline JSTestEventTarget* IDLOperation<JSTestEventTarget>::cast(ExecState& state)
205 {
206     return jsDynamicCast<JSTestEventTarget*>(state.vm(), state.thisValue());
207 }
208
209 EncodedJSValue jsTestEventTargetConstructor(ExecState* state, EncodedJSValue thisValue, PropertyName)
210 {
211     VM& vm = state->vm();
212     auto throwScope = DECLARE_THROW_SCOPE(vm);
213     auto* prototype = jsDynamicCast<JSTestEventTargetPrototype*>(vm, JSValue::decode(thisValue));
214     if (UNLIKELY(!prototype))
215         return throwVMTypeError(state, throwScope);
216     return JSValue::encode(JSTestEventTarget::getConstructor(state->vm(), prototype->globalObject()));
217 }
218
219 bool setJSTestEventTargetConstructor(ExecState* state, EncodedJSValue thisValue, EncodedJSValue encodedValue)
220 {
221     VM& vm = state->vm();
222     auto throwScope = DECLARE_THROW_SCOPE(vm);
223     auto* prototype = jsDynamicCast<JSTestEventTargetPrototype*>(vm, JSValue::decode(thisValue));
224     if (UNLIKELY(!prototype)) {
225         throwVMTypeError(state, throwScope);
226         return false;
227     }
228     // Shadowing a built-in constructor
229     return prototype->putDirect(vm, vm.propertyNames->constructor, JSValue::decode(encodedValue));
230 }
231
232 static inline JSC::EncodedJSValue jsTestEventTargetPrototypeFunctionItemBody(JSC::ExecState* state, typename IDLOperation<JSTestEventTarget>::ClassParameter castedThis, JSC::ThrowScope& throwScope)
233 {
234     UNUSED_PARAM(state);
235     UNUSED_PARAM(throwScope);
236     auto& impl = castedThis->wrapped();
237     if (UNLIKELY(state->argumentCount() < 1))
238         return throwVMError(state, throwScope, createNotEnoughArgumentsError(state));
239     auto index = convert<IDLUnsignedLong>(*state, state->uncheckedArgument(0));
240     RETURN_IF_EXCEPTION(throwScope, encodedJSValue());
241     return JSValue::encode(toJS<IDLInterface<Node>>(*state, *castedThis->globalObject(), impl.item(WTFMove(index))));
242 }
243
244 EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionItem(ExecState* state)
245 {
246     return IDLOperation<JSTestEventTarget>::call<jsTestEventTargetPrototypeFunctionItemBody>(*state, "item");
247 }
248
249 #if ENABLE(BINDING_INTEGRITY)
250 #if PLATFORM(WIN)
251 #pragma warning(disable: 4483)
252 extern "C" { extern void (*const __identifier("??_7TestEventTarget@WebCore@@6B@")[])(); }
253 #else
254 extern "C" { extern void* _ZTVN7WebCore15TestEventTargetE[]; }
255 #endif
256 #endif
257
258 JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject* globalObject, Ref<TestEventTarget>&& impl)
259 {
260
261 #if ENABLE(BINDING_INTEGRITY)
262     void* actualVTablePointer = *(reinterpret_cast<void**>(impl.ptr()));
263 #if PLATFORM(WIN)
264     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(__identifier("??_7TestEventTarget@WebCore@@6B@"));
265 #else
266     void* expectedVTablePointer = WTF_PREPARE_VTBL_POINTER_FOR_INSPECTION(&_ZTVN7WebCore15TestEventTargetE[2]);
267 #endif
268
269     // If this fails TestEventTarget does not have a vtable, so you need to add the
270     // ImplementationLacksVTable attribute to the interface definition
271     static_assert(std::is_polymorphic<TestEventTarget>::value, "TestEventTarget is not polymorphic");
272
273     // If you hit this assertion you either have a use after free bug, or
274     // TestEventTarget has subclasses. If TestEventTarget has subclasses that get passed
275     // to toJS() we currently require TestEventTarget you to opt out of binding hardening
276     // by adding the SkipVTableValidation attribute to the interface IDL definition
277     RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
278 #endif
279     return createWrapper<TestEventTarget>(globalObject, WTFMove(impl));
280 }
281
282 JSC::JSValue toJS(JSC::ExecState* state, JSDOMGlobalObject* globalObject, TestEventTarget& impl)
283 {
284     return wrap(state, globalObject, impl);
285 }
286
287 TestEventTarget* JSTestEventTarget::toWrapped(JSC::VM& vm, JSC::JSValue value)
288 {
289     if (auto* wrapper = jsDynamicCast<JSTestEventTarget*>(vm, value))
290         return &wrapper->wrapped();
291     return nullptr;
292 }
293
294 }