• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 Apple, Inc.
3  * Copyright (C) 2007 Alexey Proskuryakov (ap@webkit.org)
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 "JSHTMLSelectElementCustom.h"
23 
24 #include "ExceptionCode.h"
25 #include "HTMLNames.h"
26 #include "HTMLOptionElement.h"
27 #include "HTMLSelectElement.h"
28 #include "JSHTMLOptionElement.h"
29 
30 namespace WebCore {
31 
32 using namespace JSC;
33 using namespace HTMLNames;
34 
remove(ExecState * exec,const ArgList & args)35 JSValue JSHTMLSelectElement::remove(ExecState* exec, const ArgList& args)
36 {
37     HTMLSelectElement& select = *static_cast<HTMLSelectElement*>(impl());
38 
39     // we support both options index and options objects
40     HTMLElement* element = toHTMLElement(args.at(0));
41     if (element && element->hasTagName(optionTag))
42         select.remove(static_cast<HTMLOptionElement*>(element)->index());
43     else
44         select.remove(args.at(0).toInt32(exec));
45 
46     return jsUndefined();
47 }
48 
selectIndexSetter(HTMLSelectElement * select,JSC::ExecState * exec,unsigned index,JSC::JSValue value)49 void selectIndexSetter(HTMLSelectElement* select, JSC::ExecState* exec, unsigned index, JSC::JSValue value)
50 {
51     if (value.isUndefinedOrNull())
52         select->remove(index);
53     else {
54         ExceptionCode ec = 0;
55         HTMLOptionElement* option = toHTMLOptionElement(value);
56         if (!option)
57             ec = TYPE_MISMATCH_ERR;
58         else
59             select->setOption(index, option, ec);
60         setDOMException(exec, ec);
61     }
62 }
63 
indexSetter(JSC::ExecState * exec,unsigned index,JSC::JSValue value)64 void JSHTMLSelectElement::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value)
65 {
66     selectIndexSetter(static_cast<HTMLSelectElement*>(impl()), exec, index, value);
67 }
68 
69 }
70