|
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 |
|
23 #include "JSHTMLSelectElement.h" |
|
24 |
|
25 #include <wtf/GetPtr.h> |
|
26 |
|
27 #include "ExceptionCode.h" |
|
28 #include "HTMLFormElement.h" |
|
29 #include "HTMLOptionsCollection.h" |
|
30 #include "HTMLSelectElement.h" |
|
31 #include "JSHTMLElement.h" |
|
32 #include "JSHTMLFormElement.h" |
|
33 #include "JSHTMLOptionsCollection.h" |
|
34 #include "JSNode.h" |
|
35 #include "Node.h" |
|
36 #include "PlatformString.h" |
|
37 |
|
38 using namespace KJS; |
|
39 |
|
40 namespace WebCore { |
|
41 |
|
42 /* Hash table */ |
|
43 |
|
44 static const HashEntry JSHTMLSelectElementTableEntries[] = |
|
45 { |
|
46 { 0, 0, 0, 0, 0 }, |
|
47 { "length", JSHTMLSelectElement::LengthAttrNum, DontDelete, 0, &JSHTMLSelectElementTableEntries[13] }, |
|
48 { 0, 0, 0, 0, 0 }, |
|
49 { 0, 0, 0, 0, 0 }, |
|
50 { "size", JSHTMLSelectElement::SizeAttrNum, DontDelete, 0, 0 }, |
|
51 { "form", JSHTMLSelectElement::FormAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
52 { "multiple", JSHTMLSelectElement::MultipleAttrNum, DontDelete, 0, 0 }, |
|
53 { "type", JSHTMLSelectElement::TypeAttrNum, DontDelete|ReadOnly, 0, &JSHTMLSelectElementTableEntries[12] }, |
|
54 { "options", JSHTMLSelectElement::OptionsAttrNum, DontDelete|ReadOnly, 0, 0 }, |
|
55 { "tabIndex", JSHTMLSelectElement::TabIndexAttrNum, DontDelete, 0, &JSHTMLSelectElementTableEntries[15] }, |
|
56 { 0, 0, 0, 0, 0 }, |
|
57 { "value", JSHTMLSelectElement::ValueAttrNum, DontDelete, 0, 0 }, |
|
58 { "selectedIndex", JSHTMLSelectElement::SelectedIndexAttrNum, DontDelete, 0, 0 }, |
|
59 { "disabled", JSHTMLSelectElement::DisabledAttrNum, DontDelete, 0, &JSHTMLSelectElementTableEntries[14] }, |
|
60 { "name", JSHTMLSelectElement::NameAttrNum, DontDelete, 0, 0 }, |
|
61 { "constructor", JSHTMLSelectElement::ConstructorAttrNum, DontDelete|DontEnum|ReadOnly, 0, 0 } |
|
62 }; |
|
63 |
|
64 static const HashTable JSHTMLSelectElementTable = |
|
65 { |
|
66 2, 16, JSHTMLSelectElementTableEntries, 12 |
|
67 }; |
|
68 |
|
69 /* Hash table for constructor */ |
|
70 |
|
71 static const HashEntry JSHTMLSelectElementConstructorTableEntries[] = |
|
72 { |
|
73 { 0, 0, 0, 0, 0 } |
|
74 }; |
|
75 |
|
76 static const HashTable JSHTMLSelectElementConstructorTable = |
|
77 { |
|
78 2, 1, JSHTMLSelectElementConstructorTableEntries, 1 |
|
79 }; |
|
80 |
|
81 class JSHTMLSelectElementConstructor : public DOMObject { |
|
82 public: |
|
83 JSHTMLSelectElementConstructor(ExecState* exec) |
|
84 { |
|
85 setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype()); |
|
86 putDirect(exec->propertyNames().prototype, JSHTMLSelectElementPrototype::self(exec), None); |
|
87 } |
|
88 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); |
|
89 JSValue* getValueProperty(ExecState*, int token) const; |
|
90 virtual const ClassInfo* classInfo() const { return &info; } |
|
91 static const ClassInfo info; |
|
92 |
|
93 virtual bool implementsHasInstance() const { return true; } |
|
94 }; |
|
95 |
|
96 const ClassInfo JSHTMLSelectElementConstructor::info = { "HTMLSelectElementConstructor", 0, &JSHTMLSelectElementConstructorTable, 0 }; |
|
97 |
|
98 bool JSHTMLSelectElementConstructor::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
99 { |
|
100 return getStaticValueSlot<JSHTMLSelectElementConstructor, DOMObject>(exec, &JSHTMLSelectElementConstructorTable, this, propertyName, slot); |
|
101 } |
|
102 |
|
103 JSValue* JSHTMLSelectElementConstructor::getValueProperty(ExecState*, int token) const |
|
104 { |
|
105 // The token is the numeric value of its associated constant |
|
106 return jsNumber(token); |
|
107 } |
|
108 |
|
109 /* Hash table for prototype */ |
|
110 |
|
111 static const HashEntry JSHTMLSelectElementPrototypeTableEntries[] = |
|
112 { |
|
113 { "remove", JSHTMLSelectElement::RemoveFuncNum, DontDelete|Function, 0, 0 }, |
|
114 { "add", JSHTMLSelectElement::AddFuncNum, DontDelete|Function, 2, 0 }, |
|
115 { 0, 0, 0, 0, 0 }, |
|
116 { "blur", JSHTMLSelectElement::BlurFuncNum, DontDelete|Function, 0, &JSHTMLSelectElementPrototypeTableEntries[6] }, |
|
117 { "focus", JSHTMLSelectElement::FocusFuncNum, DontDelete|Function, 0, 0 }, |
|
118 { "item", JSHTMLSelectElement::ItemFuncNum, DontDelete|Function, 1, 0 }, |
|
119 { "namedItem", JSHTMLSelectElement::NamedItemFuncNum, DontDelete|Function, 1, 0 } |
|
120 }; |
|
121 |
|
122 static const HashTable JSHTMLSelectElementPrototypeTable = |
|
123 { |
|
124 2, 7, JSHTMLSelectElementPrototypeTableEntries, 6 |
|
125 }; |
|
126 |
|
127 const ClassInfo JSHTMLSelectElementPrototype::info = { "HTMLSelectElementPrototype", 0, &JSHTMLSelectElementPrototypeTable, 0 }; |
|
128 |
|
129 JSObject* JSHTMLSelectElementPrototype::self(ExecState* exec) |
|
130 { |
|
131 return KJS::cacheGlobalObject<JSHTMLSelectElementPrototype>(exec, "[[JSHTMLSelectElement.prototype]]"); |
|
132 } |
|
133 |
|
134 bool JSHTMLSelectElementPrototype::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
135 { |
|
136 return getStaticFunctionSlot<JSHTMLSelectElementPrototypeFunction, JSObject>(exec, &JSHTMLSelectElementPrototypeTable, this, propertyName, slot); |
|
137 } |
|
138 |
|
139 const ClassInfo JSHTMLSelectElement::info = { "HTMLSelectElement", &JSHTMLElement::info, &JSHTMLSelectElementTable, 0 }; |
|
140 |
|
141 JSHTMLSelectElement::JSHTMLSelectElement(ExecState* exec, HTMLSelectElement* impl) |
|
142 : JSHTMLElement(exec, impl) |
|
143 { |
|
144 setPrototype(JSHTMLSelectElementPrototype::self(exec)); |
|
145 } |
|
146 |
|
147 bool JSHTMLSelectElement::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot) |
|
148 { |
|
149 const HashEntry* entry = Lookup::findEntry(&JSHTMLSelectElementTable, propertyName); |
|
150 if (entry) { |
|
151 slot.setStaticEntry(this, entry, staticValueGetter<JSHTMLSelectElement>); |
|
152 return true; |
|
153 } |
|
154 bool ok; |
|
155 unsigned index = propertyName.toUInt32(&ok, false); |
|
156 if (ok && index < static_cast<HTMLSelectElement*>(impl())->length()) { |
|
157 slot.setCustomIndex(this, index, indexGetter); |
|
158 return true; |
|
159 } |
|
160 return JSHTMLElement::getOwnPropertySlot(exec, propertyName, slot); |
|
161 } |
|
162 |
|
163 JSValue* JSHTMLSelectElement::getValueProperty(ExecState* exec, int token) const |
|
164 { |
|
165 switch (token) { |
|
166 case TypeAttrNum: { |
|
167 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
168 |
|
169 return jsString(imp->type()); |
|
170 } |
|
171 case SelectedIndexAttrNum: { |
|
172 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
173 |
|
174 return jsNumber(imp->selectedIndex()); |
|
175 } |
|
176 case ValueAttrNum: { |
|
177 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
178 |
|
179 return jsString(imp->value()); |
|
180 } |
|
181 case LengthAttrNum: { |
|
182 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
183 |
|
184 return jsNumber(imp->length()); |
|
185 } |
|
186 case FormAttrNum: { |
|
187 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
188 |
|
189 return toJS(exec, WTF::getPtr(imp->form())); |
|
190 } |
|
191 case OptionsAttrNum: { |
|
192 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
193 |
|
194 return toJS(exec, WTF::getPtr(imp->options())); |
|
195 } |
|
196 case DisabledAttrNum: { |
|
197 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
198 |
|
199 return jsBoolean(imp->disabled()); |
|
200 } |
|
201 case MultipleAttrNum: { |
|
202 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
203 |
|
204 return jsBoolean(imp->multiple()); |
|
205 } |
|
206 case NameAttrNum: { |
|
207 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
208 |
|
209 return jsString(imp->name()); |
|
210 } |
|
211 case SizeAttrNum: { |
|
212 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
213 |
|
214 return jsNumber(imp->size()); |
|
215 } |
|
216 case TabIndexAttrNum: { |
|
217 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
218 |
|
219 return jsNumber(imp->tabIndex()); |
|
220 } |
|
221 case ConstructorAttrNum: |
|
222 return getConstructor(exec); |
|
223 } |
|
224 return 0; |
|
225 } |
|
226 |
|
227 void JSHTMLSelectElement::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr) |
|
228 { |
|
229 bool ok; |
|
230 unsigned index = propertyName.toUInt32(&ok, false); |
|
231 if (ok) { |
|
232 indexSetter(exec, index, value, attr); |
|
233 return; |
|
234 } |
|
235 lookupPut<JSHTMLSelectElement, JSHTMLElement>(exec, propertyName, value, attr, &JSHTMLSelectElementTable, this); |
|
236 } |
|
237 |
|
238 void JSHTMLSelectElement::putValueProperty(ExecState* exec, int token, JSValue* value, int /*attr*/) |
|
239 { |
|
240 switch (token) { |
|
241 case SelectedIndexAttrNum: { |
|
242 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
243 |
|
244 imp->setSelectedIndex(value->toInt32(exec)); |
|
245 break; |
|
246 } |
|
247 case ValueAttrNum: { |
|
248 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
249 |
|
250 imp->setValue(valueToStringWithNullCheck(exec, value)); |
|
251 break; |
|
252 } |
|
253 case LengthAttrNum: { |
|
254 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
255 |
|
256 ExceptionCode ec = 0; |
|
257 imp->setLength(value->toInt32(exec), ec); |
|
258 setDOMException(exec, ec); |
|
259 break; |
|
260 } |
|
261 case DisabledAttrNum: { |
|
262 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
263 |
|
264 imp->setDisabled(value->toBoolean(exec)); |
|
265 break; |
|
266 } |
|
267 case MultipleAttrNum: { |
|
268 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
269 |
|
270 imp->setMultiple(value->toBoolean(exec)); |
|
271 break; |
|
272 } |
|
273 case NameAttrNum: { |
|
274 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
275 |
|
276 imp->setName(valueToStringWithNullCheck(exec, value)); |
|
277 break; |
|
278 } |
|
279 case SizeAttrNum: { |
|
280 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
281 |
|
282 imp->setSize(value->toInt32(exec)); |
|
283 break; |
|
284 } |
|
285 case TabIndexAttrNum: { |
|
286 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(impl()); |
|
287 |
|
288 imp->setTabIndex(value->toInt32(exec)); |
|
289 break; |
|
290 } |
|
291 } |
|
292 } |
|
293 |
|
294 JSValue* JSHTMLSelectElement::getConstructor(ExecState* exec) |
|
295 { |
|
296 return KJS::cacheGlobalObject<JSHTMLSelectElementConstructor>(exec, "[[HTMLSelectElement.constructor]]"); |
|
297 } |
|
298 JSValue* JSHTMLSelectElementPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args) |
|
299 { |
|
300 if (!thisObj->inherits(&JSHTMLSelectElement::info)) |
|
301 return throwError(exec, TypeError); |
|
302 |
|
303 HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObj)->impl()); |
|
304 |
|
305 switch (id) { |
|
306 case JSHTMLSelectElement::AddFuncNum: { |
|
307 ExceptionCode ec = 0; |
|
308 HTMLElement* element = toHTMLElement(args[0]); |
|
309 HTMLElement* before = toHTMLElement(args[1]); |
|
310 |
|
311 imp->add(element, before, ec); |
|
312 setDOMException(exec, ec); |
|
313 return jsUndefined(); |
|
314 } |
|
315 case JSHTMLSelectElement::RemoveFuncNum: { |
|
316 return static_cast<JSHTMLSelectElement*>(thisObj)->remove(exec, args); |
|
317 } |
|
318 case JSHTMLSelectElement::BlurFuncNum: { |
|
319 |
|
320 imp->blur(); |
|
321 return jsUndefined(); |
|
322 } |
|
323 case JSHTMLSelectElement::FocusFuncNum: { |
|
324 |
|
325 imp->focus(); |
|
326 return jsUndefined(); |
|
327 } |
|
328 case JSHTMLSelectElement::ItemFuncNum: { |
|
329 bool indexOk; |
|
330 int index = args[0]->toInt32(exec, indexOk); |
|
331 if (!indexOk) { |
|
332 setDOMException(exec, TYPE_MISMATCH_ERR); |
|
333 return jsUndefined(); |
|
334 } |
|
335 if (index < 0) { |
|
336 setDOMException(exec, INDEX_SIZE_ERR); |
|
337 return jsUndefined(); |
|
338 } |
|
339 |
|
340 |
|
341 KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->item(index))); |
|
342 return result; |
|
343 } |
|
344 case JSHTMLSelectElement::NamedItemFuncNum: { |
|
345 String name = args[0]->toString(exec); |
|
346 |
|
347 |
|
348 KJS::JSValue* result = toJS(exec, WTF::getPtr(imp->namedItem(name))); |
|
349 return result; |
|
350 } |
|
351 } |
|
352 return 0; |
|
353 } |
|
354 |
|
355 JSValue* JSHTMLSelectElement::indexGetter(ExecState* exec, JSObject* originalObject, const Identifier& propertyName, const PropertySlot& slot) |
|
356 { |
|
357 JSHTMLSelectElement* thisObj = static_cast<JSHTMLSelectElement*>(slot.slotBase()); |
|
358 return toJS(exec, static_cast<HTMLSelectElement*>(thisObj->impl())->item(slot.index())); |
|
359 } |
|
360 |
|
361 } |