Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(70)

Side by Side Diff: Source/bindings/v8/custom/V8HTMLOptionsCollectionCustom.cpp

Issue 121113004: Improve handling of failed integer type conversions. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Rebase Created 6 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 #include "config.h" 31 #include "config.h"
32 #include "V8HTMLOptionsCollection.h" 32 #include "V8HTMLOptionsCollection.h"
33 33
34 #include "V8HTMLOptionElement.h" 34 #include "V8HTMLOptionElement.h"
35 #include "V8Node.h" 35 #include "V8Node.h"
36 #include "V8NodeList.h" 36 #include "V8NodeList.h"
37 #include "bindings/v8/ExceptionMessages.h"
38 #include "bindings/v8/ExceptionState.h" 37 #include "bindings/v8/ExceptionState.h"
39 #include "bindings/v8/V8Binding.h" 38 #include "bindings/v8/V8Binding.h"
40 #include "core/dom/ExceptionCode.h" 39 #include "core/dom/ExceptionCode.h"
41 #include "core/dom/NamedNodesCollection.h" 40 #include "core/dom/NamedNodesCollection.h"
42 #include "core/html/HTMLOptionElement.h" 41 #include "core/html/HTMLOptionElement.h"
43 #include "core/html/HTMLOptionsCollection.h" 42 #include "core/html/HTMLOptionsCollection.h"
44 #include "core/html/HTMLSelectElement.h" 43 #include "core/html/HTMLSelectElement.h"
45 44
46 namespace WebCore { 45 namespace WebCore {
47 46
(...skipping 28 matching lines...) Expand all
76 ExceptionState exceptionState(ExceptionState::ExecutionContext, "add", "HTML OptionsCollection", info.Holder(), info.GetIsolate()); 75 ExceptionState exceptionState(ExceptionState::ExecutionContext, "add", "HTML OptionsCollection", info.Holder(), info.GetIsolate());
77 if (!V8HTMLOptionElement::hasInstance(info[0], info.GetIsolate(), worldType( info.GetIsolate()))) { 76 if (!V8HTMLOptionElement::hasInstance(info[0], info.GetIsolate(), worldType( info.GetIsolate()))) {
78 exceptionState.throwTypeError("The element provided was not an HTMLOptio nElement."); 77 exceptionState.throwTypeError("The element provided was not an HTMLOptio nElement.");
79 } else { 78 } else {
80 HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Hold er()); 79 HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Hold er());
81 HTMLOptionElement* option = V8HTMLOptionElement::toNative(v8::Handle<v8: :Object>(v8::Handle<v8::Object>::Cast(info[0]))); 80 HTMLOptionElement* option = V8HTMLOptionElement::toNative(v8::Handle<v8: :Object>(v8::Handle<v8::Object>::Cast(info[0])));
82 81
83 if (info.Length() < 2) { 82 if (info.Length() < 2) {
84 imp->add(option, exceptionState); 83 imp->add(option, exceptionState);
85 } else { 84 } else {
86 bool ok; 85 int index = toInt32(info[1], exceptionState);
87 V8TRYCATCH_VOID(int, index, toInt32(info[1], ok)); 86 if (exceptionState.throwIfNeeded())
88 if (!ok) 87 return;
89 exceptionState.throwTypeError("The index provided could not be i nterpreted as an integer."); 88
90 else 89 imp->add(option, index, exceptionState);
91 imp->add(option, index, exceptionState);
92 } 90 }
93 } 91 }
94 92
95 exceptionState.throwIfNeeded(); 93 exceptionState.throwIfNeeded();
96 } 94 }
97 95
98 void V8HTMLOptionsCollection::lengthAttributeSetterCustom(v8::Local<v8::Value> v alue, const v8::PropertyCallbackInfo<void>& info) 96 void V8HTMLOptionsCollection::lengthAttributeSetterCustom(v8::Local<v8::Value> v alue, const v8::PropertyCallbackInfo<void>& info)
99 { 97 {
100 HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Holder() ); 98 HTMLOptionsCollection* imp = V8HTMLOptionsCollection::toNative(info.Holder() );
101 double v = value->NumberValue(); 99 double v = value->NumberValue();
102 unsigned newLength = 0; 100 unsigned newLength = 0;
103 ExceptionState exceptionState(ExceptionState::SetterContext, "length", "HTML OptionsCollection", info.Holder(), info.GetIsolate()); 101 ExceptionState exceptionState(ExceptionState::SetterContext, "length", "HTML OptionsCollection", info.Holder(), info.GetIsolate());
104 if (!std::isnan(v) && !std::isinf(v)) { 102 if (!std::isnan(v) && !std::isinf(v)) {
105 if (v < 0.0) 103 if (v < 0.0)
106 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(v) + ") is negative. Lengths must be greater than or equal to 0."); 104 exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(v) + ") is negative. Lengths must be greater than or equal to 0.");
107 else if (v > static_cast<double>(UINT_MAX)) 105 else if (v > static_cast<double>(UINT_MAX))
108 newLength = UINT_MAX; 106 newLength = UINT_MAX;
109 else 107 else
110 newLength = static_cast<unsigned>(v); 108 newLength = static_cast<unsigned>(v);
111 } 109 }
112 110
113 if (exceptionState.throwIfNeeded()) 111 if (exceptionState.throwIfNeeded())
114 return; 112 return;
115 113
116 imp->setLength(newLength, exceptionState); 114 imp->setLength(newLength, exceptionState);
117 } 115 }
118 116
119 } // namespace WebCore 117 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/bindings/v8/custom/V8BiquadFilterNodeCustom.cpp ('k') | Source/bindings/v8/custom/V8OscillatorNodeCustom.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698