Bug 155336 - Implement Function.name and Function#toString for ES6 class.
Summary: Implement Function.name and Function#toString for ES6 class.
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Local Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Mark Lam
URL:
Keywords: InRadar
: 144285 149743 (view as bug list)
Depends on:
Blocks:
 
Reported: 2016-03-10 16:22 PST by Mark Lam
Modified: 2016-06-06 23:23 PDT (History)
10 users (show)

See Also:


Attachments
proposed patch. (62.31 KB, patch)
2016-03-11 06:56 PST, Mark Lam
mark.lam: commit-queue-
Details | Formatted Diff | Diff
proposed patch with more tests, some additional comments, + darin's feedback. (69.19 KB, patch)
2016-03-11 12:59 PST, Mark Lam
no flags Details | Formatted Diff | Diff
diff of the old patch vs the current one: for your reviewing convenience. (11.84 KB, text/plain)
2016-03-11 13:00 PST, Mark Lam
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mark Lam 2016-03-10 16:22:33 PST
Patch coming.
Comment 1 Radar WebKit Bug Importer 2016-03-10 16:23:27 PST
<rdar://problem/25098147>
Comment 2 Mark Lam 2016-03-11 06:56:52 PST
Created attachment 273725 [details]
proposed patch.

Still need to run benchmarks.  This patch has passed the JSC and layout tests.
Comment 3 Geoffrey Garen 2016-03-11 09:17:17 PST
Comment on attachment 273725 [details]
proposed patch.

r=me
Comment 4 Saam Barati 2016-03-11 09:23:39 PST
Comment on attachment 273725 [details]
proposed patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=273725&action=review

> Source/JavaScriptCore/runtime/Executable.cpp:513
> +    m_classSource = unlinkedExecutable->classSource();

Is this correct with code caching?
Is it possible to construct a conflict here where we get
instantiated with an unlinked code block that isn't from a class constructor?
Comment 5 Mark Lam 2016-03-11 09:25:27 PST
Comment on attachment 273725 [details]
proposed patch.

Let me double check the UnlinkedFunctionExecutable caching issue.
Comment 6 Saam Barati 2016-03-11 09:27:48 PST
To me it seems like we could construct the same exact
normal "function(){...}" function, call new on it, and then
have a class' constructor be the same source code, and get a
conflict. I don't remember exactly how the hash is determined,
but it seems possible that this could happen.
Comment 7 Saam Barati 2016-03-11 09:38:00 PST
(In reply to comment #6)
> To me it seems like we could construct the same exact
> normal "function(){...}" function, call new on it, and then
> have a class' constructor be the same source code, and get a
> conflict. I don't remember exactly how the hash is determined,
> but it seems possible that this could happen.

Or even two different classes with the same constructor
Comment 8 Mark Lam 2016-03-11 09:48:30 PST
(In reply to comment #7)
> (In reply to comment #6)
> > To me it seems like we could construct the same exact
> > normal "function(){...}" function, call new on it, and then
> > have a class' constructor be the same source code, and get a
> > conflict. I don't remember exactly how the hash is determined,
> > but it seems possible that this could happen.
> 
> Or even two different classes with the same constructor

I'm aware of the theoretical issue, but testing shows that there's no issue.  I'll dig into the code a bit and will update later with reasons why there is / isn't an issue.
Comment 9 Darin Adler 2016-03-11 12:47:31 PST
Comment on attachment 273725 [details]
proposed patch.

View in context: https://bugs.webkit.org/attachment.cgi?id=273725&action=review

> Source/JavaScriptCore/parser/ParserFunctionInfo.h:46
>      const Identifier* className = 0;

nullptr

> Source/JavaScriptCore/parser/ParserFunctionInfo.h:50
> +    unsigned startOffset = 0;
> +    unsigned endOffset = 0;
> +    int startLine = 0;
> +    unsigned startColumn = 0;

In other WebKit code we have been using the brace syntax:

    unsigned startOffset { 0 };

Not sure it’s better, but it would be nice to be consistent in style.
Comment 10 Mark Lam 2016-03-11 12:59:15 PST
Created attachment 273755 [details]
proposed patch with more tests, some additional comments, + darin's feedback.

I investigated the potential code caching issue, and concluded that there is no issue.  This is because we currently only do caching of unlinked executables for global programs or dynamically created functions via the Function constructor.  Class constructors are not cached, and hence, it is safe to stash the class source in its unlinked function executable.

function-toString-vs-name.js already tests for this caching behavior, and I've also added some additional tests to check for global, eval, and Function constructor cases in this revised patch.  If the code caching behavior changes in the future, the tests in function-toString-vs-name.js will catch it.
Comment 11 Mark Lam 2016-03-11 13:00:09 PST
Created attachment 273757 [details]
diff of the old patch vs the current one: for your reviewing convenience.
Comment 12 Mark Lam 2016-03-11 13:02:10 PST
Comment on attachment 273755 [details]
proposed patch with more tests, some additional comments, + darin's feedback.

Saam tells me (offline) that he doesn't think this need additional review.  Will land.
Comment 13 Mark Lam 2016-03-11 13:08:42 PST
Thanks for all the reviews.  Landed in r198042: <http://trac.webkit.org/r198042>.
Comment 14 Ryosuke Niwa 2016-03-30 22:50:26 PDT
*** Bug 144285 has been marked as a duplicate of this bug. ***
Comment 15 Joseph Pecoraro 2016-06-06 20:39:35 PDT
*** Bug 149743 has been marked as a duplicate of this bug. ***
Comment 16 Jordan Harband 2016-06-06 23:23:32 PDT
*** Bug 149743 has been marked as a duplicate of this bug. ***