<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>12798</bug_id>
          
          <creation_ts>2011-05-27 12:13:01 +0000</creation_ts>
          <short_desc>Default to [TreatNullAs=EmptyString]</short_desc>
          <delta_ts>2013-10-28 05:54:23 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>WebIDL</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>WONTFIX</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ms2ger">Ms2ger</reporter>
          <assigned_to name="Cameron McCormack">cam</assigned_to>
          <cc>adrianba</cc>
    
    <cc>allen</cc>
    
    <cc>annevk</cc>
    
    <cc>brendan</cc>
    
    <cc>bugs</cc>
    
    <cc>jonas</cc>
    
    <cc>kennyluck</cc>
    
    <cc>lachlan.hunt</cc>
    
    <cc>mike</cc>
    
    <cc>public-script-coord</cc>
    
    <cc>travil</cc>
    
    <cc>w3c</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>48868</commentid>
    <comment_count>0</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2011-05-27 12:13:01 +0000</bug_when>
    <thetext>Just to make sure you don&apos;t forget.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>48899</commentid>
    <comment_count>1</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2011-05-29 22:30:53 +0000</bug_when>
    <thetext>Thanks, done now.  I called the old behaviour &quot;[TreatNullAs=String]&quot;, for want of a better identifier to use after the &quot;=&quot;.

http://dev.w3.org/cvsweb/2006/webapi/WebIDL/Overview.xml.diff?r1=1.279;r2=1.280;f=h</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49511</commentid>
    <comment_count>2</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2011-06-13 19:44:18 +0000</bug_when>
    <thetext>I&apos;m a little concerned about this change; what was the justification for this change?

In IE9, we now use WebIDL syntax to drive the code-generation for our legacy DOM APIs. I just checked, and 443+ of our legacy APIs are using null-&gt;&quot;null&quot; conversions, while only 2 needed the [TreatNullAs=EmptyString] annotations. There are some additional APIs I&apos;d have to test to validate (as the signatures don&apos;t 100% align with those speced in the latest W3C WebIDL-converted specs)--however it&apos;s doubtful that those would change the tide. Given IE&apos;s wide deployment and large compatibility history, I&apos;d guess that null-&gt;&quot;null&quot; conversions are more typically expected by the web.

Additionally, by flipping the default, you are moving away from ECMAScript default conversions (ToString(x)) which seems backwards and not a direction we should be going.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49513</commentid>
    <comment_count>3</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2011-06-13 19:58:02 +0000</bug_when>
    <thetext>I agree. I&apos;d prefer to see this go the other direction despite the fact that Gecko&apos;s default is to do what the spec now says.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49514</commentid>
    <comment_count>4</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-06-13 20:04:43 +0000</bug_when>
    <thetext>null -&gt; &quot;null&quot; has always felt very strange to me.
