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
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:

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

class C {}

this should print

"class C {}"

and not

"function C() {}"

This is important because it is a


"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() {
}, 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
Comment 2 Ryosuke Niwa 2015-05-05 21:51:33 PDT
Created attachment 252446 [details]
Comment 3 Ryosuke Niwa 2016-03-30 22:50:26 PDT

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