Bug 175210 - [ESNext] Async iteration - Implement Async Generator - parser
Summary: [ESNext] Async iteration - Implement Async Generator - parser
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: GSkachkov
URL:
Keywords: InRadar
Depends on:
Blocks: 166695
  Show dependency treegraph
 
Reported: 2017-08-04 14:28 PDT by GSkachkov
Modified: 2017-08-30 03:08 PDT (History)
7 users (show)

See Also:


Attachments
Patch (51.43 KB, patch)
2017-08-04 15:02 PDT, GSkachkov
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description GSkachkov 2017-08-04 14:28:16 PDT
Implemented parser part of the Async Generator
Comment 1 GSkachkov 2017-08-04 15:02:09 PDT
Created attachment 317298 [details]
Patch

Patch
Comment 2 Yusuke Suzuki 2017-08-05 11:54:56 PDT
Comment on attachment 317298 [details]
Patch

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

r=+ with nits.

> Source/JavaScriptCore/parser/ASTBuilder.h:440
> +        SourceParseMode sourceParseMode;

Let's rename this to `bodySourceParseMode` and set `bodySourceParseMode = mode;` first.

> Source/JavaScriptCore/parser/ASTBuilder.h:451
> +        } else
> +            sourceParseMode = mode;

Drop this.

> Source/JavaScriptCore/parser/Parser.cpp:2866
> +            if (isAsyncMethodParseMode(parseMode) || isAsyncGeneratorMethodParseMode(parseMode)) {
>                  isConstructor = false;
> -                parseMode = SourceParseMode::AsyncMethodMode;
> -                semanticFailIfTrue(*ident == m_vm->propertyNames->prototype, "Cannot declare an async method named 'prototype'");
> -                semanticFailIfTrue(*ident == m_vm->propertyNames->constructor, "Cannot declare an async method named 'constructor'");
> -            } else if (isGenerator) {
> +                semanticFailIfTrue(*ident == m_vm->propertyNames->prototype, "Cannot declare ", stringArticleForFunctionMode(parseMode), stringForFunctionMode(parseMode), " named 'prototype'");
> +                semanticFailIfTrue(*ident == m_vm->propertyNames->constructor, "Cannot declare ", stringArticleForFunctionMode(parseMode), stringForFunctionMode(parseMode), " named 'constructor'");
> +            } else if (isGeneratorMethodParseMode(parseMode)) {
>                  isConstructor = false;
>                  parseMode = SourceParseMode::GeneratorWrapperMethodMode;
>                  semanticFailIfTrue(*ident == m_vm->propertyNames->prototype, "Cannot declare a generator named 'prototype'");
>                  semanticFailIfTrue(*ident == m_vm->propertyNames->constructor, "Cannot declare a generator named 'constructor'");
>              }

I think this `if (isGeneratorMethodParseMode(parseMode))` case can be merged into the above async case if you add a generator case to stringArticleForFunctionMode and stringForFunctionMode.
And we do not need to execute `parseMode = SourceParseMode::GeneratorWrapperMethodMode;` since parseMode is already SourceParseMode::GeneratorWrapperMethodMode.

> Source/JavaScriptCore/parser/Parser.cpp:3858
> +    bool isIdentSet = false;

I think this is always `false`, right? Nobody changes this isIdentSet.
What is the purpose of this variable?

> Source/JavaScriptCore/parser/Parser.cpp:3861
> +    const Identifier* ident;
> +    unsigned getterOrSetterStartOffset;
> +    JSToken identToken;

These changes are not necessary. Let's revert this.

> Source/JavaScriptCore/parser/Parser.cpp:3896
> -        JSToken identToken = m_token;
> -        const Identifier* ident = m_token.m_data.ident;
> -        unsigned getterOrSetterStartOffset = tokenStart();
> +        identToken = m_token;
> +        ident = m_token.m_data.ident;
> +        getterOrSetterStartOffset = tokenStart();

I don't think these changes are necessary. Let's revert this.

> Source/JavaScriptCore/parser/Parser.cpp:3900
> +        else if (UNLIKELY(!isIdentSet))

This is always `false`, right?

> Source/JavaScriptCore/parser/Parser.h:1514
> +    ALWAYS_INLINE SourceParseMode getAsynFunctionBodyParseMode(SourceParseMode parseMode)
> +    {
> +        if (isAsyncGeneratorFunctionParseMode(parseMode))
> +            return SourceParseMode::AsyncGeneratorBodyMode;
> +
> +        if (parseMode == SourceParseMode::AsyncArrowFunctionMode)
> +            return SourceParseMode::AsyncArrowFunctionBodyMode;
> +        
> +        return SourceParseMode::AsyncFunctionBodyMode;
> +    }

Let's put it in Parser.cpp as static function insead of Parser's member function.
Comment 3 GSkachkov 2017-08-06 06:05:38 PDT
Patch applied https://trac.webkit.org/r220323
Comment 4 GSkachkov 2017-08-06 06:05:50 PDT
Comment on attachment 317298 [details]
Patch

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

>> Source/JavaScriptCore/parser/ASTBuilder.h:440
>> +        SourceParseMode sourceParseMode;
> 
> Let's rename this to `bodySourceParseMode` and set `bodySourceParseMode = mode;` first.

Done

>> Source/JavaScriptCore/parser/ASTBuilder.h:451
>> +            sourceParseMode = mode;
> 
> Drop this.

Done
Comment 5 Radar WebKit Bug Importer 2017-08-30 03:08:18 PDT
<rdar://problem/34158206>