2 * Copyright (C) 2009 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include "HTMLOptionsCollection.h"
34 #include "HTMLOptionElement.h"
35 #include "HTMLSelectElement.h"
36 #include "ExceptionCode.h"
38 #include "V8Binding.h"
39 #include "V8CustomBinding.h"
40 #include "V8HTMLOptionElement.h"
41 #include "V8HTMLSelectElementCustom.h"
46 CALLBACK_FUNC_DECL(HTMLOptionsCollectionRemove)
48 INC_STATS("DOM.HTMLOptionsCollection.remove()");
49 HTMLOptionsCollection* imp = V8Proxy::ToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, args.Holder());
50 HTMLSelectElement* base = static_cast<HTMLSelectElement*>(imp->base());
51 return removeElement(base, args);
54 CALLBACK_FUNC_DECL(HTMLOptionsCollectionAdd)
56 INC_STATS("DOM.HTMLOptionsCollection.add()");
57 if (!V8HTMLOptionElement::HasInstance(args[0])) {
58 V8Proxy::SetDOMException(TYPE_MISMATCH_ERR);
59 return v8::Undefined();
61 HTMLOptionsCollection* imp = V8Proxy::ToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, args.Holder());
62 HTMLOptionElement* option = V8Proxy::DOMWrapperToNode<HTMLOptionElement>(args[0]);
65 if (args.Length() < 2)
69 v8::TryCatch try_catch;
70 int index = ToInt32(args[1], ok);
72 if (try_catch.HasCaught())
73 return v8::Undefined();
76 ec = TYPE_MISMATCH_ERR;
78 imp->add(option, index, ec);
82 V8Proxy::SetDOMException(ec);
84 return v8::Undefined();
87 ACCESSOR_GETTER(HTMLOptionsCollectionLength)
89 INC_STATS("DOM.HTMLOptionsCollection.length._get");
90 HTMLOptionsCollection* imp = V8Proxy::ToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, info.Holder());
91 int v = imp->length();
92 return v8::Integer::New(v);
95 ACCESSOR_SETTER(HTMLOptionsCollectionLength)
97 INC_STATS("DOM.HTMLOptionsCollection.length._set");
98 HTMLOptionsCollection* imp = V8Proxy::ToNativeObject<HTMLOptionsCollection>(V8ClassIndex::HTMLOPTIONSCOLLECTION, info.Holder());
99 double v = value->NumberValue();
100 unsigned newLength = 0;
101 ExceptionCode ec = 0;
102 if (!isnan(v) && !isinf(v)) {
105 else if (v > static_cast<double>(UINT_MAX))
106 newLength = UINT_MAX;
108 newLength = static_cast<unsigned>(v);
111 imp->setLength(value->Uint32Value(), ec);
113 V8Proxy::SetDOMException(ec);
116 } // namespace WebCore