2 This file is part of the WebKit open source project.
3 This file has been generated by generate-bindings.pl. DO NOT MODIFY!
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.
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.
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.
22 #include "JSTestEventTarget.h"
25 #include "ExceptionCode.h"
26 #include "JSDOMBinding.h"
28 #include "JSEventListener.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>
41 ASSERT_CLASS_FITS_IN_CELL(JSTestEventTarget);
44 static const HashTableValue JSTestEventTargetTableValues[] =
46 { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestEventTargetConstructor), (intptr_t)0, NoIntrinsic },
47 { 0, 0, 0, 0, NoIntrinsic }
50 static const HashTable JSTestEventTargetTable = { 2, 1, JSTestEventTargetTableValues, 0 };
51 /* Hash table for constructor */
53 static const HashTableValue JSTestEventTargetConstructorTableValues[] =
55 { 0, 0, 0, 0, NoIntrinsic }
58 static const HashTable JSTestEventTargetConstructorTable = { 1, 0, JSTestEventTargetConstructorTableValues, 0 };
59 const ClassInfo JSTestEventTargetConstructor::s_info = { "TestEventTargetConstructor", &Base::s_info, &JSTestEventTargetConstructorTable, 0, CREATE_METHOD_TABLE(JSTestEventTargetConstructor) };
61 JSTestEventTargetConstructor::JSTestEventTargetConstructor(Structure* structure, JSDOMGlobalObject* globalObject)
62 : DOMConstructorObject(structure, globalObject)
66 void JSTestEventTargetConstructor::finishCreation(ExecState* exec, JSDOMGlobalObject* globalObject)
68 Base::finishCreation(exec->globalData());
69 ASSERT(inherits(&s_info));
70 putDirect(exec->globalData(), exec->propertyNames().prototype, JSTestEventTargetPrototype::self(exec, globalObject), DontDelete | ReadOnly);
73 bool JSTestEventTargetConstructor::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
75 return getStaticValueSlot<JSTestEventTargetConstructor, JSDOMWrapper>(exec, &JSTestEventTargetConstructorTable, static_cast<JSTestEventTargetConstructor*>(cell), propertyName, slot);
78 bool JSTestEventTargetConstructor::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
80 return getStaticValueDescriptor<JSTestEventTargetConstructor, JSDOMWrapper>(exec, &JSTestEventTargetConstructorTable, static_cast<JSTestEventTargetConstructor*>(object), propertyName, descriptor);
83 /* Hash table for prototype */
85 static const HashTableValue JSTestEventTargetPrototypeTableValues[] =
87 { "item", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionItem), (intptr_t)1, NoIntrinsic },
88 { "addEventListener", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionAddEventListener), (intptr_t)3, NoIntrinsic },
89 { "removeEventListener", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionRemoveEventListener), (intptr_t)3, NoIntrinsic },
90 { "dispatchEvent", DontDelete | JSC::Function, (intptr_t)static_cast<NativeFunction>(jsTestEventTargetPrototypeFunctionDispatchEvent), (intptr_t)1, NoIntrinsic },
91 { 0, 0, 0, 0, NoIntrinsic }
94 static const HashTable JSTestEventTargetPrototypeTable = { 8, 7, JSTestEventTargetPrototypeTableValues, 0 };
95 const ClassInfo JSTestEventTargetPrototype::s_info = { "TestEventTargetPrototype", &Base::s_info, &JSTestEventTargetPrototypeTable, 0, CREATE_METHOD_TABLE(JSTestEventTargetPrototype) };
97 JSObject* JSTestEventTargetPrototype::self(ExecState* exec, JSGlobalObject* globalObject)
99 return getDOMPrototype<JSTestEventTarget>(exec, globalObject);
102 bool JSTestEventTargetPrototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
104 JSTestEventTargetPrototype* thisObject = jsCast<JSTestEventTargetPrototype*>(cell);
105 return getStaticFunctionSlot<JSObject>(exec, &JSTestEventTargetPrototypeTable, thisObject, propertyName, slot);
108 bool JSTestEventTargetPrototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
110 JSTestEventTargetPrototype* thisObject = jsCast<JSTestEventTargetPrototype*>(object);
111 return getStaticFunctionDescriptor<JSObject>(exec, &JSTestEventTargetPrototypeTable, thisObject, propertyName, descriptor);
114 const ClassInfo JSTestEventTarget::s_info = { "TestEventTarget", &Base::s_info, &JSTestEventTargetTable, 0 , CREATE_METHOD_TABLE(JSTestEventTarget) };
116 JSTestEventTarget::JSTestEventTarget(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<TestEventTarget> impl)
117 : JSDOMWrapper(structure, globalObject)
118 , m_impl(impl.leakRef())
122 void JSTestEventTarget::finishCreation(JSGlobalData& globalData)
124 Base::finishCreation(globalData);
125 ASSERT(inherits(&s_info));
128 JSObject* JSTestEventTarget::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
130 return JSTestEventTargetPrototype::create(exec->globalData(), globalObject, JSTestEventTargetPrototype::createStructure(globalObject->globalData(), globalObject, globalObject->objectPrototype()));
133 void JSTestEventTarget::destroy(JSC::JSCell* cell)
135 JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(cell);
136 thisObject->JSTestEventTarget::~JSTestEventTarget();
139 JSTestEventTarget::~JSTestEventTarget()
141 releaseImplIfNotNull();
144 bool JSTestEventTarget::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
146 JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(cell);
147 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
148 const HashEntry* entry = JSTestEventTargetTable.entry(exec, propertyName);
150 slot.setCustom(thisObject, entry->propertyGetter());
154 unsigned index = propertyName.toUInt32(ok);
155 if (ok && index < static_cast<TestEventTarget*>(thisObject->impl())->length()) {
156 slot.setCustomIndex(thisObject, index, indexGetter);
159 if (canGetItemsForName(exec, static_cast<TestEventTarget*>(thisObject->impl()), propertyName)) {
160 slot.setCustom(thisObject, thisObject->nameGetter);
163 return getStaticValueSlot<JSTestEventTarget, Base>(exec, &JSTestEventTargetTable, thisObject, propertyName, slot);
166 bool JSTestEventTarget::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
168 JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(object);
169 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
170 const HashEntry* entry = JSTestEventTargetTable.entry(exec, propertyName);
173 slot.setCustom(thisObject, entry->propertyGetter());
174 descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
178 unsigned index = propertyName.toUInt32(ok);
179 if (ok && index < static_cast<TestEventTarget*>(thisObject->impl())->length()) {
181 slot.setCustomIndex(thisObject, index, indexGetter);
182 descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly);
185 if (canGetItemsForName(exec, static_cast<TestEventTarget*>(thisObject->impl()), propertyName)) {
187 slot.setCustom(thisObject, nameGetter);
188 descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
191 return getStaticValueDescriptor<JSTestEventTarget, Base>(exec, &JSTestEventTargetTable, thisObject, propertyName, descriptor);
194 bool JSTestEventTarget::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
196 JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(cell);
197 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
198 if (propertyName < static_cast<TestEventTarget*>(thisObject->impl())->length()) {
199 slot.setCustomIndex(thisObject, propertyName, thisObject->indexGetter);
202 return thisObject->methodTable()->getOwnPropertySlot(thisObject, exec, Identifier::from(exec, propertyName), slot);
205 JSValue jsTestEventTargetConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
207 JSTestEventTarget* domObject = static_cast<JSTestEventTarget*>(asObject(slotBase));
208 return JSTestEventTarget::getConstructor(exec, domObject->globalObject());
211 void JSTestEventTarget::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
213 JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(object);
214 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
215 for (unsigned i = 0; i < static_cast<TestEventTarget*>(thisObject->impl())->length(); ++i)
216 propertyNames.add(Identifier::from(exec, i));
217 Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
220 JSValue JSTestEventTarget::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
222 return getDOMConstructor<JSTestEventTargetConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
225 EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionItem(ExecState* exec)
227 JSValue thisValue = exec->hostThisValue();
228 if (!thisValue.inherits(&JSTestEventTarget::s_info))
229 return throwVMTypeError(exec);
230 JSTestEventTarget* castedThis = static_cast<JSTestEventTarget*>(asObject(thisValue));
231 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestEventTarget::s_info);
232 TestEventTarget* impl = static_cast<TestEventTarget*>(castedThis->impl());
233 if (exec->argumentCount() < 1)
234 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
235 int index(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined).toUInt32(exec));
237 setDOMException(exec, INDEX_SIZE_ERR);
238 return JSValue::encode(jsUndefined());
240 if (exec->hadException())
241 return JSValue::encode(jsUndefined());
243 JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(impl->item(index)));
244 return JSValue::encode(result);
247 EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionAddEventListener(ExecState* exec)
249 JSValue thisValue = exec->hostThisValue();
250 if (!thisValue.inherits(&JSTestEventTarget::s_info))
251 return throwVMTypeError(exec);
252 JSTestEventTarget* castedThis = static_cast<JSTestEventTarget*>(asObject(thisValue));
253 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestEventTarget::s_info);
254 TestEventTarget* impl = static_cast<TestEventTarget*>(castedThis->impl());
255 if (exec->argumentCount() < 2)
256 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
257 JSValue listener = exec->argument(1);
258 if (!listener.isObject())
259 return JSValue::encode(jsUndefined());
260 impl->addEventListener(ustringToAtomicString(exec->argument(0).toString(exec)->value(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)), exec->argument(2).toBoolean(exec));
261 return JSValue::encode(jsUndefined());
264 EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionRemoveEventListener(ExecState* exec)
266 JSValue thisValue = exec->hostThisValue();
267 if (!thisValue.inherits(&JSTestEventTarget::s_info))
268 return throwVMTypeError(exec);
269 JSTestEventTarget* castedThis = static_cast<JSTestEventTarget*>(asObject(thisValue));
270 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestEventTarget::s_info);
271 TestEventTarget* impl = static_cast<TestEventTarget*>(castedThis->impl());
272 if (exec->argumentCount() < 2)
273 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
274 JSValue listener = exec->argument(1);
275 if (!listener.isObject())
276 return JSValue::encode(jsUndefined());
277 impl->removeEventListener(ustringToAtomicString(exec->argument(0).toString(exec)->value(exec)), JSEventListener::create(asObject(listener), castedThis, false, currentWorld(exec)).get(), exec->argument(2).toBoolean(exec));
278 return JSValue::encode(jsUndefined());
281 EncodedJSValue JSC_HOST_CALL jsTestEventTargetPrototypeFunctionDispatchEvent(ExecState* exec)
283 JSValue thisValue = exec->hostThisValue();
284 if (!thisValue.inherits(&JSTestEventTarget::s_info))
285 return throwVMTypeError(exec);
286 JSTestEventTarget* castedThis = static_cast<JSTestEventTarget*>(asObject(thisValue));
287 ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTestEventTarget::s_info);
288 TestEventTarget* impl = static_cast<TestEventTarget*>(castedThis->impl());
289 if (exec->argumentCount() < 1)
290 return throwVMError(exec, createTypeError(exec, "Not enough arguments"));
291 ExceptionCode ec = 0;
292 Event* evt(toEvent(MAYBE_MISSING_PARAMETER(exec, 0, DefaultIsUndefined)));
293 if (exec->hadException())
294 return JSValue::encode(jsUndefined());
296 JSC::JSValue result = jsBoolean(impl->dispatchEvent(evt, ec));
297 setDOMException(exec, ec);
298 return JSValue::encode(result);
301 void JSTestEventTarget::visitChildren(JSCell* cell, SlotVisitor& visitor)
303 JSTestEventTarget* thisObject = jsCast<JSTestEventTarget*>(cell);
304 ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);
305 COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);
306 ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());
307 Base::visitChildren(thisObject, visitor);
308 thisObject->impl()->visitJSEventListeners(visitor);
312 JSValue JSTestEventTarget::indexGetter(ExecState* exec, JSValue slotBase, unsigned index)
314 JSTestEventTarget* thisObj = static_cast<JSTestEventTarget*>(asObject(slotBase));
315 ASSERT_GC_OBJECT_INHERITS(thisObj, &s_info);
316 return toJS(exec, thisObj->globalObject(), static_cast<TestEventTarget*>(thisObj->impl())->item(index));
319 static inline bool isObservable(JSTestEventTarget* jsTestEventTarget)
321 if (jsTestEventTarget->hasCustomProperties())
323 if (jsTestEventTarget->impl()->hasEventListeners())
328 bool JSTestEventTargetOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown> handle, void*, SlotVisitor& visitor)
330 JSTestEventTarget* jsTestEventTarget = static_cast<JSTestEventTarget*>(handle.get().asCell());
331 if (!isObservable(jsTestEventTarget))
333 UNUSED_PARAM(visitor);
337 void JSTestEventTargetOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
339 JSTestEventTarget* jsTestEventTarget = static_cast<JSTestEventTarget*>(handle.get().asCell());
340 DOMWrapperWorld* world = static_cast<DOMWrapperWorld*>(context);
341 uncacheWrapper(world, jsTestEventTarget->impl(), jsTestEventTarget);
342 jsTestEventTarget->releaseImpl();
345 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, TestEventTarget* impl)
347 return wrap<JSTestEventTarget>(exec, globalObject, impl);
350 TestEventTarget* toTestEventTarget(JSC::JSValue value)
352 return value.inherits(&JSTestEventTarget::s_info) ? static_cast<JSTestEventTarget*>(asObject(value))->impl() : 0;