mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 19:33:18 +00:00
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:
parent
31576fc132
commit
d72c513fd0
@ -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));
|
||||
|
@ -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)
|
||||
|
51
content/html/content/test/test_bug593689.html
Normal file
51
content/html/content/test/test_bug593689.html
Normal 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>
|
Loading…
Reference in New Issue
Block a user