And based on experience with Gecko, the Web doesn&apos;t expect it
more than handling null as a null or empty string.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49516</commentid>
    <comment_count>5</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2011-06-13 20:08:21 +0000</bug_when>
    <thetext>I agree that null -&gt; &quot;null is strange (which is why I originally argued against it), but no stranger than undefined -&gt; &quot;undefined&quot;. And it is what&apos;s most consistent with other JS APIs. I think that is more important.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49517</commentid>
    <comment_count>6</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-06-13 20:14:16 +0000</bug_when>
    <thetext>(In reply to comment #5)
&gt;  And it is what&apos;s most
&gt; consistent with other JS APIs. 

Could you explain this a bit?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49518</commentid>
    <comment_count>7</comment_count>
    <who name="Jonas Sicking (Not reading bugmail)">jonas</who>
    <bug_when>2011-06-13 20:24:43 +0000</bug_when>
    <thetext>Any JS APIs which operate on strings will convert null to &quot;null&quot;. For example

a = &quot;foo&quot; + null;  // a = &quot;foonull&quot;

People that are more familiar with the standard JS API can probably come up with many more examples.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49520</commentid>
    <comment_count>8</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-06-13 20:40:05 +0000</bug_when>
    <thetext>But this kind of common API doesn&apos;t magically convert null to &quot;null&quot;.

var o = {
  _a : &quot;foo&quot;,
  setA: function(v) {
    this._a = v;
  },
  getA: function(v) {
    return this._a;
  }
}

var value = null;
o.setA(value);
alert(value == o.getA());

So, I&apos;m not sure &quot;And it is what&apos;s most consistent with other JS APIs. &quot;
argument really holds.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49521</commentid>
    <comment_count>9</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2011-06-13 20:52:35 +0000</bug_when>
    <thetext>It&apos;s less about user code than about what ECMAScript defines in their &quot;ToString()&quot; internal API used throughout the specification to handle conversions.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49522</commentid>
    <comment_count>10</comment_count>
    <who name="Allen Wirfs-Brock">allen</who>
    <bug_when>2011-06-13 21:14:20 +0000</bug_when>
    <thetext>(In reply to comment #8)
&gt; But this kind of common API doesn&apos;t magically convert null to &quot;null&quot;.
&gt; 
&gt; var o = {
&gt;   _a : &quot;foo&quot;,
&gt;   setA: function(v) {
&gt;     this._a = v;
&gt;   },
&gt;   getA: function(v) {
&gt;     return this._a;
&gt;   }
&gt; }
&gt; 
&gt; var value = null;
&gt; o.setA(value);
&gt; alert(value == o.getA());
&gt; 
&gt; So, I&apos;m not sure &quot;And it is what&apos;s most consistent with other JS APIs. &quot;
&gt; argument really holds.

The above setA method doesn&apos;t do any conversion so it simply stores whatever was passed as the v argument.  If a JavaScript programmer wanted to enforce that _a was a string they would most likely code it as:

   setA: function(v) {
     this._a = String(v);
   },

This String conversion is defined by ECMAScript in terms of ToString (section 9.8) which converts null to &quot;null&quot; and undefined to &quot;undefined&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49523</commentid>
    <comment_count>11</comment_count>
    <who name="Olli Pettay">bugs</who>
    <bug_when>2011-06-13 21:16:20 +0000</bug_when>
    <thetext>That example was just a counter example to
&quot;And it is what&apos;s most consistent with other JS APIs. &quot;
Nothing to do with string conversion ;)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49524</commentid>
    <comment_count>12</comment_count>
    <who name="Brendan Eich">brendan</who>
    <bug_when>2011-06-13 21:18:20 +0000</bug_when>
    <thetext>(In reply to comment #8)
&gt; But this kind of common API doesn&apos;t magically convert null to &quot;null&quot;.
&gt; 
&gt; var o = {
&gt;   _a : &quot;foo&quot;,
&gt;   setA: function(v) {
&gt;     this._a = v;
&gt;   },
&gt;   getA: function(v) {
&gt;     return this._a;
&gt;   }
&gt; }
&gt; 
&gt; var value = null;
&gt; o.setA(value);
&gt; alert(value == o.getA());

There is no conversion here at all!

I don&apos;t see how this argue for null -&gt; &quot;&quot; or null -&gt; &quot;null&quot;.

OTOH, the + operator with string on left or right, String called as function, parseInt/parseFloat convering their argument to string, all use ECMA-262&apos;s ToString, which does null -&gt; &quot;null&quot;.

/be</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49525</commentid>
    <comment_count>13</comment_count>
    <who name="Allen Wirfs-Brock">allen</who>
    <bug_when>2011-06-13 21:46:07 +0000</bug_when>
    <thetext>(In reply to comment #11)
&gt; That example was just a counter example to
&gt; &quot;And it is what&apos;s most consistent with other JS APIs. &quot;
&gt; Nothing to do with string conversion ;)

It&apos;s all about string conversion.

This issue is about what to do when null is passed as an argument corresponding to a parameter that is supposed to be a DOMString.  In general, JS code that wants to ensure that a value is a string will use the String() function to do the conversion.  That function is defined in terms of ToString.

ToString is also specified as the default conversion algorithm for DOMString parameters in Web IDL 4.1.14</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49530</commentid>
    <comment_count>14</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2011-06-13 22:20:17 +0000</bug_when>
    <thetext>(In reply to comment #13)
&gt; ToString is also specified as the default conversion algorithm for DOMString
&gt; parameters in Web IDL 4.1.14

Not after the recent change that prompted Jonas to reopen this bug.
http://dev.w3.org/2006/webapi/WebIDL/#es-DOMString

I had written myself a note from a fair while ago to make this change, but I didn&apos;t write down the arguments for doing so. :o

In trying to come up with arguments to support this post facto, I can&apos;t come up with anything super strong.  We do of course have [TreatNullAs] to handle cases where the default isn&apos;t compatible with content.

There are many operation/attributes in the HTML5 spec that take a string where passing in null seems like it should do the same thing as the empty string.  null to me seems more &quot;do nothing-ish&quot; than the string &quot;null&quot;.  So for example doing

  inputElement.value = null;

on the face of it looks much more like it would clear the value rather than set it to the string &quot;null&quot;.  OTOH this could encourage two different, valid ways of getting the same behaviour, when perhaps we should just be encouraging authors to use &quot;&quot;.

The previous behaviour is easier to explain.  &quot;When you pass a value to a DOMString parameter, it&apos;s always converted to a string like String(value) or value+&apos;&apos;&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49534</commentid>
    <comment_count>15</comment_count>
    <who name="Allen Wirfs-Brock">allen</who>
    <bug_when>2011-06-13 22:33:45 +0000</bug_when>
    <thetext>(In reply to comment #14)
&gt; (In reply to comment #13)
&gt; &gt; ToString is also specified as the default conversion algorithm for DOMString
&gt; &gt; parameters in Web IDL 4.1.14
&gt; 
&gt; Not after the recent change that prompted Jonas to reopen this bug.
&gt; http://dev.w3.org/2006/webapi/WebIDL/#es-DOMString
&gt; 

Actually, what I meant is that the default (step 3) after the special cases are found not to apply is ToString.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49675</commentid>
    <comment_count>16</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2011-06-16 08:45:29 +0000</bug_when>
    <thetext>I&apos;m okay with reverting this; I filed the bug because I understood the consensus to be that null -&gt; &quot;null&quot; wasn&apos;t web-compatible (at least, for non-IE browsers). I&apos;d be rather happy if we could get away with changing the default.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49781</commentid>
    <comment_count>17</comment_count>
    <who name="Lachlan Hunt">lachlan.hunt</who>
    <bug_when>2011-06-17 12:14:10 +0000</bug_when>
    <thetext>There are cases like document.write(null) and alert(null), where stringifying to &quot;null&quot; is better, particularly where those methods are used for quick debugging to check what the value of a variable is.  If they stringify to &quot;&quot;, then the output would be misleading for developers which, based on existing widespread behaviour, is to expect &quot;null&quot;.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49820</commentid>
    <comment_count>18</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2011-06-18 05:41:29 +0000</bug_when>
    <thetext>I&apos;ve reverted the change.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49825</commentid>
    <comment_count>19</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-06-18 07:54:04 +0000</bug_when>
    <thetext>Pretty much every method and attribute setter relies on the Gecko behavior of null -&gt; &quot;&quot; I think and there is quite some content out there that relies on this too. Enough that Opera recently switched from null -&gt; &quot;null&quot; to null -&gt; &quot;&quot;.

I believe WebKit has had similar experience. Now if Gecko is changed and they can ship with that change null -&gt; &quot;null&quot; might be the right thing to do, but otherwise the more sensible default is null -&gt; &quot;&quot;. Both for existing methods and attribute setters and for future ones, so we have at least some consistency.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49842</commentid>
    <comment_count>20</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2011-06-18 19:17:59 +0000</bug_when>
    <thetext>&gt;&gt; &quot;I *think* and there is quite some content out there that relies on
this too&quot;

&gt;&gt; &quot;I *believe* WebKit has had similar experience.&quot;

Anne, can you provide some examples that motivated the change in Opera?

As I sighted before, the IE behavior defatul is null-&gt;&quot;null&quot;, so I&apos;m wondering what sites are broken in IE due to this behavior (and not some other side-effect)?

In addition to the compatibility argument, there&apos;s also the argument around consistency _with ECMAScript_ default behavior. We should be very careful about changing to a default that is inconsistent with ECMAScript null converstions in [[ToString]]. Now, if ECMAScript is willing to change their defaults, then I think we may have something to discuss.


&gt;&gt; Now if Gecko is changed and they can ship with that change null -&gt; &quot;null&quot; might be the right thing to do, but otherwise the more sensible default is null -&gt; &quot;&quot;. Both for existing methods and attribute setters and for future ones, so we have at least some consistency.

Indeed I am arguing for consistency, but consistency between the DOM and ECMAScript. This is one of my goals for the WebIDL binding.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49885</commentid>
    <comment_count>21</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2011-06-20 05:53:19 +0000</bug_when>
    <thetext>It would be good to hear from WebKit developers about this.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49898</commentid>
    <comment_count>22</comment_count>
    <who name="Adam Barth">w3c</who>
    <bug_when>2011-06-20 07:06:55 +0000</bug_when>
    <thetext>&gt; It would be good to hear from WebKit developers about this.

I don&apos;t have much to add.  You all can test WebKit&apos;s behavior just as well as I can.  I don&apos;t know of any particular requirements one way or another.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49929</commentid>
    <comment_count>23</comment_count>
    <who name="Brendan Eich">brendan</who>
    <bug_when>2011-06-20 17:48:10 +0000</bug_when>
    <thetext>Need to survey some Gecko/WebKit/Presto forks of content that might care. I wrote in public-script-coord:

Could someone cite some examples on the web?

I&apos;m prepared to believe they are Out There. We might have to cater to them with some quirks mode or other. But we need a survey to study the de-facto standard requirements.

BTW, I&apos;m sympathetic to the idea that WebIDL, for historical or even just-so ahistorical reasons, might want a &quot;nullable DOMString&quot; type. This is not that JS-friendly, and JS matters a lot more than Java, C#, etc. But it still could be that WebIDL and users, even users of the JS APIs, want null -&gt; &quot;&quot; (a falsy value).

So ignoring compatibility constraints, and ignoring the separate falsy-might-be-better argument, I&apos;d prefer &quot;ECMAScript ToString&quot; semantics.

But we can&apos;t ignore those two issues, I agree. We need to study some JS on the web that cares.
---

The breaking change could be bad: falsy value becomes truthy, changing control flow. Also, less bad but still pretty bad: you see &quot;null&quot; instead of &quot;&quot; in data that is presented to the user.

/be</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>49944</commentid>
    <comment_count>24</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2011-06-20 21:41:58 +0000</bug_when>
    <thetext>It seems my recollection about this affecting a lot was wrong (thankfully I guess). This affected two or three sites of which I cannot give the URL and given that both Gecko and WebKit were consistent we decided to follow them. In particular innerHTML and setAttribute() are affected. If both Gecko and WebKit change we can change as well.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>50086</commentid>
    <comment_count>25</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2011-06-22 00:02:16 +0000</bug_when>
    <thetext>Per http://www.w3.org/mid/op.vxfg9dxp64w2qv@anne-van-kesterens-macbook-pro.local I&apos;m marking this RESOLVED WONTFIX.  Remember that this would have been only a change in defaults -- individual attributes and operation arguments can be marked with [TreatNullAs] to override the default, in case of compatibility problems.  If in the future we have some concrete data on whether DOM APIs overwhelmingly prefer &quot;&quot; or &quot;null&quot;, we can just select the default appropriately and update specifications.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>