OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2009 Google Inc. All rights reserved. | 2 * Copyright (C) 2009 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 26 matching lines...) Expand all Loading... |
37 #include "bindings/v8/ExceptionState.h" | 37 #include "bindings/v8/ExceptionState.h" |
38 #include "bindings/v8/V8Binding.h" | 38 #include "bindings/v8/V8Binding.h" |
39 #include "core/dom/ExceptionCode.h" | 39 #include "core/dom/ExceptionCode.h" |
40 #include "core/dom/NamedNodesCollection.h" | 40 #include "core/dom/NamedNodesCollection.h" |
41 #include "core/html/HTMLOptionElement.h" | 41 #include "core/html/HTMLOptionElement.h" |
42 #include "core/html/HTMLOptionsCollection.h" | 42 #include "core/html/HTMLOptionsCollection.h" |
43 #include "core/html/HTMLSelectElement.h" | 43 #include "core/html/HTMLSelectElement.h" |
44 | 44 |
45 namespace WebCore { | 45 namespace WebCore { |
46 | 46 |
47 template<typename CallbackInfo> | |
48 static void getNamedItems(HTMLOptionsCollection* collection, const AtomicString&
name, const CallbackInfo& info) | |
49 { | |
50 Vector<RefPtr<Element> > namedItems; | |
51 collection->namedItems(name, namedItems); | |
52 | |
53 if (!namedItems.size()) { | |
54 v8SetReturnValueNull(info); | |
55 return; | |
56 } | |
57 | |
58 if (namedItems.size() == 1) { | |
59 v8SetReturnValueFast(info, namedItems.at(0).release(), collection); | |
60 return; | |
61 } | |
62 | |
63 v8SetReturnValueFast(info, NamedNodesCollection::create(namedItems), collect
ion); | |
64 } | |
65 | |
66 void V8HTMLOptionsCollection::namedItemMethodCustom(const v8::FunctionCallbackIn
fo<v8::Value>& info) | |
67 { | |
68 V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource<>, name, info[0]); | |
69 HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Holder()
); | |
70 getNamedItems(imp, name, info); | |
71 } | |
72 | |
73 void V8HTMLOptionsCollection::addMethodCustom(const v8::FunctionCallbackInfo<v8:
:Value>& info) | 47 void V8HTMLOptionsCollection::addMethodCustom(const v8::FunctionCallbackInfo<v8:
:Value>& info) |
74 { | 48 { |
75 ExceptionState exceptionState(ExceptionState::ExecutionContext, "add", "HTML
OptionsCollection", info.Holder(), info.GetIsolate()); | 49 ExceptionState exceptionState(ExceptionState::ExecutionContext, "add", "HTML
OptionsCollection", info.Holder(), info.GetIsolate()); |
76 if (!V8HTMLOptionElement::hasInstance(info[0], info.GetIsolate())) { | 50 if (!V8HTMLOptionElement::hasInstance(info[0], info.GetIsolate())) { |
77 exceptionState.throwTypeError("The element provided was not an HTMLOptio
nElement."); | 51 exceptionState.throwTypeError("The element provided was not an HTMLOptio
nElement."); |
78 } else { | 52 } else { |
79 HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Hold
er()); | 53 HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Hold
er()); |
80 HTMLOptionElement* option = V8HTMLOptionElement::toNative(v8::Handle<v8:
:Object>(v8::Handle<v8::Object>::Cast(info[0]))); | 54 HTMLOptionElement* option = V8HTMLOptionElement::toNative(v8::Handle<v8:
:Object>(v8::Handle<v8::Object>::Cast(info[0]))); |
81 | 55 |
82 if (info.Length() < 2) { | 56 if (info.Length() < 2) { |
(...skipping 25 matching lines...) Expand all Loading... |
108 newLength = static_cast<unsigned>(v); | 82 newLength = static_cast<unsigned>(v); |
109 } | 83 } |
110 | 84 |
111 if (exceptionState.throwIfNeeded()) | 85 if (exceptionState.throwIfNeeded()) |
112 return; | 86 return; |
113 | 87 |
114 imp->setLength(newLength, exceptionState); | 88 imp->setLength(newLength, exceptionState); |
115 } | 89 } |
116 | 90 |
117 } // namespace WebCore | 91 } // namespace WebCore |
OLD | NEW |