Bug 593689. Convert arguments to new Image() to integers the way other conversions to integer happen. r=jst a=jst

This commit is contained in:
Boris Zbarsky 2010-09-09 01:38:10 -04:00
parent 5276057293
commit 1bbc3ac123
3 changed files with 56 additions and 4 deletions

View File

@ -601,16 +601,16 @@ nsHTMLImageElement::Initialize(nsISupports* aOwner, JSContext* aContext,
}
// The first (optional) argument is the width of the image
int32 width;
JSBool ret = JS_ValueToInt32(aContext, argv[0], &width);
uint32 width;
JSBool ret = JS_ValueToECMAUint32(aContext, argv[0], &width);
NS_ENSURE_TRUE(ret, NS_ERROR_INVALID_ARG);
nsresult rv = SetIntAttr(nsGkAtoms::width, static_cast<PRInt32>(width));
if (NS_SUCCEEDED(rv) && (argc > 1)) {
// The second (optional) argument is the height of the image
int32 height;
ret = JS_ValueToInt32(aContext, argv[1], &height);
uint32 height;
ret = JS_ValueToECMAUint32(aContext, argv[1], &height);
NS_ENSURE_TRUE(ret, NS_ERROR_INVALID_ARG);
rv = SetIntAttr(nsGkAtoms::height, static_cast<PRInt32>(height));

View File

@ -211,6 +211,7 @@ _TEST_FILES = \
test_bug588683-4.html \
test_bug590353-1.html \
test_bug590353-2.html \
test_bug593689.html \
$(NULL)
libs:: $(_TEST_FILES)

View File

@ -0,0 +1,51 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=593689
-->
<head>
<title>Test for Bug 593689</title>
<script type="application/javascript" src="/MochiKit/packed.js"></script>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=593689">Mozilla Bug 593689</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script type="application/javascript">
/** Test for Bug 593689 **/
function testWidth(w) {
var img = new Image(w);
is(img.width, w|0, "Unexpected handling of '" + w + "' width");
}
testWidth(1);
testWidth(0);
testWidth("xxx");
testWidth(null);
testWidth(undefined);
testWidth({});
testWidth({ valueOf: function() { return 10; } });
function testHeight(h) {
var img = new Image(100, h);
is(img.height, h|0, "Unexpected handling of '" + h + "' height");
}
testHeight(1);
testHeight(0);
testHeight("xxx");
testHeight(null);
testHeight(undefined);
testHeight({});
testHeight({ valueOf: function() { return 10; } });
</script>
</pre>
</body>
</html>