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 "Event.h"
25#include "ExceptionCode.h"
26#include "JSDOMBinding.h"
27#include "JSEvent.h"
28#include "JSEventListener.h"
29#include "JSNode.h"
30#include "Node.h"
31#include "TestEventTarget.h"
32#include "wtf/text/AtomicString.h"
33#include <runtime/Error.h>
34#include <runtime/PropertyNameArray.h>
35#include <wtf/GetPtr.h>
36
37using namespace JSC;
38
39namespace WebCore {
40
41// Functions
42
43JSC::EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionItem(JSC::ExecState*);
44JSC::EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionAddEventListener(JSC::ExecState*);
45JSC::EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionRemoveEventListener(JSC::ExecState*);
46JSC::EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionDispatchEvent(JSC::ExecState*);
47
48// Attributes
49
50JSC::EncodedJSValue jsTestEventTargetConstructor(JSC::ExecState*, JSC::JSObject*, JSC::EncodedJSValue, JSC::PropertyName);
51
52class JSTestEventTargetPrototype : public JSC::JSNonFinalObject {
53public:
54    typedef JSC::JSNonFinalObject Base;
55    static JSTestEventTargetPrototype* create(JSC::VM& vm, JSC::JSGlobalObject* 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
68private:
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
77class JSTestEventTargetConstructor : public DOMConstructorObject {
78private:
79    JSTestEventTargetConstructor(JSC::Structure*, JSDOMGlobalObject*);
80    void finishCreation(JSC::VM&, JSDOMGlobalObject*);
81
82public:
83    typedef DOMConstructorObject Base;
84    static JSTestEventTargetConstructor* create(JSC::VM& vm, JSC::Structure* structure, JSDOMGlobalObject* globalObject)
85    {
86        JSTestEventTargetConstructor* ptr = new (NotNull, JSC::allocateCell<JSTestEventTargetConstructor>(vm.heap)) JSTestEventTargetConstructor(structure, globalObject);
87        ptr->finishCreation(vm, globalObject);
88        return ptr;
89    }
90
91    DECLARE_INFO;
92    static JSC::Structure* createStructure(JSC::VM& vm, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)
93    {
94        return JSC::Structure::create(vm, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), info());
95    }
96};
97
98/* Hash table */
99
100static const struct CompactHashIndex JSTestEventTargetTableIndex[2] = {
101    { -1, -1 },
102    { 0, -1 },
103};
104
105
106static const HashTableValue JSTestEventTargetTableValues[] =
107{
108    { "constructor", DontEnum | ReadOnly, NoIntrinsic, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventTargetConstructor), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) },
109};
110
111static const HashTable JSTestEventTargetTable = { 1, 1, true, JSTestEventTargetTableValues, 0, JSTestEventTargetTableIndex };
112const ClassInfo JSTestEventTargetConstructor::s_info = { "TestEventTargetConstructor", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSTestEventTargetConstructor) };
113
114JSTestEventTargetConstructor::JSTestEventTargetConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
115    : DOMConstructorObject(structure, globalObject)
116{
117}
118
119void JSTestEventTargetConstructor::finishCreation(VM& vm, JSDOMGlobalObject* globalObject)
120{
121    Base::finishCreation(vm);
122    ASSERT(inherits(info()));
123    putDirect(vm, vm.propertyNames->prototype, JSTestEventTarget::getPrototype(vm, globalObject), DontDelete | ReadOnly);
124    putDirect(vm, vm.propertyNames->length, jsNumber(0), ReadOnly | DontDelete | DontEnum);
125}
126
127/* Hash table for prototype */
128
129static const HashTableValue JSTestEventTargetPrototypeTableValues[] =
130{
131    { "item", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionItem), (intptr_t) (1) },
132    { "addEventListener", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionAddEventListener), (intptr_t) (2) },
133    { "removeEventListener", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionRemoveEventListener), (intptr_t) (2) },
134    { "dispatchEvent", JSC::Function, NoIntrinsic, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionDispatchEvent), (intptr_t) (1) },
135};
136
137const ClassInfo JSTestEventTargetPrototype::s_info = { "TestEventTargetPrototype", &Base::s_info, 0, 0, CREATE_METHOD_TABLE(JSTestEventTargetPrototype) };
138
139void JSTestEventTargetPrototype::finishCreation(VM& vm)
140{
141    Base::finishCreation(vm);
142    reifyStaticProperties(vm, JSTestEventTargetPrototypeTableValues, *this);
143}
144
145const ClassInfo JSTestEventTarget::s_info = { "TestEventTarget", &Base::s_info, &JSTestEventTargetTable, 0 , CREATE_METHOD_TABLE(JSTestEventTarget) };
146
147JSTestEventTarget::JSTestEventTarget(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<TestEventTarget> impl)
148    : JSDOMWrapper(structure, globalObject)
149    , m_impl(impl.leakRef())
150{
151}
152
153JSObject* JSTestEventTarget::createPrototype(VM& vm, JSGlobalObject* globalObject)
154{
155    return JSTestEventTargetPrototype::create(vm, globalObject, JSTestEventTargetPrototype::createStructure(vm, globalObject, globalObject->objectPrototype()));
156}
157
158JSObject* JSTestEventTarget::getPrototype(VM& vm, JSGlobalObject* globalObject)
159{
160    return getDOMPrototype<JSTestEventTarget>(vm, globalObject);
161}
162
163void JSTestEventTarget::destroy(JSC::JSCell* cell)
164{
165    JSTestEventTarget* thisObject = static_cast<JSTestEventTarget*>(cell);
166    thisObject->JSTestEventTarget::~JSTestEventTarget();
167}
168
169JSTestEventTarget::~JSTestEventTarget()
170{
171    releaseImplIfNotNull();
172}
173
174bool JSTestEventTarget::getOwnPropertySlot(JSObject* object, ExecState* exec, PropertyName propertyName, PropertySlot& slot)
175{
176    JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(object);
177    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
178    const HashTableValue* entry = getStaticValueSlotEntryWithoutCaching<JSTestEventTarget>(exec, propertyName);
179    if (entry) {
180        slot.setCacheableCustom(thisObject, entry->attributes(), entry->propertyGetter());
181        return true;
182    }
183    unsigned index = propertyName.asIndex();
184    if (index != PropertyName::NotAnIndex && index < thisObject->impl().length()) {
185        unsigned attributes = DontDelete | ReadOnly;
186        slot.setValue(thisObject, attributes, toJS(exec, thisObject->globalObject(), thisObject->impl().item(index)));
187        return true;
188    }
189    if (canGetItemsForName(exec, &thisObject->impl(), propertyName)) {
190        slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, thisObject->nameGetter);
191        return true;
192    }
193    return getStaticValueSlot<JSTestEventTarget, Base>(exec, JSTestEventTargetTable, thisObject, propertyName, slot);
194}
195
196bool JSTestEventTarget::getOwnPropertySlotByIndex(JSObject* object, ExecState* exec, unsigned index, PropertySlot& slot)
197{
198    JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(object);
199    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
200    if (index < thisObject->impl().length()) {
201        unsigned attributes = DontDelete | ReadOnly;
202        slot.setValue(thisObject, attributes, toJS(exec, thisObject->globalObject(), thisObject->impl().item(index)));
203        return true;
204    }
205    PropertyName propertyName = Identifier::from(exec, index);
206    if (canGetItemsForName(exec, &thisObject->impl(), propertyName)) {
207        slot.setCustom(thisObject, ReadOnly | DontDelete | DontEnum, thisObject->nameGetter);
208        return true;
209    }
210    return Base::getOwnPropertySlotByIndex(thisObject, exec, index, slot);
211}
212
213EncodedJSValue jsTestEventTargetConstructor(ExecState* exec, JSObject*, EncodedJSValue thisValue, PropertyName)
214{
215    JSTestEventTarget* domObject = jsDynamicCast<JSTestEventTarget*>(JSValue::decode(thisValue));
216    if (!domObject)
217        return throwVMTypeError(exec);
218    return JSValue::encode(JSTestEventTarget::getConstructor(exec->vm(), domObject->globalObject()));
219}
220
221void JSTestEventTarget::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
222{
223    JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(object);
224    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
225    for (unsigned i = 0, count = thisObject->impl().length(); i < count; ++i)
226        propertyNames.add(Identifier::from(exec, i));
227     Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
228}
229
230JSValue JSTestEventTarget::getConstructor(VM& vm, JSGlobalObject* globalObject)
231{
232    return getDOMConstructor<JSTestEventTargetConstructor>(vm, jsCast<JSDOMGlobalObject*>(globalObject));
233}
234
235EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionItem(ExecState* exec)
236{
237    JSValue thisValue = exec->thisValue();
238    JSTestEventTarget* castedThis = jsDynamicCast<JSTestEventTarget*>(thisValue);
239    if (UNLIKELY(!castedThis))
240        return throwThisTypeError(*exec, "TestEventTarget", "item");
241    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestEventTarget::info());
242    TestEventTarget& impl = castedThis->impl();
243    if (exec->argumentCount() < 1)
244        return throwVMError(exec, createNotEnoughArgumentsError(exec));
245    int index(toUInt32(exec, exec->argument(0), NormalConversion));
246    if (index < 0) {
247        setDOMException(exec, INDEX_SIZE_ERR);
248        return JSValue::encode(jsUndefined());
249    }
250    if (UNLIKELY(exec->hadException()))
251        return JSValue::encode(jsUndefined());
252    JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl.item(index)));
253    return JSValue::encode(result);
254}
255
256EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionAddEventListener(ExecState* exec)
257{
258    JSValue thisValue = exec->thisValue();
259    JSTestEventTarget* castedThis = jsDynamicCast<JSTestEventTarget*>(thisValue);
260    if (UNLIKELY(!castedThis))
261        return throwThisTypeError(*exec, "TestEventTarget", "addEventListener");
262    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestEventTarget::info());
263    TestEventTarget& impl = castedThis->impl();
264    JSValue listener = exec->argument(1);
265    if (!listener.isObject())
266        return JSValue::encode(jsUndefined());
267    impl.addEventListener(exec->argument(0).toString(exec)->value(exec), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)), exec->argument(2).toBoolean(exec));
268    return JSValue::encode(jsUndefined());
269}
270
271EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionRemoveEventListener(ExecState* exec)
272{
273    JSValue thisValue = exec->thisValue();
274    JSTestEventTarget* castedThis = jsDynamicCast<JSTestEventTarget*>(thisValue);
275    if (UNLIKELY(!castedThis))
276        return throwThisTypeError(*exec, "TestEventTarget", "removeEventListener");
277    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestEventTarget::info());
278    TestEventTarget& impl = castedThis->impl();
279    JSValue listener = exec->argument(1);
280    if (!listener.isObject())
281        return JSValue::encode(jsUndefined());
282    impl.removeEventListener(exec->argument(0).toString(exec)->value(exec), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
283    return JSValue::encode(jsUndefined());
284}
285
286EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionDispatchEvent(ExecState* exec)
287{
288    JSValue thisValue = exec->thisValue();
289    JSTestEventTarget* castedThis = jsDynamicCast<JSTestEventTarget*>(thisValue);
290    if (UNLIKELY(!castedThis))
291        return throwThisTypeError(*exec, "TestEventTarget", "dispatchEvent");
292    ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestEventTarget::info());
293    TestEventTarget& impl = castedThis->impl();
294    if (exec->argumentCount() < 1)
295        return throwVMError(exec, createNotEnoughArgumentsError(exec));
296    ExceptionCode ec = 0;
297    Event* evt(toEvent(exec->argument(0)));
298    if (UNLIKELY(exec->hadException()))
299        return JSValue::encode(jsUndefined());
300    JSValue result = jsBoolean(impl.dispatchEvent(evt, ec));
301
302    setDOMException(exec, ec);
303    return JSValue::encode(result);
304}
305
306void JSTestEventTarget::visitChildren(JSCell* cell, SlotVisitor& visitor)
307{
308    JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(cell);
309    ASSERT_GC_OBJECT_INHERITS(thisObject, info());
310    COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
311    ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
312    Base::visitChildren(thisObject, visitor);
313    thisObject->impl().visitJSEventListeners(visitor);
314}
315
316bool JSTestEventTargetOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
317{
318    JSTestEventTarget* jsTestEventTarget = jsCast<JSTestEventTarget*>(handle.slot()->asCell());
319    if (jsTestEventTarget->impl().isFiringEventListeners())
320        return true;
321    UNUSED_PARAM(visitor);
322    return false;
323}
324
325void JSTestEventTargetOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
326{
327    JSTestEventTarget* jsTestEventTarget = jsCast<JSTestEventTarget*>(handle.slot()->asCell());
328    DOMWrapperWorld& world = *static_cast<DOMWrapperWorld*>(context);
329    uncacheWrapper(world, &jsTestEventTarget->impl(), jsTestEventTarget);
330    jsTestEventTarget->releaseImpl();
331}
332
333#if ENABLE(BINDING_INTEGRITY)
334#if PLATFORM(WIN)
335#pragma warning(disable: 4483)
336extern "C" { extern void (*const __identifier("??_7TestEventTarget@WebCore@@6B@")[])(); }
337#else
338extern "C" { extern void* _ZTVN7WebCore15TestEventTargetE[]; }
339#endif
340#endif
341JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject* globalObject, TestEventTarget* impl)
342{
343    if (!impl)
344        return jsNull();
345    if (JSValue result = getExistingWrapper<JSTestEventTarget>(globalObject, impl))
346        return result;
347
348#if ENABLE(BINDING_INTEGRITY)
349    void* actualVTablePointer = *(reinterpret_cast<void**>(impl));
350#if PLATFORM(WIN)
351    void* expectedVTablePointer = reinterpret_cast<void*>(__identifier("??_7TestEventTarget@WebCore@@6B@"));
352#else
353    void* expectedVTablePointer = &_ZTVN7WebCore15TestEventTargetE[2];
354#if COMPILER(CLANG)
355    // If this fails TestEventTarget does not have a vtable, so you need to add the
356    // ImplementationLacksVTable attribute to the interface definition
357    COMPILE_ASSERT(__is_polymorphic(TestEventTarget), TestEventTarget_is_not_polymorphic);
358#endif
359#endif
360    // If you hit this assertion you either have a use after free bug, or
361    // TestEventTarget has subclasses. If TestEventTarget has subclasses that get passed
362    // to toJS() we currently require TestEventTarget you to opt out of binding hardening
363    // by adding the SkipVTableValidation attribute to the interface IDL definition
364    RELEASE_ASSERT(actualVTablePointer == expectedVTablePointer);
365#endif
366    return createNewWrapper<JSTestEventTarget>(globalObject, impl);
367}
368
369TestEventTarget* toTestEventTarget(JSC::JSValue value)
370{
371    if (auto* wrapper = jsDynamicCast<JSTestEventTarget*>(value))
372        return &wrapper->impl();
373    return nullptr;
374}
375
376}
377