Re: [whatwg] WebIDL and HTML5

On Mon, Aug 25, 2008 at 11:28 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:
> Garrett Smith wrote:
>>
>> window.open();
>
> Which should be equivalent to window.open(undefined) (and isn't in some
> UAs), right?
>
> What should window.open(null) do?
>
>> If the first argument is null or undefined or the empty string, no uri
>> is loaded and an blank/empty window is displayed.
>
> This is not the case in Firefox, Opera, or Safari.  Safari and Firefox treat
> null as "null".  Opera treats it as "".  Opera treats undefined as "", while
> Safari and Firefox treat it as "undefined".
>
> This is for window.open's first argument.
>
>> There seems to be no mapping though Ian has requested documenting such
>> mapping.
>
> No mapping of what?  ""+null is "null".  ""+undefined is "undefined".

The addition operator results in concatenation when either operand is
a string. This results in a calls to the internal ToString, which is
what I'm suggesting should be the general rule.

> Those
> are basically what Firefox and Safari do. That doesn't seem like the right
> thing to do here, necessarily.
>

I agree that loading path + '/null' or path + 'undefined' is not
desirable. Any application that relies on this is already broken,
arguably, because, contrary to your observations, safari first checks
to see if the argument is null or undefined or the empty string, and,
if that is true, then no uri is loaded. Example:

<!DOCTYPE HTML>
<html lang="en">
<head>
	<title>window.open()</title>
</head>
<body>
<a href="javascript:void(window.open());">open()</a>
<a href="javascript:void(window.open(null));">open(null)</a>
<a href="javascript:void(window.open(undefined));">open(undefined)</a>
<a href="javascript:void(window.open(0));">open(0)</a>
</body>
</html>

Result in Safari:

 window.open(0), loads "can't find that page".
 all others load blank window

Result in Firefox:
 open() open('') open blank window
 all others load "can't find that page"

Ian and others, you may use this and any other test case I post up.

>> Are there other examples for "if the argument is null or undefined..."?
>
> Sure.  A lot of the namespace-relatd DOM methods, as well as all sorts of
> DOM0 stuff.
>
>> There are probably others but I can't think of them. I think the
>> majority of the time that strings will want to go to ToString,
>> booleans will want to go to ToBoolean.
>
> That can be the default, perhaps.  But I suspect usually null should become
> "", not "null".
>

Why?

Garrett
> -Boris
>

Received on Monday, 25 August 2008 18:45:17 UTC