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 "JSNodeList.h"
23 
24 #include "ExceptionCode.h"
25 #include "JSDOMBinding.h"
26 #include "JSNode.h"
27 #include "Node.h"
28 #include "NodeList.h"
29 #include "wtf/text/AtomicString.h"
30 #include <runtime/Error.h>
31 #include <runtime/PropertyNameArray.h>
32 #include <wtf/GetPtr.h>
33 
34 using namespace JSC;
35 
36 namespace WebCore {
37 
38 ASSERT_CLASS_FITS_IN_CELL(JSNodeList);
39 
40 /* Hash table */
41 #if ENABLE(JIT)
42 #define THUNK_GENERATOR(generator) , generator
43 #else
44 #define THUNK_GENERATOR(generator)
45 #endif
46 
47 static const HashTableValue JSNodeListTableValues[3] =
48 {
49     { "length", DontDelete | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeListLength), (intptr_t)0 THUNK_GENERATOR(0) },
50     { "constructor", DontEnum | ReadOnly, (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsNodeListConstructor), (intptr_t)0 THUNK_GENERATOR(0) },
51     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
52 };
53 
54 #undef THUNK_GENERATOR
55 static JSC_CONST_HASHTABLE HashTable JSNodeListTable = { 5, 3, JSNodeListTableValues, 0 };
56 /* Hash table for constructor */
57 #if ENABLE(JIT)
58 #define THUNK_GENERATOR(generator) , generator
59 #else
60 #define THUNK_GENERATOR(generator)
61 #endif
62 
63 static const HashTableValue JSNodeListConstructorTableValues[1] =
64 {
65     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
66 };
67 
68 #undef THUNK_GENERATOR
69 static JSC_CONST_HASHTABLE HashTable JSNodeListConstructorTable = { 1, 0, JSNodeListConstructorTableValues, 0 };
70 class JSNodeListConstructor : public DOMConstructorObject {
71 public:
72     JSNodeListConstructor(JSC::ExecState*, JSC::Structure*, JSDOMGlobalObject*);
73 
74     virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier&, JSC::PropertySlot&);
75     virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier&, JSC::PropertyDescriptor&);
76     static const JSC::ClassInfo s_info;
createStructure(JSC::JSGlobalData & globalData,JSC::JSValue prototype)77     static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype)
78     {
79         return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
80     }
81 protected:
82     static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::ImplementsHasInstance | DOMConstructorObject::StructureFlags;
83 };
84 
85 const ClassInfo JSNodeListConstructor::s_info = { "NodeListConstructor", &DOMConstructorObject::s_info, &JSNodeListConstructorTable, 0 };
86 
JSNodeListConstructor(ExecState * exec,Structure * structure,JSDOMGlobalObject * globalObject)87 JSNodeListConstructor::JSNodeListConstructor(ExecState* exec, Structure* structure, JSDOMGlobalObject* globalObject)
88     : DOMConstructorObject(structure, globalObject)
89 {
90     ASSERT(inherits(&s_info));
91     putDirect(exec->globalData(), exec->propertyNames().prototype, JSNodeListPrototype::self(exec, globalObject), DontDelete | ReadOnly);
92 }
93 
getOwnPropertySlot(ExecState * exec,const Identifier & propertyName,PropertySlot & slot)94 bool JSNodeListConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
95 {
96     return getStaticValueSlot<JSNodeListConstructor, JSDOMWrapper>(exec, &JSNodeListConstructorTable, this, propertyName, slot);
97 }
98 
getOwnPropertyDescriptor(ExecState * exec,const Identifier & propertyName,PropertyDescriptor & descriptor)99 bool JSNodeListConstructor::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
100 {
101     return getStaticValueDescriptor<JSNodeListConstructor, JSDOMWrapper>(exec, &JSNodeListConstructorTable, this, propertyName, descriptor);
102 }
103 
104 /* Hash table for prototype */
105 #if ENABLE(JIT)
106 #define THUNK_GENERATOR(generator) , generator
107 #else
108 #define THUNK_GENERATOR(generator)
109 #endif
110 
111 static const HashTableValue JSNodeListPrototypeTableValues[2] =
112 {
113     { "item", DontDelete | Function, (intptr_t)static_cast<NativeFunction>(jsNodeListPrototypeFunctionItem), (intptr_t)1 THUNK_GENERATOR(0) },
114     { 0, 0, 0, 0 THUNK_GENERATOR(0) }
115 };
116 
117 #undef THUNK_GENERATOR
118 static JSC_CONST_HASHTABLE HashTable JSNodeListPrototypeTable = { 2, 1, JSNodeListPrototypeTableValues, 0 };
119 const ClassInfo JSNodeListPrototype::s_info = { "NodeListPrototype", &JSC::JSObjectWithGlobalObject::s_info, &JSNodeListPrototypeTable, 0 };
120 
self(ExecState * exec,JSGlobalObject * globalObject)121 JSObject* JSNodeListPrototype::self(ExecState* exec, JSGlobalObject* globalObject)
122 {
123     return getDOMPrototype<JSNodeList>(exec, globalObject);
124 }
125 
getOwnPropertySlot(ExecState * exec,const Identifier & propertyName,PropertySlot & slot)126 bool JSNodeListPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
127 {
128     return getStaticFunctionSlot<JSObject>(exec, &JSNodeListPrototypeTable, this, propertyName, slot);
129 }
130 
getOwnPropertyDescriptor(ExecState * exec,const Identifier & propertyName,PropertyDescriptor & descriptor)131 bool JSNodeListPrototype::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
132 {
133     return getStaticFunctionDescriptor<JSObject>(exec, &JSNodeListPrototypeTable, this, propertyName, descriptor);
134 }
135 
136 const ClassInfo JSNodeList::s_info = { "NodeList", &JSDOMWrapper::s_info, &JSNodeListTable, 0 };
137 
JSNodeList(Structure * structure,JSDOMGlobalObject * globalObject,PassRefPtr<NodeList> impl)138 JSNodeList::JSNodeList(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<NodeList> impl)
139     : JSDOMWrapper(structure, globalObject)
140     , m_impl(impl)
141 {
142     ASSERT(inherits(&s_info));
143 }
144 
createPrototype(ExecState * exec,JSGlobalObject * globalObject)145 JSObject* JSNodeList::createPrototype(ExecState* exec, JSGlobalObject* globalObject)
146 {
147     return new (exec) JSNodeListPrototype(exec->globalData(), globalObject, JSNodeListPrototype::createStructure(globalObject->globalData(), globalObject->objectPrototype()));
148 }
149 
getOwnPropertySlot(ExecState * exec,const Identifier & propertyName,PropertySlot & slot)150 bool JSNodeList::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
151 {
152     const HashEntry* entry = JSNodeListTable.entry(exec, propertyName);
153     if (entry) {
154         slot.setCustom(this, entry->propertyGetter());
155         return true;
156     }
157     bool ok;
158     unsigned index = propertyName.toUInt32(ok);
159     if (ok && index < static_cast<NodeList*>(impl())->length()) {
160         slot.setCustomIndex(this, index, indexGetter);
161         return true;
162     }
163     if (canGetItemsForName(exec, static_cast<NodeList*>(impl()), propertyName)) {
164         slot.setCustom(this, nameGetter);
165         return true;
166     }
167     return getStaticValueSlot<JSNodeList, Base>(exec, &JSNodeListTable, this, propertyName, slot);
168 }
169 
getOwnPropertyDescriptor(ExecState * exec,const Identifier & propertyName,PropertyDescriptor & descriptor)170 bool JSNodeList::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
171 {
172     const HashEntry* entry = JSNodeListTable.entry(exec, propertyName);
173     if (entry) {
174         PropertySlot slot;
175         slot.setCustom(this, entry->propertyGetter());
176         descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());
177         return true;
178     }
179     bool ok;
180     unsigned index = propertyName.toUInt32(ok);
181     if (ok && index < static_cast<NodeList*>(impl())->length()) {
182         PropertySlot slot;
183         slot.setCustomIndex(this, index, indexGetter);
184         descriptor.setDescriptor(slot.getValue(exec, propertyName), DontDelete | ReadOnly);
185         return true;
186     }
187     if (canGetItemsForName(exec, static_cast<NodeList*>(impl()), propertyName)) {
188         PropertySlot slot;
189         slot.setCustom(this, nameGetter);
190         descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);
191         return true;
192     }
193     return getStaticValueDescriptor<JSNodeList, Base>(exec, &JSNodeListTable, this, propertyName, descriptor);
194 }
195 
getOwnPropertySlot(ExecState * exec,unsigned propertyName,PropertySlot & slot)196 bool JSNodeList::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
197 {
198     if (propertyName < static_cast<NodeList*>(impl())->length()) {
199         slot.setCustomIndex(this, propertyName, indexGetter);
200         return true;
201     }
202     return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
203 }
204 
jsNodeListLength(ExecState * exec,JSValue slotBase,const Identifier &)205 JSValue jsNodeListLength(ExecState* exec, JSValue slotBase, const Identifier&)
206 {
207     JSNodeList* castedThis = static_cast<JSNodeList*>(asObject(slotBase));
208     UNUSED_PARAM(exec);
209     NodeList* imp = static_cast<NodeList*>(castedThis->impl());
210     JSValue result = jsNumber(imp->length());
211     return result;
212 }
213 
214 
jsNodeListConstructor(ExecState * exec,JSValue slotBase,const Identifier &)215 JSValue jsNodeListConstructor(ExecState* exec, JSValue slotBase, const Identifier&)
216 {
217     JSNodeList* domObject = static_cast<JSNodeList*>(asObject(slotBase));
218     return JSNodeList::getConstructor(exec, domObject->globalObject());
219 }
220 
getOwnPropertyNames(ExecState * exec,PropertyNameArray & propertyNames,EnumerationMode mode)221 void JSNodeList::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
222 {
223     for (unsigned i = 0; i < static_cast<NodeList*>(impl())->length(); ++i)
224         propertyNames.add(Identifier::from(exec, i));
225      Base::getOwnPropertyNames(exec, propertyNames, mode);
226 }
227 
getConstructor(ExecState * exec,JSGlobalObject * globalObject)228 JSValue JSNodeList::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
229 {
230     return getDOMConstructor<JSNodeListConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
231 }
232 
jsNodeListPrototypeFunctionItem(ExecState * exec)233 EncodedJSValue JSC_HOST_CALL jsNodeListPrototypeFunctionItem(ExecState* exec)
234 {
235     JSValue thisValue = exec->hostThisValue();
236     if (!thisValue.inherits(&JSNodeList::s_info))
237         return throwVMTypeError(exec);
238     JSNodeList* castedThis = static_cast<JSNodeList*>(asObject(thisValue));
239     NodeList* imp = static_cast<NodeList*>(castedThis->impl());
240     int index(exec->argument(0).toUInt32(exec));
241     if (index < 0) {
242         setDOMException(exec, INDEX_SIZE_ERR);
243         return JSValue::encode(jsUndefined());
244     }
245     if (exec->hadException())
246         return JSValue::encode(jsUndefined());
247 
248 
249     JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->item(index)));
250     return JSValue::encode(result);
251 }
252 
253 
indexGetter(ExecState * exec,JSValue slotBase,unsigned index)254 JSValue JSNodeList::indexGetter(ExecState* exec, JSValue slotBase, unsigned index)
255 {
256     JSNodeList* thisObj = static_cast<JSNodeList*>(asObject(slotBase));
257     return toJS(exec, thisObj->globalObject(), static_cast<NodeList*>(thisObj->impl())->item(index));
258 }
259 
finalize(JSC::Handle<JSC::Unknown> handle,void * context)260 void JSNodeListOwner::finalize(JSC::Handle<JSC::Unknown> handle, void* context)
261 {
262     JSNodeList* jsNodeList = static_cast<JSNodeList*>(handle.get().asCell());
263     DOMWrapperWorld* world = static_cast<DOMWrapperWorld*>(context);
264     uncacheWrapper(world, jsNodeList->impl(), jsNodeList);
265 }
266 
toJS(JSC::ExecState * exec,JSDOMGlobalObject * globalObject,NodeList * impl)267 JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, NodeList* impl)
268 {
269     return wrap<JSNodeList>(exec, globalObject, impl);
270 }
271 
toNodeList(JSC::JSValue value)272 NodeList* toNodeList(JSC::JSValue value)
273 {
274     return value.inherits(&JSNodeList::s_info) ? static_cast<JSNodeList*>(asObject(value))->impl() : 0;
275 }
276 
277 }
278