diff options
Diffstat (limited to 'Source/WebCore/bindings/js/JSHTMLFormControlsCollectionCustom.cpp')
-rw-r--r-- | Source/WebCore/bindings/js/JSHTMLFormControlsCollectionCustom.cpp | 49 |
1 files changed, 23 insertions, 26 deletions
diff --git a/Source/WebCore/bindings/js/JSHTMLFormControlsCollectionCustom.cpp b/Source/WebCore/bindings/js/JSHTMLFormControlsCollectionCustom.cpp index fc41eb61a..58d9b676b 100644 --- a/Source/WebCore/bindings/js/JSHTMLFormControlsCollectionCustom.cpp +++ b/Source/WebCore/bindings/js/JSHTMLFormControlsCollectionCustom.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2007-2008, 2016 Apple Inc. All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -18,54 +18,51 @@ */ #include "config.h" -#include "HTMLFormControlsCollection.h" - - -#include "HTMLAllCollection.h" -#include "JSDOMBinding.h" -#include "JSHTMLCollection.h" #include "JSHTMLFormControlsCollection.h" + +#include "HTMLFormControlsCollection.h" #include "JSNode.h" -#include "JSNodeList.h" #include "JSRadioNodeList.h" -#include "Node.h" #include "RadioNodeList.h" -#include <wtf/Vector.h> -#include <wtf/text/AtomicString.h> +#include <runtime/IdentifierInlines.h> using namespace JSC; namespace WebCore { -static JSValue getNamedItems(ExecState* exec, JSHTMLFormControlsCollection* collection, PropertyName propertyName) +static JSValue namedItems(ExecState& state, JSHTMLFormControlsCollection* collection, PropertyName propertyName) { - Vector<Ref<Element>> namedItems; const AtomicString& name = propertyNameToAtomicString(propertyName); - collection->impl().namedItems(name, namedItems); + Vector<Ref<Element>> namedItems = collection->wrapped().namedItems(name); if (namedItems.isEmpty()) return jsUndefined(); if (namedItems.size() == 1) - return toJS(exec, collection->globalObject(), &namedItems[0].get()); + return toJS(&state, collection->globalObject(), namedItems[0]); - ASSERT(collection->impl().type() == FormControls); - return toJS(exec, collection->globalObject(), collection->impl().ownerNode().radioNodeList(name).get()); + ASSERT(collection->wrapped().type() == FormControls); + return toJS(&state, collection->globalObject(), collection->wrapped().ownerNode().radioNodeList(name).get()); } -bool JSHTMLFormControlsCollection::canGetItemsForName(ExecState*, HTMLFormControlsCollection* collection, PropertyName propertyName) +bool JSHTMLFormControlsCollection::nameGetter(ExecState* state, PropertyName propertyName, JSValue& value) { - return collection->hasNamedItem(propertyNameToAtomicString(propertyName)); -} + auto items = namedItems(*state, this, propertyName); + if (items.isUndefined()) + return false; -EncodedJSValue JSHTMLFormControlsCollection::nameGetter(ExecState* exec, EncodedJSValue slotBase, EncodedJSValue, PropertyName propertyName) -{ - JSHTMLFormControlsCollection* thisObj = jsCast<JSHTMLFormControlsCollection*>(JSValue::decode(slotBase)); - return JSValue::encode(getNamedItems(exec, thisObj, propertyName)); + value = items; + return true; } -JSValue JSHTMLFormControlsCollection::namedItem(ExecState* exec) +JSValue JSHTMLFormControlsCollection::namedItem(ExecState& state) { - JSValue value = getNamedItems(exec, this, Identifier(exec, exec->argument(0).toString(exec)->value(exec))); + VM& vm = state.vm(); + auto scope = DECLARE_THROW_SCOPE(vm); + + if (UNLIKELY(state.argumentCount() < 1)) + return throwException(&state, scope, createNotEnoughArgumentsError(&state)); + + JSValue value = namedItems(state, this, Identifier::fromString(&state, state.uncheckedArgument(0).toWTFString(&state))); return value.isUndefined() ? jsNull() : value; } |