<?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>22806</bug_id>
          
          <creation_ts>2013-07-25 18:10:16 +0000</creation_ts>
          <short_desc>Why special case Date and RegExp in #es-sequence</short_desc>
          <delta_ts>2016-09-08 21:15:20 +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>PC</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>[v1]</status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Erik Arvidsson">erik.arvidsson</reporter>
          <assigned_to name="Cameron McCormack">cam</assigned_to>
          <cc>allen</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>chris</cc>
    
    <cc>d</cc>
    
    <cc>mike</cc>
    
    <cc>public-script-coord</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>91286</commentid>
    <comment_count>0</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2013-07-25 18:10:16 +0000</bug_when>
    <thetext>http://dev.w3.org/2006/webapi/WebIDL/#es-sequence

&quot;Any kind of object except for a native Date object or a native RegExp object&quot;

Why are we special casing these 2? ES5 has a bunch of classes (Error, *Error, Number, Boolean, Function etc) and ES6 has a lot more.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91287</commentid>
    <comment_count>1</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2013-07-25 18:12:59 +0000</bug_when>
    <thetext>+1. This should work:

var arrayLike = new Date();
arrayLike.length = 2;
arrayLike[0] = &quot;foo&quot;;
arrayLike[1] = &quot;bar&quot;;

It&apos;s accepted by all ES built-ins.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91340</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-27 00:59:37 +0000</bug_when>
    <thetext>The main issues here are dealing with unions/overloads and whether the types are distinguishable (so that you can do things like (Date or sequence&lt;Date&gt;)).  We can probably just use the same &quot;pick an order&quot; approach we do elsewhere in overload resolution at this point.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91425</commentid>
    <comment_count>3</comment_count>
    <who name="Erik Arvidsson">erik.arvidsson</who>
    <bug_when>2013-07-30 19:59:58 +0000</bug_when>
    <thetext>Why not call out all the other ES5 built-ins? Is it because only Date and RegExp have known overloads?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91426</commentid>
    <comment_count>4</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-30 20:15:08 +0000</bug_when>
    <thetext>It&apos;s because Date and RegExp are built-ins that have corresponding WebIDL types.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91429</commentid>
    <comment_count>5</comment_count>
    <who name="Allen Wirfs-Brock">allen</who>
    <bug_when>2013-07-30 20:29:09 +0000</bug_when>
    <thetext>(In reply to comment #4)
&gt; It&apos;s because Date and RegExp are built-ins that have corresponding WebIDL
&gt; types.

But why is that relevant?  Why is it ok to try to convert a function to a sequence&lt;T&gt; but you won&apos;t allow the same conversion for RegExp?

See completely arbitrary</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91430</commentid>
    <comment_count>6</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-30 20:50:14 +0000</bug_when>
    <thetext>For functions, overloading of WebIDL callbacks (which is the WebIDL type for functions) and sequences is well-defined.  See comment 2, please.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91431</commentid>
    <comment_count>7</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-30 20:50:43 +0000</bug_when>
    <thetext>And in case it&apos;s not clear, I would definitely support removing this restriction.  It sure makes implementation simpler/faster!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91433</commentid>
    <comment_count>8</comment_count>
    <who name="Allen Wirfs-Brock">allen</who>
    <bug_when>2013-07-30 22:09:09 +0000</bug_when>
    <thetext>(In reply to comment #6)
&gt; For functions, overloading of WebIDL callbacks (which is the WebIDL type for
&gt; functions) and sequences is well-defined.  See comment 2, please.

Oh, I get it now, you have existing API&apos;s that are overloaded with X or sequence&lt;X&gt; where X may only be Date or RegExp. Any object that isn&apos;t either a Date or RegExp is treated as an array-like object.

Given how problematic is to make a scalar vs array-like determination for general JS objects, I&apos;ll argue that it is very poor design for a JS facing API to have such a overloading. You should forbid this in all new APIs.

You&apos;re stuck with the existing APIs that do this, but there is no reason you need to enshrine the ability to make such overloads in WebIDL.  It would be better to describe the existing APIs using prose and avoid expose a WebIDL that future API designer might use.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>91441</commentid>
    <comment_count>9</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-07-31 01:33:21 +0000</bug_when>
    <thetext>&gt; you have existing API&apos;s that are overloaded with X or sequence&lt;X&gt; where X may
&gt; only be Date or RegExp.

More precisely, WebIDL allows such APIs.  I rather hope no one in practice is doing that so far with Date and RegExp, though people certainly do it with Node and Touch and so forth from what I&apos;ve seen...

&gt; Given how problematic is to make a scalar vs array-like determination for
&gt; general JS objects

For most of the things above, including Date and RegExp, it&apos;s not too bad: you check whether the object is a Date or RegExp instance (or Node, whatever) and if not, treat it as an arraylike.

But yes, I think the current API best practice for things like that is to use variadics and assume that people who have an array will use spread operators or .apply...

&gt; It would be better to describe the existing APIs using prose 

Given past history, I do not trust either spec authors or the average implementor to get this approach right.  The nice thing with IDL is that it needs to be implemented once per browser, by someone who knows what they&apos;re doing, and then it just works.

I would much prefer having IDL features explicitly marked as deprecated or legacy or whatnot than forcing people to write/implement prose, with all the ensuing problems.

In any case, that&apos;s starting to get a bit afield from this bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>127351</commentid>
    <comment_count>10</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2016-09-08 21:15:20 +0000</bug_when>
    <thetext>Since Date has been removed, https://github.com/heycam/webidl/issues/145 now covers this for the remaining case of RegExp. See also https://github.com/heycam/webidl/issues/148.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>