[whatwg] A question about the drawimage() canvas function

王铁套 wang.tietao at outlook.com
Tue Feb 5 22:45:53 PST 2013


Hi, there:
This is about the drawimage() canvas function in html5.
What should the following code ouput?
///////////////<html> <head>  <title>drawImage with an incorrect type for the image argument (part two)</title>  <style> canvas { display:none } </style>  <script>   window.onload = function(){    var r = document.getElementById('r');    ctx = document.getElementsByTagName('canvas')[0].getContext('2d');    var passed = false;    var message = "";    try{     ctx.drawImage((new Image()), 0, 0, 150, 150);     message = "No exception thrown"    }catch(e){      passed = e.code === e.INDEX_SIZE_ERR;      if (!passed) {message = "Got exception code " + e.code + " expected 1 (INDEX_SIZE_ERR)"}    }    r.textContent = passed ? "PASS" : "FAIL";    if (message) {r.textContent += " (" + message + ")"}   }  </script> </head> <body>  <p id="r">FAIL (Script did not run.)</p>  <canvas></canvas> </body></html>///////////////
In Chrome(24.0.1312.57) and Firefox(18.0.1), the output is:PASS
while in Opera(12.12) and IE(10.0.9200.16439) it is:FAIL (No exception thrown)

So, what should the result be? and what is the standard for this?
Thanks,-Tietao Wang 		 	   		  


More information about the whatwg mailing list