1/* 2 * Copyright (C) 2007, 2010 Apple Inc. All rights reserved. 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 30namespace WebCore { 31 32using namespace JSC; 33using namespace HTMLNames; 34 35JSValue JSHTMLSelectElement::remove(ExecState* exec) 36{ 37 HTMLSelectElement& select = impl(); 38 39 if (!exec->argumentCount()) { 40 // When called with no argument, we should call Element::remove() to detach. 41 ExceptionCode ec = 0; 42 select.remove(ec); 43 setDOMException(exec, ec); 44 } else { 45 // The HTMLSelectElement::remove() function can take either an option object or the index of an option. 46 if (HTMLOptionElement* option = toHTMLOptionElement(exec->argument(0))) 47 select.remove(option); 48 else 49 select.removeByIndex(exec->argument(0).toInt32(exec)); 50 } 51 52 return jsUndefined(); 53} 54 55void selectIndexSetter(HTMLSelectElement* select, JSC::ExecState* exec, unsigned index, JSC::JSValue value) 56{ 57 if (value.isUndefinedOrNull()) 58 select->removeByIndex(index); 59 else { 60 ExceptionCode ec = 0; 61 HTMLOptionElement* option = toHTMLOptionElement(value); 62 if (!option) 63 ec = TYPE_MISMATCH_ERR; 64 else 65 select->setOption(index, option, ec); 66 setDOMException(exec, ec); 67 } 68} 69 70void JSHTMLSelectElement::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value) 71{ 72 selectIndexSetter(&impl(), exec, index, value); 73} 74 75} 76