void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index, ExceptionState& exceptionState) { HTMLOptionElement* newOption = element.get(); if (!newOption) { exceptionState.throwTypeError("The element provided was not an HTMLOptionElement."); return; } if (index < -1) { exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is less than -1."); return; } HTMLSelectElement* select = toHTMLSelectElement(ownerNode()); if (index == -1 || unsigned(index) >= length()) select->add(newOption, 0, exceptionState); else select->add(newOption, toHTMLOptionElement(item(index)), exceptionState); ASSERT(!exceptionState.hadException()); }
void HTMLOptionsCollection::add(PassRefPtr<HTMLOptionElement> element, int index, ExceptionCode &ec) { HTMLOptionElement* newOption = element.get(); if (!newOption) { ec = TYPE_MISMATCH_ERR; return; } if (index < -1) { ec = INDEX_SIZE_ERR; return; } ec = 0; HTMLSelectElement* select = static_cast<HTMLSelectElement*>(m_base.get()); if (index == -1 || unsigned(index) >= length()) select->add(newOption, 0, ec); else select->add(newOption, static_cast<HTMLOptionElement*>(item(index)), ec); ASSERT(ec == 0); }
static v8::Handle<v8::Value> addCallback(const v8::Arguments& args) { INC_STATS("DOM.HTMLSelectElement.add"); HTMLSelectElement* imp = V8HTMLSelectElement::toNative(args.Holder()); ExceptionCode ec = 0; { EXCEPTION_BLOCK(HTMLElement*, element, V8HTMLElement::HasInstance(args[0]) ? V8HTMLElement::toNative(v8::Handle<v8::Object>::Cast(args[0])) : 0); EXCEPTION_BLOCK(HTMLElement*, before, V8HTMLElement::HasInstance(args[1]) ? V8HTMLElement::toNative(v8::Handle<v8::Object>::Cast(args[1])) : 0); imp->add(element, before, ec); if (UNLIKELY(ec)) goto fail; return v8::Handle<v8::Value>(); } fail: V8Proxy::setDOMException(ec); return v8::Handle<v8::Value>(); }
EncodedJSValue JSC_HOST_CALL jsHTMLSelectElementPrototypeFunctionAdd(ExecState* exec) { JSValue thisValue = exec->hostThisValue(); if (!thisValue.inherits(&JSHTMLSelectElement::s_info)) return throwVMTypeError(exec); JSHTMLSelectElement* castedThis = static_cast<JSHTMLSelectElement*>(asObject(thisValue)); HTMLSelectElement* imp = static_cast<HTMLSelectElement*>(castedThis->impl()); ExceptionCode ec = 0; HTMLElement* element(toHTMLElement(exec->argument(0))); if (exec->hadException()) return JSValue::encode(jsUndefined()); HTMLElement* before(toHTMLElement(exec->argument(1))); if (exec->hadException()) return JSValue::encode(jsUndefined()); imp->add(element, before, ec); setDOMException(exec, ec); return JSValue::encode(jsUndefined()); }