V8HTMLOptionElementConstructor.cpp [plain text]
#include "config.h"
#include "HTMLOptionElement.h"
#include "Document.h"
#include "Frame.h"
#include "HTMLNames.h"
#include "Text.h"
#include "V8Binding.h"
#include "V8Proxy.h"
#include <wtf/RefPtr.h>
namespace WebCore {
CALLBACK_FUNC_DECL(HTMLOptionElementConstructor)
{
INC_STATS("DOM.HTMLOptionElement.Contructor");
if (!args.IsConstructCall())
return throwError("DOM object constructor cannot be called as a function.");
Document* document = V8Proxy::retrieveFrame()->document();
if (!document)
return throwError("Option constructor associated document is unavailable", V8Proxy::ReferenceError);
RefPtr<HTMLOptionElement> option = new HTMLOptionElement(HTMLNames::optionTag, V8Proxy::retrieveFrame()->document());
ExceptionCode ec = 0;
RefPtr<Text> text = document->createTextNode("");
if (args.Length() > 0) {
if (!args[0]->IsUndefined()) {
text->setData(toWebCoreString(args[0]), ec);
if (ec)
throwError(ec);
}
option->appendChild(text.release(), ec);
if (ec)
throwError(ec);
if (args.Length() > 1) {
if (!args[1]->IsUndefined())
option->setValue(toWebCoreString(args[1]));
if (args.Length() > 2) {
option->setDefaultSelected(args[2]->BooleanValue());
if (args.Length() > 3)
option->setSelected(args[3]->BooleanValue());
}
}
}
V8DOMWrapper::setDOMWrapper(args.Holder(), V8ClassIndex::ToInt(V8ClassIndex::NODE), option.get());
option->ref();
V8DOMWrapper::setJSWrapperForDOMNode(option.get(), v8::Persistent<v8::Object>::New(args.Holder()));
return args.Holder();
}
}