Bug 143171

Summary: Web Inspector: [ES6] Improve Type Profiler Support for Arrow Functions
Product: WebKit Reporter: Joseph Pecoraro <joepeck>
Component: Web InspectorAssignee: Saam Barati <saam>
Status: RESOLVED FIXED    
Severity: Normal CC: commit-queue, graouts, joepeck, jonowells, mattbaker, nvasilyev, saam, timothy, webkit-bug-importer
Priority: P2 Keywords: InRadar
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
patch
joepeck: review-
patch joepeck: review+

Description Joseph Pecoraro 2015-03-27 18:44:38 PDT
* SUMMARY
Improve Type Profiler Support for ES6 Syntax.

  • ScriptSyntaxTree should support ES6 syntax that Esprima produces
    - template strings
    - modules, packages (export/import)
    - arrow functions
    - binding patterns
    - comprehensions? (ES7?)

  • BasicBlockAnnotator for method syntax is a bit off
    - closing brace doesn't appear to be included
Comment 1 Radar WebKit Bug Importer 2015-03-27 18:45:09 PDT
<rdar://problem/20335738>
Comment 2 Joseph Pecoraro 2015-09-21 15:31:30 PDT
Retitling to be specifically about Arrow Functions. I think we've handled the rest for ES6, and Block Annotations is aa separate issue.
Comment 3 Saam Barati 2015-09-22 15:08:23 PDT
Created attachment 261768 [details]
patch
Comment 4 WebKit Commit Bot 2015-09-22 15:10:53 PDT
Attachment 261768 [details] did not pass style-queue:


ERROR: Source/JavaScriptCore/runtime/TypeProfiler.h:107:  This { should be at the end of the previous line  [whitespace/braces] [4]
Total errors found: 1 in 7 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 5 Joseph Pecoraro 2015-09-22 15:31:11 PDT
Comment on attachment 261768 [details]
patch

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

> Source/JavaScriptCore/runtime/TypeProfiler.h:73
> +    }
> +    bool operator==(const QueryKey& other) const

Style: Normally there are newlines between multi-line member functions.

> Source/JavaScriptCore/tests/typeProfiler/arrow-functions.js:4
> +let foo = (x) => x;
> +let bar = abc => abc;

Might want to also test a case with {}s.

    let baz = x => { return x }

> Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:152
> +        console.assert( node.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionDeclaration || node.type === WebInspector.ScriptSyntaxTree.NodeType.FunctionExpression || node.type === WebInspector.ScriptSyntaxTree.NodeType.MethodDefinition || node.type === WebInspector.ScriptSyntaxTree.NodeType.ArrowFunctionExpression); 

Style: Unnecessary leading space inside the assert(...).

> Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:372
> +        case WebInspector.ScriptSyntaxTree.NodeType.ArrowFunctionExpression:
>              callback(node, state);
>              this._recurse(node.id, callback, state);
>              this._recurseArray(node.params, callback, state);

r- ArrowFunctionExpression has "expression" but FunctionExpression/FunctionDeclaration don't. We'll need to walk over that. Either a new case, or check `if (node.expression)`.

> Source/WebInspectorUI/UserInterface/Models/ScriptSyntaxTree.js:955
> +    ArrowFunctionExpression: Symbol("arrow-function-expression"),

Nit: Alphabetical order (`sort`)

We should add a basic test for the frontend's new node type in:
LayoutTests/inspector/model/parse-script-syntax-tree.html
Comment 6 Joseph Pecoraro 2015-09-22 15:32:20 PDT
Comment on attachment 261768 [details]
patch

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

>> Source/JavaScriptCore/tests/typeProfiler/arrow-functions.js:4
>> +let bar = abc => abc;
> 
> Might want to also test a case with {}s.
> 
>     let baz = x => { return x }

And maybe even an empty case? () => {}
Comment 7 Saam Barati 2015-09-22 17:26:40 PDT
Created attachment 261782 [details]
patch

Fixed comments.
Also noted in comments that the "expression" field is just a boolean. Not an AST node.
Comment 8 Joseph Pecoraro 2015-09-22 17:29:41 PDT
Comment on attachment 261782 [details]
patch

r=me!
Comment 9 Saam Barati 2015-09-22 17:39:47 PDT
landed in:
http://trac.webkit.org/changeset/190146