Re: Need reviewers for Cameron's Web IDL tests

On 9/17/13, Arthur Barstow <art.barstow@nokia.com> wrote:
> [ Bcc public-webapps ]
>
> Hi All,
>
> Last month, Cameron submitted over 125 test files for Web IDL (Thanks
> very much Cameron!). The tests are in [PR-271] with a http mirror at
> [Mirror-271].
>
https://github.com/heycam/web-platform-tests/commit/0bab1a9d37cb20123ef90bac82e2c43a1ad8a484

Nit: This line is too long. Formatting to shorter line length would
make them easier to read.

Instead of:-
| new iframe.contentWindow.Image({ toString: function() { return { }
}, value: function() { return { } } });

Extract the outerObject to a "setup" variable that can be reused, as
you've put the iframe assignment at the top:-

| var iframe = document.getElementById("iframe");
| var outerObj = {
|    toString: function() { return { } ; },
|    value: function() { return { } ;}
| };


You pass in an object to the iframe window's Image constructor, where
DefaultValue results in a TypeError.

The test should document some of what is going on.

The HTML5 Image constructor expects an unsigned long, so the argument
must be converted into a number.
http://www.w3.org/TR/2011/WD-html5-20110525/embedded-content-1.html#htmlimageelement

WebIDL specifies calling toNumber on the input:
http://www.w3.org/TR/WebIDL/#es-unsigned-long

That goes to ES5 ToNumber:-
(WebIDL links to http://es5.github.io/#x9.3 but should instead link to
http://www.ecma-international.org/ecma-262/5.1/#sec-9.3

Which tries to convert the number ToPrimitive:-
http://www.ecma-international.org/ecma-262/5.1/#sec-9.1

| Return a default value for the Object. The default value
| of an object is retrieved by calling the [[DefaultValue]]
| internal method of the object, passing the optional hint
| PreferredType. The behaviour of the [[DefaultValue]]
| internal method is defined by this specification for all
| native ECMAScript objects in 8.12.8.

ToPrimitive goes through DefaultValue

| When the [[DefaultValue]] internal method of O is
| called with hint Number, the following steps are taken:

| Let valueOf be the result of calling the [[Get]] internal
| method of object O with argument "valueOf".
|
| If IsCallable(valueOf) is true then,
 -- it is true.
| Let val be the result of calling the [[Call]] internal method
| of valueOf, with O as the this value and an empty argument list.

- value: function() { return { } } returns an object.

| If val is a primitive value, return val.
Nope.

| Let toString be the result of calling the [[Get]] internal method of
object O with argument "toString".

Which throws a TypeError exception.

http://www.ecma-international.org/ecma-262/5.1/#sec-8.12.8

new iframe.contentWindow.Image({ toString: function() { return { } },
value: function() { return { } } });

-- 
Garrett
Twitter: @xkit
personx.tumblr.com

Received on Wednesday, 2 October 2013 15:13:08 UTC