Bug 144285

Summary: toString doesn't work on ES6 classes
Product: WebKit Reporter: Erik Arvidsson <arv>
Component: JavaScriptCoreAssignee: Ryosuke Niwa <rniwa>
Status: RESOLVED DUPLICATE    
Severity: Normal CC: fpizlo, ggaren, joepeck, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: Unspecified   
OS: Unspecified   
Bug Depends on:    
Bug Blocks: 140491    
Attachments:
Description Flags
WIP none

Description Erik Arvidsson 2015-04-27 15:54:18 PDT
Given

class C {}
print(C.toString());

this should print

"class C {}"

and not

"function C() {}"

This is important because it is a

https://people.mozilla.org/~jorendorff/es6-draft.html#sec-function.prototype.tostring

"If the object was defined using ECMAScript code and the returned string representation is not in the form of a MethodDefinition or GeneratorMethod then the representation must be such that if the string is evaluated, using eval in a lexical context that is equivalent to the lexical context used to create the original object, it will result in a new functionally equivalent object. In that case the returned source code must not mention freely any variables that were not mentioned freely by the original function’s source code, even if these “extra” names were originally in scope."

The behavior of a FunctionDeclaration/FunctionExpression is not equivalent to a ClassDeclaration/ClassExpression. For example try this:

class C {}
assertThrows(function() {
  eval(C.toString())();
}, TypeError); // Class constructors cannot be invoked without 'new'

This fails in JSC.
Comment 1 Radar WebKit Bug Importer 2015-05-03 17:14:57 PDT
<rdar://problem/20795345>
Comment 2 Ryosuke Niwa 2015-05-05 21:51:33 PDT
Created attachment 252446 [details]
WIP
Comment 3 Ryosuke Niwa 2016-03-30 22:50:26 PDT

*** This bug has been marked as a duplicate of bug 155336 ***