Chromium Code Reviews| Index: Source/core/html/HTMLSelectElement.cpp |
| diff --git a/Source/core/html/HTMLSelectElement.cpp b/Source/core/html/HTMLSelectElement.cpp |
| index a1305e285839e0d4f038c3507a3a0a1f5e45925e..1bef20c0c2f99d43711097921588c970112ad1e1 100644 |
| --- a/Source/core/html/HTMLSelectElement.cpp |
| +++ b/Source/core/html/HTMLSelectElement.cpp |
| @@ -51,6 +51,7 @@ |
| #include "core/html/HTMLOptionElement.h" |
| #include "core/html/forms/FormController.h" |
| #include "core/input/EventHandler.h" |
| +#include "core/inspector/ConsoleMessage.h" |
| #include "core/layout/HitTestRequest.h" |
| #include "core/layout/HitTestResult.h" |
| #include "core/layout/LayoutListBox.h" |
| @@ -467,8 +468,11 @@ HTMLOptionElement* HTMLSelectElement::item(unsigned index) |
| void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, ExceptionState& exceptionState) |
| { |
| - if (index > maxSelectItems - 1) |
| - index = maxSelectItems - 1; |
| + if (index >= length() && index >= maxSelectItems) { |
|
davve
2015/08/20 07:40:43
I like that you added the comparison to current le
tkent
2015/08/20 08:05:47
Yeah, I'll add this to the description.
Shrinking
|
| + document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, |
| + String::format("A request to update an option at index=%u is ignored. The maximum length is %u.", index, maxSelectItems))); |
|
keishi
2015/08/20 07:39:46
nit: Other messages seemed to be like "Failed to b
tkent
2015/08/20 08:05:47
will do.
|
| + return; |
| + } |
| int diff = index - length(); |
| HTMLOptionElementOrHTMLOptGroupElement element; |
| element.setHTMLOptionElement(option); |
| @@ -491,8 +495,11 @@ void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc |
| void HTMLSelectElement::setLength(unsigned newLen, ExceptionState& exceptionState) |
| { |
| - if (newLen > maxSelectItems) |
| + if (newLen > length() && newLen > maxSelectItems) { |
| + document().addConsoleMessage(ConsoleMessage::create(JSMessageSource, WarningMessageLevel, |
| + String::format("A request to update the option length to %u is ignored. The maximum length is %u.", newLen, maxSelectItems))); |
| return; |
| + } |
| int diff = length() - newLen; |
| if (diff < 0) { // Add dummy elements. |