~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2006 Apple Computer, Inc.
 
3
 *
 
4
 * This library is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU Library General Public
 
6
 * License as published by the Free Software Foundation; either
 
7
 * version 2 of the License, or (at your option) any later version.
 
8
 *
 
9
 * This library is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
12
 * Library General Public License for more details.
 
13
 *
 
14
 * You should have received a copy of the GNU Library General Public License
 
15
 * along with this library; see the file COPYING.LIB.  If not, write to
 
16
 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 
17
 * Boston, MA 02111-1307, USA.
 
18
 */
 
19
 
 
20
#include "config.h"
 
21
#include "JSHTMLOptionsCollection.h"
 
22
 
 
23
#include "ExceptionCode.h"
 
24
#include "HTMLNames.h"
 
25
#include "HTMLOptionElement.h"
 
26
#include "HTMLOptionsCollection.h"
 
27
#include "HTMLSelectElement.h"
 
28
#include "JSHTMLOptionElement.h"
 
29
#include "JSHTMLSelectElementCustom.h"
 
30
 
 
31
#include <kjs/operations.h>
 
32
 
 
33
using namespace KJS;
 
34
 
 
35
namespace WebCore {
 
36
 
 
37
JSValue* JSHTMLOptionsCollection::length(ExecState* exec) const
 
38
{
 
39
    HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
 
40
    return jsNumber(imp->length());
 
41
}
 
42
 
 
43
void JSHTMLOptionsCollection::setLength(ExecState* exec, JSValue* value)
 
44
{
 
45
    HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
 
46
    ExceptionCode ec = 0;
 
47
    unsigned newLength = 0;
 
48
    double lengthValue = value->getNumber();
 
49
    if (!isNaN(lengthValue) && !isInf(lengthValue)) {
 
50
        if (lengthValue < 0.0)
 
51
            ec = INDEX_SIZE_ERR;
 
52
        else if (lengthValue > static_cast<double>(UINT_MAX))
 
53
            newLength = UINT_MAX;
 
54
        else
 
55
            newLength = static_cast<unsigned>(lengthValue);
 
56
    }
 
57
    if (!ec)
 
58
        imp->setLength(newLength, ec);
 
59
    setDOMException(exec, ec);
 
60
}
 
61
 
 
62
void JSHTMLOptionsCollection::indexSetter(KJS::ExecState* exec, unsigned index, KJS::JSValue* value, int attr)
 
63
{
 
64
    HTMLOptionsCollection* imp = static_cast<HTMLOptionsCollection*>(impl());
 
65
    HTMLSelectElement* base = static_cast<HTMLSelectElement*>(imp->base());
 
66
    selectIndexSetter(base, exec, index, value);
 
67
}
 
68
 
 
69
}