<?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>25050</bug_id>
          
          <creation_ts>2014-03-14 07:36:35 +0000</creation_ts>
          <short_desc>Should Constructors behave like operations or (attribute) setters?</short_desc>
          <delta_ts>2019-03-01 16:19:52 +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>FIXED</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="Nils Barth">nbarth+w3bugzilla</reporter>
          <assigned_to name="Cameron McCormack">cam</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>mike</cc>
    
    <cc>Ms2ger</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>102354</commentid>
    <comment_count>0</comment_count>
    <who name="Nils Barth">nbarth+w3bugzilla</who>
    <bug_when>2014-03-14 07:36:35 +0000</bug_when>
    <thetext>http://heycam.github.io/webidl/#Constructor

[[
throw an exception
]]

Could we clarify that this throws exceptions for invalid arguments
the same as *operations* (not *attributes*), if this is correct?

This came up in asking what happens if you pass an invalid value for enumeration argument;
a constructor is a method (on the global object), hence presumably the same
behavior as operations (methods on interface objects): throw TypeError on invalid value.

However, it&apos;s potentially ambiguous, as constructors set *attributes*,
and for attributes assigning an invalid value is *ignored*.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102374</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2014-03-14 14:15:55 +0000</bug_when>
    <thetext>&gt; if this is correct?

It&apos;s correct.  The normative spec for what calling a constructor does is at http://heycam.github.io/webidl/#es-interface-call and directly invokes &quot;convert to an IDL value&quot; on the arguments.  This will throw for an invalid value of an enumeration.

&gt; and for attributes assigning an invalid value is *ignored*.

This is done explicitly in http://heycam.github.io/webidl/#dfn-attribute-setter which doesn&apos;t actually invoke &quot;convert to an IDL value&quot; in the enumeration case.

&gt; as constructors set *attributes*

Not as far as WebIDL is concerned.  Any attribute setting a constructor might do would happen in the &quot;performing the actions listed in the description of constructor with values as the argument values&quot; step (step 5 in the &quot;The internal [[Call]] method of the interface object behaves as follows&quot; steps, which I sadly can&apos;t link to directly), while the handling of the constructor arguments happens in step 4 of those same staps.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102375</commentid>
    <comment_count>2</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2014-03-14 14:18:31 +0000</bug_when>
    <thetext>Put another way, in pseudocode a WebIDL constructor looks like this:

  function myConstructor() {
    [f, args] = selectOverloadAndCoerceArgs(arguments);
    return f.call(args);
  }

where the behavior of &quot;f&quot; is defined by whatever specification is defining the constructor (and might set attributes on the object, or do something else; who knows) and the coercions performed to produce &quot;args&quot; are defined by WebIDL.  The latter are what throws when an out-of-the-set value is passed for an enumeration.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>102906</commentid>
    <comment_count>3</comment_count>
    <who name="Nils Barth">nbarth+w3bugzilla</who>
    <bug_when>2014-03-26 05:08:42 +0000</bug_when>
    <thetext>(In reply to Boris Zbarsky from comment #2)

Thanks for clarifying Boris!
Agreed that the spec is unambiguous, but the behavior is a bit buried.

Perhaps a note to the effect that constructors behave like operations for arguments could be added?

For example:
[[
Note:
Constructors and operations use the same overload resolution algorithm for identification of which overloaded operation, constructor, etc. is being called, and for conversion of the ECMAScript argument values to their corresponding IDL values.
]]

...right after:
[[
See section 4.5.1.1 below for details on how a constructor for an interface is to be implemented, and section 4.5.3 for how a constructor for a dictionary is to be implemented.
]]</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>129592</commentid>
    <comment_count>4</comment_count>
    <who name="Ms2ger">Ms2ger</who>
    <bug_when>2019-03-01 16:19:52 +0000</bug_when>
    <thetext>https://github.com/heycam/webidl/pull/673</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>