From 74a4152703de006433df26e583f996b84f5c0dbd Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Fri, 25 Sep 2020 17:05:08 -0400 Subject: [PATCH] Coverage: lexical arguments, new.target, in async arrow functions. Fixes gh-1737 --- ...eturns-arguments-from-parent-function.case | 30 +++++++++++++++++++ ...returns-async-arrow-returns-newtarget.case | 29 ++++++++++++++++++ src/async-functions/returns-async-arrow.case | 29 ++++++++++++++++++ ...n-returns-arguments-from-own-function.case | 30 +++++++++++++++++++ ...urns-async-function-returns-newtarget.case | 29 ++++++++++++++++++ .../returns-async-function.case | 29 ++++++++++++++++++ .../syntax/async-arrow.template | 4 +-- .../syntax/async-class-decl-method.template | 9 ++++-- .../async-class-decl-private-method.template | 12 ++++++-- .../async-class-decl-static-method.template | 9 ++++-- ...-class-decl-static-private-method.template | 12 ++++++-- .../syntax/async-class-expr-method.template | 10 +++++-- .../async-class-expr-private-method.template | 12 ++++++-- .../async-class-expr-static-method.template | 8 +++-- ...-class-expr-static-private-method.template | 11 +++++-- .../syntax/async-declaration.template | 2 +- .../syntax/async-expression-named.template | 2 +- .../syntax/async-expression.template | 2 +- .../syntax/async-obj-method.template | 4 ++- 19 files changed, 251 insertions(+), 22 deletions(-) create mode 100644 src/async-functions/returns-async-arrow-returns-arguments-from-parent-function.case create mode 100644 src/async-functions/returns-async-arrow-returns-newtarget.case create mode 100644 src/async-functions/returns-async-arrow.case create mode 100644 src/async-functions/returns-async-function-returns-arguments-from-own-function.case create mode 100644 src/async-functions/returns-async-function-returns-newtarget.case create mode 100644 src/async-functions/returns-async-function.case diff --git a/src/async-functions/returns-async-arrow-returns-arguments-from-parent-function.case b/src/async-functions/returns-async-arrow-returns-arguments-from-parent-function.case new file mode 100644 index 0000000000..7868b52aa8 --- /dev/null +++ b/src/async-functions/returns-async-arrow-returns-arguments-from-parent-function.case @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-arrow-function-definitions +desc: > + Async function returns an async function. +templates: + - syntax/async-class-*.template + - syntax/async-declaration.template + - syntax/async-expression-*.template + - syntax/async-obj-method.template +flags: [async] +---*/ + +//- setup +let count = 0; +//- params +x +//- body + let a = arguments; + return async () => a === arguments; +//- teardown +asyncFn().then(retFn => { + count++; + return retFn(); +}).then(result => { + assert.sameValue(result, true); + assert.sameValue(count, 1); +}).then($DONE, $DONE); diff --git a/src/async-functions/returns-async-arrow-returns-newtarget.case b/src/async-functions/returns-async-arrow-returns-newtarget.case new file mode 100644 index 0000000000..3fe4fa7ecb --- /dev/null +++ b/src/async-functions/returns-async-arrow-returns-newtarget.case @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-arrow-function-definitions +desc: > + Async function returns an async function. +templates: + - syntax/async-class-*.template + - syntax/async-declaration.template + - syntax/async-expression-*.template + - syntax/async-obj-method.template +flags: [async] +---*/ + +//- setup +let count = 0; +//- params +x +//- body + return async () => new.target; +//- teardown +asyncFn().then(retFn => { + count++; + return retFn(); +}).then(result => { + assert.sameValue(result, undefined); + assert.sameValue(count, 1); +}).then($DONE, $DONE); diff --git a/src/async-functions/returns-async-arrow.case b/src/async-functions/returns-async-arrow.case new file mode 100644 index 0000000000..e6469869e3 --- /dev/null +++ b/src/async-functions/returns-async-arrow.case @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-arrow-function-definitions +desc: > + Async function returns an async function. +templates: + - syntax/async-class-*.template + - syntax/async-declaration.template + - syntax/async-expression-*.template + - syntax/async-obj-method.template +flags: [async] +---*/ + +//- setup +let count = 0; +//- params +x +//- body + return async () => x; +//- teardown +asyncFn(1).then(retFn => { + count++; + return retFn(); +}).then(result => { + assert.sameValue(result, 1); + assert.sameValue(count, 1); +}).then($DONE, $DONE); diff --git a/src/async-functions/returns-async-function-returns-arguments-from-own-function.case b/src/async-functions/returns-async-function-returns-arguments-from-own-function.case new file mode 100644 index 0000000000..17240f4b55 --- /dev/null +++ b/src/async-functions/returns-async-function-returns-arguments-from-own-function.case @@ -0,0 +1,30 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-arrow-function-definitions +desc: > + Async function returns an async function. +templates: + - syntax/async-class-*.template + - syntax/async-declaration.template + - syntax/async-expression-*.template + - syntax/async-obj-method.template +flags: [async] +---*/ + +//- setup +let count = 0; +//- params +x +//- body + let a = arguments; + return async function() { return a === arguments; }; +//- teardown +asyncFn(1).then(retFn => { + count++; + return retFn(); +}).then(result => { + assert.sameValue(result, false); + assert.sameValue(count, 1); +}).then($DONE, $DONE); diff --git a/src/async-functions/returns-async-function-returns-newtarget.case b/src/async-functions/returns-async-function-returns-newtarget.case new file mode 100644 index 0000000000..5123685772 --- /dev/null +++ b/src/async-functions/returns-async-function-returns-newtarget.case @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-arrow-function-definitions +desc: > + Async function returns an async function. +templates: + - syntax/async-class-*.template + - syntax/async-declaration.template + - syntax/async-expression-*.template + - syntax/async-obj-method.template +flags: [async] +---*/ + +//- setup +let count = 0; +//- params +x +//- body + return async function() { return new.target; }; +//- teardown +asyncFn(1).then(retFn => { + count++; + return retFn(); +}).then(result => { + assert.sameValue(result, undefined); + assert.sameValue(count, 1); +}).then($DONE, $DONE); diff --git a/src/async-functions/returns-async-function.case b/src/async-functions/returns-async-function.case new file mode 100644 index 0000000000..3eb62cb343 --- /dev/null +++ b/src/async-functions/returns-async-function.case @@ -0,0 +1,29 @@ +// Copyright (C) 2020 Rick Waldron. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-async-arrow-function-definitions +desc: > + Async function returns an async function. +templates: + - syntax/async-class-*.template + - syntax/async-declaration.template + - syntax/async-expression-*.template + - syntax/async-obj-method.template +flags: [async] +---*/ + +//- setup +let count = 0; +//- params +x +//- body + return async function() { return x; }; +//- teardown +asyncFn(1).then(retFn => { + count++; + return retFn(); +}).then(result => { + assert.sameValue(result, 1); + assert.sameValue(count, 1); +}).then($DONE, $DONE); diff --git a/src/async-functions/syntax/async-arrow.template b/src/async-functions/syntax/async-arrow.template index 14ec6f84cc..7f123e5c19 100644 --- a/src/async-functions/syntax/async-arrow.template +++ b/src/async-functions/syntax/async-arrow.template @@ -17,6 +17,6 @@ info: | features: [async-functions] ---*/ -async() => { +async (/*{ params }*/) => { /*{ body }*/ -}; +} diff --git a/src/async-functions/syntax/async-class-decl-method.template b/src/async-functions/syntax/async-class-decl-method.template index 241a621894..f9911195df 100644 --- a/src/async-functions/syntax/async-class-decl-method.template +++ b/src/async-functions/syntax/async-class-decl-method.template @@ -19,6 +19,11 @@ info: | features: [async-functions] ---*/ -class C { async method() { +class C { + async method(/*{ params }*/) { /*{ body }*/ -}} + } +} +// Stores a reference `asyncFn` for case evaluation +let c = new C(); +let asyncFn = c.method.bind(c); diff --git a/src/async-functions/syntax/async-class-decl-private-method.template b/src/async-functions/syntax/async-class-decl-private-method.template index aec9070e15..99f23261c7 100644 --- a/src/async-functions/syntax/async-class-decl-private-method.template +++ b/src/async-functions/syntax/async-class-decl-private-method.template @@ -19,6 +19,14 @@ info: | features: [async-functions, class-methods-private] ---*/ -class C { async #method() { +class C { + async #method(/*{ params }*/) { /*{ body }*/ -}} + } + async method(/*{ params }*/) { + return this.#method(/*{ params }*/); + } +} +// Stores a reference `asyncFn` for case evaluation +let c = new C(); +let asyncFn = c.method.bind(c); diff --git a/src/async-functions/syntax/async-class-decl-static-method.template b/src/async-functions/syntax/async-class-decl-static-method.template index 2a6c146ec1..d77769e622 100644 --- a/src/async-functions/syntax/async-class-decl-static-method.template +++ b/src/async-functions/syntax/async-class-decl-static-method.template @@ -19,6 +19,11 @@ info: | features: [async-functions] ---*/ -class C { static async method() { +class C { + static async method(/*{ params }*/) { /*{ body }*/ -}} + } +} +// Stores a reference `asyncFn` for case evaluation +let asyncFn = C.method; + diff --git a/src/async-functions/syntax/async-class-decl-static-private-method.template b/src/async-functions/syntax/async-class-decl-static-private-method.template index 4fdae2466e..8408b6d689 100644 --- a/src/async-functions/syntax/async-class-decl-static-private-method.template +++ b/src/async-functions/syntax/async-class-decl-static-private-method.template @@ -19,6 +19,14 @@ info: | features: [async-functions, class-static-methods-private] ---*/ -class C { static async #method() { +class C { + static async #method(/*{ params }*/) { /*{ body }*/ -}} + } + static async method(/*{ params }*/) { + return this.#method(/*{ params }*/); + } +} +// Stores a reference `asyncFn` for case evaluation +let asyncFn = C.method.bind(C); + diff --git a/src/async-functions/syntax/async-class-expr-method.template b/src/async-functions/syntax/async-class-expr-method.template index 4e988ba410..f352be40ed 100644 --- a/src/async-functions/syntax/async-class-expr-method.template +++ b/src/async-functions/syntax/async-class-expr-method.template @@ -19,6 +19,12 @@ info: | features: [async-functions] ---*/ -var C = class { async method() { +var C = class { + async method(/*{ params }*/) { /*{ body }*/ -}}; + } +}; +// Stores a reference `asyncFn` for case evaluation +let c = new C(); +let asyncFn = c.method.bind(c); + diff --git a/src/async-functions/syntax/async-class-expr-private-method.template b/src/async-functions/syntax/async-class-expr-private-method.template index d75ed16512..100aacd0fe 100644 --- a/src/async-functions/syntax/async-class-expr-private-method.template +++ b/src/async-functions/syntax/async-class-expr-private-method.template @@ -19,6 +19,14 @@ info: | features: [async-functions, class-methods-private] ---*/ -var C = class { async #method() { +var C = class { + async #method(/*{ params }*/) { /*{ body }*/ -}}; + } + async method(/*{ params }*/) { + return this.#method(/*{ params }*/); + } +}; +// Stores a reference `asyncFn` for case evaluation +let c = new C(); +let asyncFn = c.method.bind(c); diff --git a/src/async-functions/syntax/async-class-expr-static-method.template b/src/async-functions/syntax/async-class-expr-static-method.template index 9af0668c2e..f01c8a4b62 100644 --- a/src/async-functions/syntax/async-class-expr-static-method.template +++ b/src/async-functions/syntax/async-class-expr-static-method.template @@ -19,6 +19,10 @@ info: | features: [async-functions] ---*/ -var C = class { static async method() { +var C = class { + static async method(/*{ params }*/) { /*{ body }*/ -}}; + } +}; +// Stores a reference `asyncFn` for case evaluation +let asyncFn = C.method; diff --git a/src/async-functions/syntax/async-class-expr-static-private-method.template b/src/async-functions/syntax/async-class-expr-static-private-method.template index e4f3a50097..e7caf9e4c6 100644 --- a/src/async-functions/syntax/async-class-expr-static-private-method.template +++ b/src/async-functions/syntax/async-class-expr-static-private-method.template @@ -19,6 +19,13 @@ info: | features: [async-functions, class-static-methods-private] ---*/ -var C = class { static async #method() { +var C = class { + static async #method(/*{ params }*/) { /*{ body }*/ -}}; + } + static async method(/*{ params }*/) { + return this.#method(/*{ params }*/); + } +} +// Stores a reference `asyncFn` for case evaluation +let asyncFn = C.method.bind(C); diff --git a/src/async-functions/syntax/async-declaration.template b/src/async-functions/syntax/async-declaration.template index b3fcbd43b3..3c82c1749a 100644 --- a/src/async-functions/syntax/async-declaration.template +++ b/src/async-functions/syntax/async-declaration.template @@ -13,6 +13,6 @@ info: | features: [async-functions] ---*/ -async function fn() { +async function asyncFn(/*{ params }*/) { /*{ body }*/ } diff --git a/src/async-functions/syntax/async-expression-named.template b/src/async-functions/syntax/async-expression-named.template index 571d25953c..9d112dba54 100644 --- a/src/async-functions/syntax/async-expression-named.template +++ b/src/async-functions/syntax/async-expression-named.template @@ -13,6 +13,6 @@ info: | features: [async-functions] ---*/ -var fn = async function fn() { +var asyncFn = async function asyncFn(/*{ params }*/) { /*{ body }*/ }; diff --git a/src/async-functions/syntax/async-expression.template b/src/async-functions/syntax/async-expression.template index fb0122e35b..6603704cdf 100644 --- a/src/async-functions/syntax/async-expression.template +++ b/src/async-functions/syntax/async-expression.template @@ -13,6 +13,6 @@ info: | features: [async-functions] ---*/ -var fn = async function () { +var asyncFn = async function (/*{ params }*/) { /*{ body }*/ }; diff --git a/src/async-functions/syntax/async-obj-method.template b/src/async-functions/syntax/async-obj-method.template index a01c56fdad..fb09563e97 100644 --- a/src/async-functions/syntax/async-obj-method.template +++ b/src/async-functions/syntax/async-obj-method.template @@ -14,7 +14,9 @@ features: [async-functions] ---*/ var obj = { - async method() { + async method(/*{ params }*/) { /*{ body }*/ } }; +// Stores a reference `asyncFn` for case evaluation +let asyncFn = obj.method;