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