⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 235514 in webkit


Ignore:
Timestamp:
Aug 30, 2018, 12:05:34 PM (8 years ago)
Author:
yusukesuzuki@slowstart.org
Message:

output of toString() of Generator is wrong
https://bugs.webkit.org/show_bug.cgi?id=188952

Reviewed by Saam Barati.

JSTests:

  • stress/function-to-string.js: Added.

(shouldBe):
(shouldBe.test):
(test):
(shouldBe.async.test):
(async.test):
(shouldBe.async):
(async):

  • test262/expectations.yaml:

Source/JavaScriptCore:

Function#toString does not respect generator and async generator.
This patch fixes them and supports all the function types.

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString):

Location:
trunk
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r235491 r235514  
     12018-08-30  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
     2
     3        output of toString() of Generator is wrong
     4        https://bugs.webkit.org/show_bug.cgi?id=188952
     5
     6        Reviewed by Saam Barati.
     7
     8        * stress/function-to-string.js: Added.
     9        (shouldBe):
     10        (shouldBe.test):
     11        (test):
     12        (shouldBe.async.test):
     13        (async.test):
     14        (shouldBe.async):
     15        (async):
     16        * test262/expectations.yaml:
     17
    1182018-08-29  Mark Lam  <mark.lam@apple.com>
    219
  • trunk/JSTests/test262/expectations.yaml

    r234777 r235514  
    910910  strict mode: "SyntaxError: Unexpected token '}'. Expected a ')' or a ',' after a parameter declaration."
    911911test/built-ins/Function/prototype/toString/async-arrow-function.js:
    912   default: "Test262Error: Conforms to NativeFunction Syntax: 'async function ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
    913   strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'async function ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
     912  default: "Test262Error: Conforms to NativeFunction Syntax: 'async ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
     913  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'async ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ }'.(async /* a */ ( /* b */ a /* c */ , /* d */ b /* e */ ) /* f */ => /* g */ { /* h */ ; /* i */ })"
    914914test/built-ins/Function/prototype/toString/async-function-declaration.js:
    915915  default: "Test262Error: Conforms to NativeFunction Syntax: 'async function f( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }'.(async function /* a */ f /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ })"
     
    943943  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function F( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ }'.(function /* a */ F /* b */ ( /* c */ x /* d */ , /* e */ y /* f */ ) /* g */ { /* h */ ; /* i */ ; /* j */ })"
    944944test/built-ins/Function/prototype/toString/generator-function-declaration.js:
    945   default: "Test262Error: Conforms to NativeFunction Syntax: 'function g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
    946   strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
     945  default: "Test262Error: Conforms to NativeFunction Syntax: 'function* g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
     946  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function* g( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ g /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
    947947test/built-ins/Function/prototype/toString/generator-function-expression.js:
    948   default: "Test262Error: Conforms to NativeFunction Syntax: 'function F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
    949   strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
     948  default: "Test262Error: Conforms to NativeFunction Syntax: 'function* F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
     949  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function* F( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ }'.(function /* a */ * /* b */ F /* c */ ( /* d */ x /* e */ , /* f */ y /* g */ ) /* h */ { /* i */ ; /* j */ ; /* k */ })"
    950950test/built-ins/Function/prototype/toString/generator-method.js:
    951   default: "Test262Error: Conforms to NativeFunction Syntax: 'function f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
    952   strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
     951  default: "Test262Error: Conforms to NativeFunction Syntax: 'function* f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
     952  strict mode: "Test262Error: Conforms to NativeFunction Syntax: 'function* f( /* c */ ) /* d */ { /* e */ }'.(* /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
    953953test/built-ins/Function/prototype/toString/getter-class-expression-static.js:
    954954  default: "Test262Error: Conforms to NativeFunction Syntax: 'function ( /* c */ ) /* d */ { /* e */ }'.(get /* a */ f /* b */ ( /* c */ ) /* d */ { /* e */ })"
  • trunk/Source/JavaScriptCore/ChangeLog

    r235491 r235514  
     12018-08-30  Yusuke Suzuki  <yusukesuzuki@slowstart.org>
     2
     3        output of toString() of Generator is wrong
     4        https://bugs.webkit.org/show_bug.cgi?id=188952
     5
     6        Reviewed by Saam Barati.
     7
     8        Function#toString does not respect generator and async generator.
     9        This patch fixes them and supports all the function types.
     10
     11        * runtime/FunctionPrototype.cpp:
     12        (JSC::functionProtoFuncToString):
     13
    1142018-08-29  Mark Lam  <mark.lam@apple.com>
    215
  • trunk/Source/JavaScriptCore/runtime/FunctionPrototype.cpp

    r231839 r235514  
    9999        }
    100100
    101         if (thisValue.inherits<JSAsyncFunction>(vm)) {
    102             String functionHeader = executable->isArrowFunction() ? "async " : "async function ";
     101        String functionHeader;
     102        switch (executable->parseMode()) {
     103        case SourceParseMode::GeneratorWrapperFunctionMode:
     104        case SourceParseMode::GeneratorWrapperMethodMode:
     105            functionHeader = "function* ";
     106            break;
    103107
    104             StringView source = executable->source().provider()->getRange(
    105                 executable->parametersStartOffset(),
    106                 executable->parametersStartOffset() + executable->source().length());
    107             scope.release();
    108             return JSValue::encode(jsMakeNontrivialString(exec, functionHeader, function->name(vm), source));
     108        case SourceParseMode::NormalFunctionMode:
     109        case SourceParseMode::GetterMode:
     110        case SourceParseMode::SetterMode:
     111        case SourceParseMode::MethodMode:
     112        case SourceParseMode::ProgramMode:
     113        case SourceParseMode::ModuleAnalyzeMode:
     114        case SourceParseMode::ModuleEvaluateMode:
     115        case SourceParseMode::GeneratorBodyMode:
     116        case SourceParseMode::AsyncGeneratorBodyMode:
     117        case SourceParseMode::AsyncFunctionBodyMode:
     118        case SourceParseMode::AsyncArrowFunctionBodyMode:
     119            functionHeader = "function ";
     120            break;
     121
     122        case SourceParseMode::ArrowFunctionMode:
     123            functionHeader = "";
     124            break;
     125
     126        case SourceParseMode::AsyncFunctionMode:
     127        case SourceParseMode::AsyncMethodMode:
     128            functionHeader = "async function ";
     129            break;
     130
     131        case SourceParseMode::AsyncArrowFunctionMode:
     132            functionHeader = "async ";
     133            break;
     134
     135        case SourceParseMode::AsyncGeneratorWrapperFunctionMode:
     136        case SourceParseMode::AsyncGeneratorWrapperMethodMode:
     137            functionHeader = "async function* ";
     138            break;
    109139        }
    110140
    111         String functionHeader = executable->isArrowFunction() ? "" : "function ";
    112        
    113141        StringView source = executable->source().provider()->getRange(
    114142            executable->parametersStartOffset(),
Note: See TracChangeset for help on using the changeset viewer.