33
29
#include "JSHTMLFormElement.h"
34
30
#include "JSHTMLOptionsCollection.h"
35
31
#include "JSNode.h"
32
#include "JSValidityState.h"
35
#include "ValidityState.h"
39
36
#include <runtime/Error.h>
40
37
#include <runtime/JSNumberCell.h>
41
38
#include <runtime/JSString.h>
39
#include <runtime/PropertyNameArray.h>
40
#include <wtf/GetPtr.h>
43
42
using namespace JSC;
45
44
namespace WebCore {
47
ASSERT_CLASS_FITS_IN_CELL(JSHTMLSelectElement)
46
ASSERT_CLASS_FITS_IN_CELL(JSHTMLSelectElement);
51
static const HashTableValue JSHTMLSelectElementTableValues[14] =
50
static const HashTableValue JSHTMLSelectElementTableValues[15] =
53
52
{ "type", DontDelete|ReadOnly, (intptr_t)jsHTMLSelectElementType, (intptr_t)0 },
54
53
{ "selectedIndex", DontDelete, (intptr_t)jsHTMLSelectElementSelectedIndex, (intptr_t)setJSHTMLSelectElementSelectedIndex },
55
54
{ "value", DontDelete, (intptr_t)jsHTMLSelectElementValue, (intptr_t)setJSHTMLSelectElementValue },
56
55
{ "length", DontDelete, (intptr_t)jsHTMLSelectElementLength, (intptr_t)setJSHTMLSelectElementLength },
57
56
{ "form", DontDelete|ReadOnly, (intptr_t)jsHTMLSelectElementForm, (intptr_t)0 },
57
{ "validity", DontDelete|ReadOnly, (intptr_t)jsHTMLSelectElementValidity, (intptr_t)0 },
58
58
{ "willValidate", DontDelete|ReadOnly, (intptr_t)jsHTMLSelectElementWillValidate, (intptr_t)0 },
59
59
{ "options", DontDelete|ReadOnly, (intptr_t)jsHTMLSelectElementOptions, (intptr_t)0 },
60
60
{ "disabled", DontDelete, (intptr_t)jsHTMLSelectElementDisabled, (intptr_t)setJSHTMLSelectElementDisabled },
178
211
return getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
181
JSValuePtr jsHTMLSelectElementType(ExecState* exec, const Identifier&, const PropertySlot& slot)
214
JSValue jsHTMLSelectElementType(ExecState* exec, const Identifier&, const PropertySlot& slot)
183
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
216
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
218
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
184
219
return jsString(exec, imp->type());
187
JSValuePtr jsHTMLSelectElementSelectedIndex(ExecState* exec, const Identifier&, const PropertySlot& slot)
222
JSValue jsHTMLSelectElementSelectedIndex(ExecState* exec, const Identifier&, const PropertySlot& slot)
189
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
224
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
226
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
190
227
return jsNumber(exec, imp->selectedIndex());
193
JSValuePtr jsHTMLSelectElementValue(ExecState* exec, const Identifier&, const PropertySlot& slot)
230
JSValue jsHTMLSelectElementValue(ExecState* exec, const Identifier&, const PropertySlot& slot)
195
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
232
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
234
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
196
235
return jsString(exec, imp->value());
199
JSValuePtr jsHTMLSelectElementLength(ExecState* exec, const Identifier&, const PropertySlot& slot)
238
JSValue jsHTMLSelectElementLength(ExecState* exec, const Identifier&, const PropertySlot& slot)
201
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
240
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
242
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
202
243
return jsNumber(exec, imp->length());
205
JSValuePtr jsHTMLSelectElementForm(ExecState* exec, const Identifier&, const PropertySlot& slot)
207
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
208
return toJS(exec, WTF::getPtr(imp->form()));
211
JSValuePtr jsHTMLSelectElementWillValidate(ExecState* exec, const Identifier&, const PropertySlot& slot)
213
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
246
JSValue jsHTMLSelectElementForm(ExecState* exec, const Identifier&, const PropertySlot& slot)
248
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
250
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
251
return toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->form()));
254
JSValue jsHTMLSelectElementValidity(ExecState* exec, const Identifier&, const PropertySlot& slot)
256
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
258
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
259
return toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->validity()));
262
JSValue jsHTMLSelectElementWillValidate(ExecState* exec, const Identifier&, const PropertySlot& slot)
264
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
266
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
214
267
return jsBoolean(imp->willValidate());
217
JSValuePtr jsHTMLSelectElementOptions(ExecState* exec, const Identifier&, const PropertySlot& slot)
270
JSValue jsHTMLSelectElementOptions(ExecState* exec, const Identifier&, const PropertySlot& slot)
219
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
220
return toJS(exec, WTF::getPtr(imp->options()));
272
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
274
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
275
return toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->options()));
223
JSValuePtr jsHTMLSelectElementDisabled(ExecState* exec, const Identifier&, const PropertySlot& slot)
278
JSValue jsHTMLSelectElementDisabled(ExecState* exec, const Identifier&, const PropertySlot& slot)
225
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
280
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
282
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
226
283
return jsBoolean(imp->disabled());
229
JSValuePtr jsHTMLSelectElementAutofocus(ExecState* exec, const Identifier&, const PropertySlot& slot)
286
JSValue jsHTMLSelectElementAutofocus(ExecState* exec, const Identifier&, const PropertySlot& slot)
231
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
288
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
290
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
232
291
return jsBoolean(imp->autofocus());
235
JSValuePtr jsHTMLSelectElementMultiple(ExecState* exec, const Identifier&, const PropertySlot& slot)
294
JSValue jsHTMLSelectElementMultiple(ExecState* exec, const Identifier&, const PropertySlot& slot)
237
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
296
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
298
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
238
299
return jsBoolean(imp->multiple());
241
JSValuePtr jsHTMLSelectElementName(ExecState* exec, const Identifier&, const PropertySlot& slot)
302
JSValue jsHTMLSelectElementName(ExecState* exec, const Identifier&, const PropertySlot& slot)
243
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
304
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
306
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
244
307
return jsString(exec, imp->name());
247
JSValuePtr jsHTMLSelectElementSize(ExecState* exec, const Identifier&, const PropertySlot& slot)
310
JSValue jsHTMLSelectElementSize(ExecState* exec, const Identifier&, const PropertySlot& slot)
249
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->impl());
312
JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
314
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl());
250
315
return jsNumber(exec, imp->size());
253
JSValuePtr jsHTMLSelectElementConstructor(ExecState* exec, const Identifier&, const PropertySlot& slot)
318
JSValue jsHTMLSelectElementConstructor(ExecState* exec, const Identifier&, const PropertySlot& slot)
255
return static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()))->getConstructor(exec);
320
JSHTMLSelectElement* domObject = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
321
return JSHTMLSelectElement::getConstructor(exec, domObject->globalObject());
257
void JSHTMLSelectElement::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot)
323
void JSHTMLSelectElement::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
260
326
unsigned index = propertyName.toUInt32(&ok, false);
265
331
lookupPut<JSHTMLSelectElement, Base>(exec, propertyName, value, &JSHTMLSelectElementTable, this, slot);
268
void JSHTMLSelectElement::put(ExecState* exec, unsigned propertyName, JSValuePtr value)
334
void JSHTMLSelectElement::put(ExecState* exec, unsigned propertyName, JSValue value)
270
336
indexSetter(exec, propertyName, value);
274
void setJSHTMLSelectElementSelectedIndex(ExecState* exec, JSObject* thisObject, JSValuePtr value)
340
void setJSHTMLSelectElementSelectedIndex(ExecState* exec, JSObject* thisObject, JSValue value)
276
342
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
277
imp->setSelectedIndex(value->toInt32(exec));
343
imp->setSelectedIndex(value.toInt32(exec));
280
void setJSHTMLSelectElementValue(ExecState* exec, JSObject* thisObject, JSValuePtr value)
346
void setJSHTMLSelectElementValue(ExecState* exec, JSObject* thisObject, JSValue value)
282
348
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
283
349
imp->setValue(valueToStringWithNullCheck(exec, value));
286
void setJSHTMLSelectElementLength(ExecState* exec, JSObject* thisObject, JSValuePtr value)
352
void setJSHTMLSelectElementLength(ExecState* exec, JSObject* thisObject, JSValue value)
288
354
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
289
355
ExceptionCode ec = 0;
290
imp->setLength(value->toInt32(exec), ec);
356
imp->setLength(value.toInt32(exec), ec);
291
357
setDOMException(exec, ec);
294
void setJSHTMLSelectElementDisabled(ExecState* exec, JSObject* thisObject, JSValuePtr value)
296
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
297
imp->setDisabled(value->toBoolean(exec));
300
void setJSHTMLSelectElementAutofocus(ExecState* exec, JSObject* thisObject, JSValuePtr value)
302
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
303
imp->setAutofocus(value->toBoolean(exec));
306
void setJSHTMLSelectElementMultiple(ExecState* exec, JSObject* thisObject, JSValuePtr value)
308
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
309
imp->setMultiple(value->toBoolean(exec));
312
void setJSHTMLSelectElementName(ExecState* exec, JSObject* thisObject, JSValuePtr value)
360
void setJSHTMLSelectElementDisabled(ExecState* exec, JSObject* thisObject, JSValue value)
362
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
363
imp->setDisabled(value.toBoolean(exec));
366
void setJSHTMLSelectElementAutofocus(ExecState* exec, JSObject* thisObject, JSValue value)
368
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
369
imp->setAutofocus(value.toBoolean(exec));
372
void setJSHTMLSelectElementMultiple(ExecState* exec, JSObject* thisObject, JSValue value)
374
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
375
imp->setMultiple(value.toBoolean(exec));
378
void setJSHTMLSelectElementName(ExecState* exec, JSObject* thisObject, JSValue value)
314
380
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
315
381
imp->setName(valueToStringWithNullCheck(exec, value));
318
void setJSHTMLSelectElementSize(ExecState* exec, JSObject* thisObject, JSValuePtr value)
384
void setJSHTMLSelectElementSize(ExecState* exec, JSObject* thisObject, JSValue value)
320
386
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(static_cast<JSHTMLSelectElement*>(thisObject)->impl());
321
imp->setSize(value->toInt32(exec));
387
imp->setSize(value.toInt32(exec));
324
void JSHTMLSelectElement::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
390
void JSHTMLSelectElement::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
326
392
for (unsigned i = 0; i < static_cast<HTMLSelectElement*>(impl())->length(); ++i)
327
393
propertyNames.add(Identifier::from(exec, i));
328
Base::getPropertyNames(exec, propertyNames);
331
JSValuePtr JSHTMLSelectElement::getConstructor(ExecState* exec)
333
return getDOMConstructor<JSHTMLSelectElementConstructor>(exec);
336
JSValuePtr jsHTMLSelectElementPrototypeFunctionAdd(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args)
338
if (!thisValue->isObject(&JSHTMLSelectElement::s_info))
394
Base::getOwnPropertyNames(exec, propertyNames);
397
JSValue JSHTMLSelectElement::getConstructor(ExecState* exec, JSGlobalObject* globalObject)
399
return getDOMConstructor<JSHTMLSelectElementConstructor>(exec, static_cast<JSDOMGlobalObject*>(globalObject));
402
JSValue JSC_HOST_CALL jsHTMLSelectElementPrototypeFunctionCheckValidity(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
405
if (!thisValue.inherits(&JSHTMLSelectElement::s_info))
406
return throwError(exec, TypeError);
407
JSHTMLSelectElement* castedThisObj = static_cast<JSHTMLSelectElement*>(asObject(thisValue));
408
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThisObj->impl());
411
JSC::JSValue result = jsBoolean(imp->checkValidity());
415
JSValue JSC_HOST_CALL jsHTMLSelectElementPrototypeFunctionSetCustomValidity(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
418
if (!thisValue.inherits(&JSHTMLSelectElement::s_info))
419
return throwError(exec, TypeError);
420
JSHTMLSelectElement* castedThisObj = static_cast<JSHTMLSelectElement*>(asObject(thisValue));
421
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThisObj->impl());
422
const UString& error = valueToStringWithUndefinedOrNullCheck(exec, args.at(0));
424
imp->setCustomValidity(error);
425
return jsUndefined();
428
JSValue JSC_HOST_CALL jsHTMLSelectElementPrototypeFunctionAdd(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
431
if (!thisValue.inherits(&JSHTMLSelectElement::s_info))
339
432
return throwError(exec, TypeError);
340
433
JSHTMLSelectElement* castedThisObj = static_cast<JSHTMLSelectElement*>(asObject(thisValue));
341
434
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThisObj->impl());
342
435
ExceptionCode ec = 0;
343
HTMLElement* element = toHTMLElement(args.at(exec, 0));
344
HTMLElement* before = toHTMLElement(args.at(exec, 1));
436
HTMLElement* element = toHTMLElement(args.at(0));
437
HTMLElement* before = toHTMLElement(args.at(1));
346
439
imp->add(element, before, ec);
347
440
setDOMException(exec, ec);
348
441
return jsUndefined();
351
JSValuePtr jsHTMLSelectElementPrototypeFunctionRemove(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args)
444
JSValue JSC_HOST_CALL jsHTMLSelectElementPrototypeFunctionRemove(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
353
if (!thisValue->isObject(&JSHTMLSelectElement::s_info))
447
if (!thisValue.inherits(&JSHTMLSelectElement::s_info))
354
448
return throwError(exec, TypeError);
355
449
JSHTMLSelectElement* castedThisObj = static_cast<JSHTMLSelectElement*>(asObject(thisValue));
356
450
return castedThisObj->remove(exec, args);
359
JSValuePtr jsHTMLSelectElementPrototypeFunctionItem(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args)
453
JSValue JSC_HOST_CALL jsHTMLSelectElementPrototypeFunctionItem(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
361
if (!thisValue->isObject(&JSHTMLSelectElement::s_info))
456
if (!thisValue.inherits(&JSHTMLSelectElement::s_info))
362
457
return throwError(exec, TypeError);
363
458
JSHTMLSelectElement* castedThisObj = static_cast<JSHTMLSelectElement*>(asObject(thisValue));
364
459
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThisObj->impl());
365
int index = args.at(exec, 0)->toInt32(exec);
460
int index = args.at(0).toInt32(exec);
367
462
setDOMException(exec, INDEX_SIZE_ERR);
368
463
return jsUndefined();
372
JSC::JSValuePtr result = toJS(exec, WTF::getPtr(imp->item(index)));
467
JSC::JSValue result = toJS(exec, castedThisObj->globalObject(), WTF::getPtr(imp->item(index)));
376
JSValuePtr jsHTMLSelectElementPrototypeFunctionNamedItem(ExecState* exec, JSObject*, JSValuePtr thisValue, const ArgList& args)
471
JSValue JSC_HOST_CALL jsHTMLSelectElementPrototypeFunctionNamedItem(ExecState* exec, JSObject*, JSValue thisValue, const ArgList& args)
378
if (!thisValue->isObject(&JSHTMLSelectElement::s_info))
474
if (!thisValue.inherits(&JSHTMLSelectElement::s_info))
379
475
return throwError(exec, TypeError);
380
476
JSHTMLSelectElement* castedThisObj = static_cast<JSHTMLSelectElement*>(asObject(thisValue));
381
477
HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThisObj->impl());
382
const UString& name = args.at(exec, 0)->toString(exec);
385
JSC::JSValuePtr result = toJS(exec, WTF::getPtr(imp->namedItem(name)));
478
const UString& name = args.at(0).toString(exec);
481
JSC::JSValue result = toJS(exec, castedThisObj->globalObject(), WTF::getPtr(imp->namedItem(name)));
390
JSValuePtr JSHTMLSelectElement::indexGetter(ExecState* exec, const Identifier& propertyName, const PropertySlot& slot)
486
JSValue JSHTMLSelectElement::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)
392
488
JSHTMLSelectElement* thisObj = static_cast<JSHTMLSelectElement*>(asObject(slot.slotBase()));
393
return toJS(exec, static_cast<HTMLSelectElement*>(thisObj->impl())->item(slot.index()));
489
return toJS(exec, thisObj->globalObject(), static_cast<HTMLSelectElement*>(thisObj->impl())->item(slot.index()));