Commit 37b9365e authored by vivek.vg@samsung.com's avatar vivek.vg@samsung.com

[bindings] Avoid using custom binding for HTMLOptionsCollection.length attribute

As per the specification, https://html.spec.whatwg.org/#the-htmloptionscollection-interface,
there is no exception throwing mechanism defined when negative values are passed. In such case
we should just ignore the values and avoid using the custom binding for such usage.

Trying to set any value greater than 10000 will be ignored with the existing
length unchanged.

BUG=345519

R=haraken@chromium.org

Review URL: https://codereview.chromium.org/1292653003

git-svn-id: svn://svn.chromium.org/blink/trunk@200819 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 4cfabd5e
1) setting length to a negative length
PASS mySelect.options.length = -1; threw exception IndexSizeError: Failed to set the 'length' property on 'HTMLOptionsCollection': The value provided (-1) is negative. Lengths must be greater than or equal to 0..
PASS mySelect.options.length is 2
PASS mySelect.selectedIndex is 1
2) setting length to a larger length
......@@ -73,6 +72,9 @@ PASS mySelect.selectedIndex is -1
PASS mySelect.options.add({}) threw exception TypeError: Failed to execute 'add' on 'HTMLOptionsCollection': The provided value is not of type '(HTMLOptionElement or HTMLOptGroupElement)'.
PASS mySelect.options.length is 10
PASS mySelect.selectedIndex is -1
24) setting length to a value greater than 10000
PASS mySelect.options.length is 10
PASS mySelect.selectedIndex is -1
PASS successfullyParsed is true
......
1) setting length to a negative length
PASS mySelect.options.length = -1; threw exception IndexSizeError: Failed to set the 'length' property on 'HTMLOptionsCollection': The value provided (-1) is negative. Lengths must be greater than or equal to 0..
PASS mySelect.options.length is 2
PASS mySelect.selectedIndex is 0
2) setting length to a larger length
......@@ -69,6 +68,9 @@ PASS mySelect.selectedIndex is 0
22) trying to set a option element using an invalid index: positive infinity
PASS mySelect.options.length is 10
PASS mySelect.selectedIndex is 0
23) setting length to a value greater than 10000
PASS mySelect.options.length is 10
PASS mySelect.selectedIndex is 0
PASS successfullyParsed is true
......
......@@ -14,7 +14,7 @@ reset(mySelect);
var i = 0;
debug((++i) + ") setting length to a negative length");
shouldThrow("mySelect.options.length = -1;");
mySelect.options.length = -1;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "0");
......@@ -137,5 +137,10 @@ mySelect.options[1/0] = document.createElement("option");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug((++i) + ") setting length to a value greater than 10000");
mySelect.options.length = 10001;
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "0");
debug("");
</script>
......@@ -14,7 +14,7 @@ reset(mySelect);
var i = 0;
debug((++i) + ") setting length to a negative length");
shouldThrow("mySelect.options.length = -1;");
mySelect.options.length = -1;
shouldBe("mySelect.options.length", "2");
shouldBe("mySelect.selectedIndex", "1");
......@@ -142,5 +142,10 @@ shouldThrow("mySelect.options.add({})");
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "-1");
debug((++i) + ") setting length to a value greater than 10000");
mySelect.options.length = 10001;
shouldBe("mySelect.options.length", "10");
shouldBe("mySelect.selectedIndex", "-1");
debug("");
</script>
......@@ -2,9 +2,9 @@ This test that setting HTMLSelectElement.length is capped to 10,000, but that yo
Select length is 0
Trying: - sel.length = 20000;
Select length is 10000
Select length is 0
Trying: - sel.add(new Option, 0);
Select length is 10001
Select length is 1
Trying: - sel.length = 0;
Select length is 0
/*
* Copyright (C) 2009 Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following disclaimer
* in the documentation and/or other materials provided with the
* distribution.
* * Neither the name of Google Inc. nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "bindings/core/v8/V8HTMLOptionsCollection.h"
#include "bindings/core/v8/ExceptionState.h"
#include "bindings/core/v8/V8Binding.h"
#include "bindings/core/v8/V8HTMLOptionElement.h"
#include "bindings/core/v8/V8Node.h"
#include "bindings/core/v8/V8NodeList.h"
#include "core/dom/ExceptionCode.h"
#include "core/html/HTMLOptionElement.h"
#include "core/html/HTMLOptionsCollection.h"
#include "core/html/HTMLSelectElement.h"
namespace blink {
void V8HTMLOptionsCollection::lengthAttributeSetterCustom(v8::Local<v8::Value> value, const v8::FunctionCallbackInfo<v8::Value>& info)
{
HTMLOptionsCollection* impl = V8HTMLOptionsCollection::toImpl(info.Holder());
unsigned newLength = 0;
double currentLength;
if (!v8Call(value->NumberValue(info.GetIsolate()->GetCurrentContext()), currentLength))
return;
ExceptionState exceptionState(ExceptionState::SetterContext, "length", "HTMLOptionsCollection", info.Holder(), info.GetIsolate());
if (!std::isnan(currentLength) && !std::isinf(currentLength)) {
if (currentLength < 0.0)
exceptionState.throwDOMException(IndexSizeError, "The value provided (" + String::number(currentLength) + ") is negative. Lengths must be greater than or equal to 0.");
else if (currentLength > static_cast<double>(UINT_MAX))
newLength = UINT_MAX;
else
newLength = static_cast<unsigned>(currentLength);
}
if (exceptionState.throwIfNeeded())
return;
impl->setLength(newLength, exceptionState);
}
} // namespace blink
......@@ -14,7 +14,6 @@
'V8ErrorEventCustom.cpp',
'V8EventTargetCustom.cpp',
'V8HTMLAllCollectionCustom.cpp',
'V8HTMLOptionsCollectionCustom.cpp',
'V8HTMLPlugInElementCustom.cpp',
'V8InjectedScriptManager.cpp',
'V8MediaQueryListCustom.cpp',
......
......@@ -26,7 +26,7 @@
SetWrapperReferenceFrom=ownerNode,
] interface HTMLOptionsCollection : HTMLCollection {
// inherits item()
[Custom=Setter, RaisesException=Setter] attribute unsigned long length; // shadows inherited length
[RaisesException=Setter] attribute unsigned long length; // shadows inherited length
// FIXME: The spec has a legacycaller HTMLOptionElement? (DOMString name);
[RaisesException, TypeChecking=Interface] setter void (unsigned long index, HTMLOptionElement? option);
[RaisesException, TypeChecking=Interface] void add((HTMLOptionElement or HTMLOptGroupElement) element, optional (HTMLElement or long)? before = null);
......
......@@ -492,7 +492,7 @@ void HTMLSelectElement::setOption(unsigned index, HTMLOptionElement* option, Exc
void HTMLSelectElement::setLength(unsigned newLen, ExceptionState& exceptionState)
{
if (newLen > maxSelectItems)
newLen = maxSelectItems;
return;
int diff = length() - newLen;
if (diff < 0) { // Add dummy elements.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment