JSHTMLFormControlsCollectionCustom.cpp [plain text]
#include "config.h"
#include "JSHTMLFormControlsCollection.h"
#include "HTMLFormControlsCollection.h"
#include "JSNode.h"
#include "JSRadioNodeList.h"
#include "RadioNodeList.h"
#include <runtime/IdentifierInlines.h>
using namespace JSC;
namespace WebCore {
static JSValue namedItems(ExecState& state, JSHTMLFormControlsCollection* collection, PropertyName propertyName)
{
const AtomicString& name = propertyNameToAtomicString(propertyName);
Vector<Ref<Element>> namedItems = collection->wrapped().namedItems(name);
if (namedItems.isEmpty())
return jsUndefined();
if (namedItems.size() == 1)
return toJS(&state, collection->globalObject(), namedItems[0]);
ASSERT(collection->wrapped().type() == FormControls);
return toJS(&state, collection->globalObject(), collection->wrapped().ownerNode().radioNodeList(name).get());
}
bool JSHTMLFormControlsCollection::nameGetter(ExecState* state, PropertyName propertyName, JSValue& value)
{
auto items = namedItems(*state, this, propertyName);
if (items.isUndefined())
return false;
value = items;
return true;
}
JSValue JSHTMLFormControlsCollection::namedItem(ExecState& state)
{
JSValue value = namedItems(state, this, Identifier::fromString(&state, state.argument(0).toString(&state)->value(&state)));
return value.isUndefined() ? jsNull() : value;
}
}