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

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>149743</bug_id>
          
          <creation_ts>2015-10-02 01:08:20 -0700</creation_ts>
          <short_desc>Function.toString.call(class Foo {}) doesn&apos;t say &quot;class&quot;</short_desc>
          <delta_ts>2016-06-06 23:23:32 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Safari 9</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>DUPLICATE</resolution>
          <dup_id>155336</dup_id>
          
          <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="Jordan Harband">ljharb</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>darin</cc>
    
    <cc>fpizlo</cc>
    
    <cc>joepeck</cc>
    
    <cc>saam</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1130191</commentid>
    <comment_count>0</comment_count>
    <who name="Jordan Harband">ljharb</who>
    <bug_when>2015-10-02 01:08:20 -0700</bug_when>
    <thetext>`Function.toString.call(class Foo {})` should return `class Foo {}`, not `function Foo() {}`.

Function#toString is definitely underspecified in ES6, but the current spec text *allows* for the correct representation, and future spec text will require it. Please fix this ASAP.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1130745</commentid>
    <comment_count>1</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2015-10-05 14:47:41 -0700</bug_when>
    <thetext>When implementing methods in class body, what happens?


function A() {
}

A.prototype.method = function () { };


class B {
    method() { }
}

In the above case, A.toString() just returns the function code, but B.toString() returns the class body including the method definition.
I don&apos;t think there should be difference because class declaration behaves like a syntax sugar.

So I think waiting the things specified in the spec.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1130746</commentid>
    <comment_count>2</comment_count>
    <who name="Yusuke Suzuki">ysuzuki</who>
    <bug_when>2015-10-05 14:51:05 -0700</bug_when>
    <thetext>/So I think waiting the things specified in the spec./So I think waiting the things specified in the spec is better./s</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1130762</commentid>
    <comment_count>3</comment_count>
    <who name="Jordan Harband">ljharb</who>
    <bug_when>2015-10-05 15:34:40 -0700</bug_when>
    <thetext>In that example - when the method is dynamically added - the &quot;method&quot; function absolutely wouldn&apos;t appear. If you define a function&apos;s name later, it doesn&apos;t affect its string representation.

While it&apos;s fine to wait, this means it&apos;s *impossible* to detect when a &quot;class&quot; was defined using &quot;class&quot; syntax, and also does not comply with how Chrome or Edge does it (although it does comply with how Firefox does it).

Waiting for the spec to define it isn&apos;t the worst idea, but Chrome and Edge&apos;s behavior will almost certainly become the standard - so it&apos;d be nice if WebKit/Safari followed suit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1130813</commentid>
    <comment_count>4</comment_count>
    <who name="Saam Barati">saam</who>
    <bug_when>2015-10-05 17:27:05 -0700</bug_when>
    <thetext>(In reply to comment #3)
&gt; In that example - when the method is dynamically added - the &quot;method&quot;
&gt; function absolutely wouldn&apos;t appear. If you define a function&apos;s name later,
&gt; it doesn&apos;t affect its string representation.
&gt; 
&gt; While it&apos;s fine to wait, this means it&apos;s *impossible* to detect when a
&gt; &quot;class&quot; was defined using &quot;class&quot; syntax, and also does not comply with how
&gt; Chrome or Edge does it (although it does comply with how Firefox does it).
Why would you want to detect this?

&gt; Waiting for the spec to define it isn&apos;t the worst idea, but Chrome and
&gt; Edge&apos;s behavior will almost certainly become the standard - so it&apos;d be nice
&gt; if WebKit/Safari followed suit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1130839</commentid>
    <comment_count>5</comment_count>
    <who name="Jordan Harband">ljharb</who>
    <bug_when>2015-10-05 19:59:22 -0700</bug_when>
    <thetext>&gt; Why would you want to detect this?

There&apos;s any number of reasons. When I give them, the typical response is, &quot;don&apos;t do that&quot; - ie, determinine if a function will throw on [[Call]], or to help determine `IsConstructor` in an engine that doesn&apos;t support `new.target`. I&apos;ve also written modules that detect if something&apos;s an arrow function, or a generator, etc - it&apos;s a use case that exists. Sadly, it&apos;s impossible without this fix.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1199878</commentid>
    <comment_count>6</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2016-06-06 20:39:35 -0700</bug_when>
    <thetext>This is working as expected now. I believe this was fixed by:

Implement Function.name and Function#toString for ES6 class.
https://bugs.webkit.org/show_bug.cgi?id=155336
http://trac.webkit.org/r198042

*** This bug has been marked as a duplicate of bug 155336 ***</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1199895</commentid>
    <comment_count>7</comment_count>
    <who name="Jordan Harband">ljharb</who>
    <bug_when>2016-06-06 21:22:03 -0700</bug_when>
    <thetext>This is still not fixed in stable, nor in nightly from 2016-06-06.

`Function.toString.call(class Foo {})` returns `
&quot;function () {
    
}&quot;` which is decidedly not correct, especially given the `Function#toString` spec changes that are now stage 3 in ECMAScript.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1199929</commentid>
    <comment_count>8</comment_count>
    <who name="Joseph Pecoraro">joepeck</who>
    <bug_when>2016-06-06 22:57:34 -0700</bug_when>
    <thetext>(In reply to comment #7)
&gt; This is still not fixed in stable, nor in nightly from 2016-06-06.
&gt; 
&gt; `Function.toString.call(class Foo {})` returns `
&gt; &quot;function () {
&gt;     
&gt; }&quot;` which is decidedly not correct, especially given the `Function#toString`
&gt; spec changes that are now stage 3 in ECMAScript.

When I run this I get:

js&gt; Function.toString.call(class Foo {})
&quot;class Foo {}&quot;

I checked Safari Technology Preview Release 5, WebKit Nightly 6/6 (r201731), and a Trunk Build in `jsc` from around 201700 (give or take 15 commits).

Could you clarify in what version of WebKit you are testing this?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1199943</commentid>
    <comment_count>9</comment_count>
    <who name="Jordan Harband">ljharb</who>
    <bug_when>2016-06-06 23:23:32 -0700</bug_when>
    <thetext>ahh oops sorry, I was looking at the wrong bugs site :-p this is broken in firefox but works fine in the latest Safari Tech Preview.

Thanks for fixing this!!

*** This bug has been marked as a duplicate of bug 155336 ***</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>