void V8HTMLAllCollection::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (info.Length() < 1)
        return;

    HTMLAllCollection* impl = V8HTMLAllCollection::toImpl(info.Holder());
    Node& ownerNode = impl->ownerNode();

    UseCounter::countIfNotPrivateScript(info.GetIsolate(), ownerNode.document(), UseCounter::DocumentAllLegacyCall);

    if (info.Length() == 1) {
        v8SetReturnValue(info, getItem(impl, info[0], info));
        return;
    }

    // If there is a second argument it is the index of the item we want.
    TOSTRING_VOID(V8StringResource<>, name, info[0]);
    v8::Local<v8::Uint32> index;
    if (!info[1]->ToArrayIndex(info.GetIsolate()->GetCurrentContext()).ToLocal(&index))
        return;

    if (Node* node = impl->namedItemWithIndex(name, index->Value())) {
        v8SetReturnValueFast(info, node, impl);
        return;
    }
}
v8::Handle<v8::Value> V8HTMLAllCollection::callAsFunctionCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.HTMLAllCollection.callAsFunction()");
    if (args.Length() < 1)
        return v8::Undefined();

    HTMLAllCollection* imp = V8HTMLAllCollection::toNative(args.Holder());

    if (args.Length() == 1)
        return getItem(imp, args[0]);

    // If there is a second argument it is the index of the item we want.
    String name = toWebCoreString(args[0]);
    v8::Local<v8::Uint32> index = args[1]->ToArrayIndex();
    if (index.IsEmpty())
        return v8::Undefined();

    unsigned current = index->Uint32Value();
    Node* node = imp->namedItem(name);
    while (node) {
        if (!current)
            return toV8(node);

        node = imp->nextNamedItem(name);
        current--;
    }

    return v8::Undefined();
}
void V8HTMLAllCollection::legacyCallCustom(const v8::FunctionCallbackInfo<v8::Value>& info)
{
    if (info.Length() < 1)
        return;

    HTMLAllCollection* imp = V8HTMLAllCollection::toNative(info.Holder());
    Node* ownerNode = imp->ownerNode();
    ASSERT(ownerNode);

    UseCounter::count(ownerNode->document(), UseCounter::DocumentAllLegacyCall);

    if (info.Length() == 1) {
        v8SetReturnValue(info, getItem(imp, info[0], info));
        return;
    }

    // If there is a second argument it is the index of the item we want.
    V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, info[0]);
    v8::Local<v8::Uint32> index = info[1]->ToArrayIndex();
    if (index.IsEmpty())
        return;

    if (Node* node = imp->namedItemWithIndex(name, index->Uint32Value())) {
        v8SetReturnValueFast(info, node, imp);
        return;
    }
}
JSValue jsHTMLAllCollectionLength(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSHTMLAllCollection* castedThis = static_cast<JSHTMLAllCollection*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    HTMLAllCollection* imp = static_cast<HTMLAllCollection*>(castedThis->impl());
    JSValue result = jsNumber(imp->length());
    return result;
}
EncodedJSValue JSC_HOST_CALL jsHTMLAllCollectionPrototypeFunctionTags(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSHTMLAllCollection::s_info))
        return throwVMTypeError(exec);
    JSHTMLAllCollection* castedThis = static_cast<JSHTMLAllCollection*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSHTMLAllCollection::s_info);
    HTMLAllCollection* imp = static_cast<HTMLAllCollection*>(castedThis->impl());
    const String& name(ustringToString(exec->argument(0).toString(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());


    JSC::JSValue result = toJS(exec, castedThis->globalObject(), WTF::getPtr(imp->tags(name)));
    return JSValue::encode(result);
}
// HTMLAllCollections are strange objects, they support both get and call.
static EncodedJSValue JSC_HOST_CALL callHTMLAllCollection(ExecState* exec)
{
    if (exec->argumentCount() < 1)
        return JSValue::encode(jsUndefined());

    // Do not use thisObj here. It can be the JSHTMLDocument, in the document.forms(i) case.
    JSHTMLAllCollection* jsCollection = static_cast<JSHTMLAllCollection*>(exec->callee());
    HTMLAllCollection* collection = static_cast<HTMLAllCollection*>(jsCollection->impl());

    // Also, do we need the TypeError test here ?

    if (exec->argumentCount() == 1) {
        // Support for document.all(<index>) etc.
        bool ok;
        UString string = exec->argument(0).toString(exec);
        unsigned index = Identifier::toUInt32(string, ok);
        if (ok)
            return JSValue::encode(toJS(exec, jsCollection->globalObject(), collection->item(index)));

        // Support for document.images('<name>') etc.
        return JSValue::encode(getNamedItems(exec, jsCollection, Identifier(exec, string)));
    }

    // The second arg, if set, is the index of the item we want
    bool ok;
    UString string = exec->argument(0).toString(exec);
    unsigned index = Identifier::toUInt32(exec->argument(1).toString(exec), ok);
    if (ok) {
        AtomicString pstr = ustringToAtomicString(string);
        Node* node = collection->namedItem(pstr);
        while (node) {
            if (!index)
                return JSValue::encode(toJS(exec, jsCollection->globalObject(), node));
            node = collection->nextNamedItem(pstr);
            --index;
        }
    }

    return JSValue::encode(jsUndefined());
}