Bug 144285 - toString doesn't work on ES6 classes
Summary: toString doesn't work on ES6 classes
Status: RESOLVED DUPLICATE of bug 155336
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Ryosuke Niwa
URL:
Keywords: InRadar
Depends on:
Blocks: 140491
  Show dependency treegraph
 
Reported: 2015-04-27 15:54 PDT by Erik Arvidsson
Modified: 2016-03-30 22:50 PDT (History)
4 users (show)

See Also:


Attachments
WIP (23.75 KB, patch)
2015-05-05 21:51 PDT, Ryosuke Niwa
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
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 ***