[esnext] Async function toString support

BUG=v8:4483

Review-Url: https://codereview.chromium.org/1973193002
Cr-Commit-Position: refs/heads/master@{#36265}
This commit is contained in:
littledan 2016-05-16 18:27:23 -07:00 committed by Commit bot
parent 690922c959
commit 4afe89a7da
2 changed files with 16 additions and 1 deletions

View File

@ -12192,10 +12192,16 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
IncrementalStringBuilder builder(isolate); IncrementalStringBuilder builder(isolate);
if (!shared_info->is_arrow()) { if (!shared_info->is_arrow()) {
if (shared_info->is_concise_method()) { if (shared_info->is_concise_method()) {
if (shared_info->is_generator()) builder.AppendCharacter('*'); if (shared_info->is_generator()) {
builder.AppendCharacter('*');
} else if (shared_info->is_async()) {
builder.AppendCString("async ");
}
} else { } else {
if (shared_info->is_generator()) { if (shared_info->is_generator()) {
builder.AppendCString("function* "); builder.AppendCString("function* ");
} else if (shared_info->is_async()) {
builder.AppendCString("async function ");
} else { } else {
builder.AppendCString("function "); builder.AppendCString("function ");
} }

View File

@ -336,3 +336,12 @@ var resumeAfterThrowNewEval = new AsyncFunction("value", `
log = []; log = [];
assertEqualsAsync(6, () => resumeAfterThrowNewEval(5)); assertEqualsAsync(6, () => resumeAfterThrowNewEval(5));
assertEquals("start:5 resume:throw1 resume:throw2", log.join(" ")); assertEquals("start:5 resume:throw1 resume:throw2", log.join(" "));
async function foo() {}
assertEquals("async function foo() {}", foo.toString());
assertEquals("async function () {}", async function() {}.toString());
assertEquals("async x => x", (async x => x).toString());
assertEquals("async x => { return x }", (async x => { return x }).toString());
class AsyncMethod { async foo() { } }
assertEquals("async foo() { }", Function.prototype.toString.call(AsyncMethod.prototype.foo));
assertEquals("async foo() { }", Function.prototype.toString.call({async foo() { }}.foo));