Commit e89452dd authored by Caitlin Potter's avatar Caitlin Potter Committed by Commit Bot

[async-iteration] improve Function.prototype.toString() output

Currently, async generators are stringified the same way normal
Generators are. This change prefixes async generator methods with
"async *", and other async generator functions with
"async function* ".

BUG=v8:5855
R=adamk@chromium.org, littledan@chromium.org, jwolfe@igalia.com

Change-Id: Ia809fad64caac4464dbc9f7fa7728584d0f67832
Reviewed-on: https://chromium-review.googlesource.com/463526
Commit-Queue: Caitlin Potter <caitp@igalia.com>
Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Cr-Commit-Position: refs/heads/master@{#44278}
parent fc0caf6d
......@@ -13052,13 +13052,17 @@ Handle<String> JSFunction::ToString(Handle<JSFunction> function) {
FunctionKind kind = shared_info->kind();
if (!IsArrowFunction(kind)) {
if (IsConciseMethod(kind)) {
if (IsGeneratorFunction(kind)) {
if (IsAsyncGeneratorFunction(kind)) {
builder.AppendCString("async *");
} else if (IsGeneratorFunction(kind)) {
builder.AppendCharacter('*');
} else if (IsAsyncFunction(kind)) {
builder.AppendCString("async ");
}
} else {
if (IsGeneratorFunction(kind)) {
if (IsAsyncGeneratorFunction(kind)) {
builder.AppendCString("async function* ");
} else if (IsGeneratorFunction(kind)) {
builder.AppendCString("function* ");
} else if (IsAsyncFunction(kind)) {
builder.AppendCString("async function ");
......
......@@ -147,6 +147,28 @@ assertEquals(AsyncGeneratorFunction.prototype.prototype,
Object.getPrototypeOf(new AsyncGeneratorFunction().prototype));
assertTrue(new AsyncGeneratorFunction().hasOwnProperty("prototype"));
// ----------------------------------------------------------------------------
// Basic Function.prototype.toString()
async function* asyncGeneratorForToString() {}
assertEquals("async function* asyncGeneratorForToString() {}",
asyncGeneratorForToString.toString());
assertEquals("async function* () {}", async function*() {}.toString());
assertEquals("async function* namedAsyncGeneratorForToString() {}",
async function* namedAsyncGeneratorForToString() {}.toString());
assertEquals("async *method() { }",
({ async *method() { } }).method.toString());
assertEquals("async *method() { }",
(class { static async *method() { } }).method.toString());
assertEquals("async *method() { }",
(new (class { async *method() { } })).method.toString());
assertEquals("async function* anonymous() {\n\n}",
AsyncGeneratorFunction().toString());
assertEquals("async function* anonymous() {\n\n}",
(new AsyncGeneratorFunction()).toString());
// ----------------------------------------------------------------------------
// AsyncGenerator functions syntactically allow AwaitExpressions
assertEquals(1, async function*(a) { await 1; }.length);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment