mirror of https://github.com/tc39/test262.git
test: adding async optional chaining tests (#2337)
* test: adding async optional chaining tests * Update test/language/expressions/optional-chaining/member-expression-async-identifier.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/optional-chain-async-square-brackets.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/member-expression-async-this.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/optional-chain-async-optional-chain-square-brackets.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/optional-chain-async-optional-chain-square-brackets.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/optional-chain-async-square-brackets.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/optional-chain-async-square-brackets.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/optional-chain-async-optional-chain-square-brackets.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * Update test/language/expressions/optional-chaining/member-expression-async-identifier.js Co-Authored-By: Leo Balter <leonardo.balter@gmail.com> * chore: update tests based on code review * chore: address code review
This commit is contained in:
parent
256f5f4b46
commit
c41a8ac1a0
|
@ -0,0 +1,32 @@
|
||||||
|
// Copyright 2019 Google, Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain on member expression in async context
|
||||||
|
info: |
|
||||||
|
Left-Hand-Side Expressions
|
||||||
|
OptionalExpression
|
||||||
|
MemberExpression [PrimaryExpression identifier] OptionalChain
|
||||||
|
features: [optional-chaining]
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
const a = undefined;
|
||||||
|
const c = {d: Promise.resolve(11)};
|
||||||
|
async function checkAssertions() {
|
||||||
|
assert.sameValue(await a?.b, undefined);
|
||||||
|
assert.sameValue(await c?.d, 11);
|
||||||
|
|
||||||
|
Promise.prototype.x = 42;
|
||||||
|
var res = await Promise.resolve(undefined)?.x;
|
||||||
|
assert.sameValue(res, 42, 'await unwraps the evaluation of the whole optional chaining expression #1');
|
||||||
|
|
||||||
|
Promise.prototype.y = 43;
|
||||||
|
var res = await Promise.reject(undefined)?.y;
|
||||||
|
assert.sameValue(res, 43, 'await unwraps the evaluation of the whole optional chaining expression #2');
|
||||||
|
|
||||||
|
c.e = Promise.resolve(39);
|
||||||
|
assert.sameValue(await c?.e, 39, 'await unwraps the promise given after the evaluation of the OCE');
|
||||||
|
}
|
||||||
|
checkAssertions().then($DONE, $DONE);
|
|
@ -0,0 +1,19 @@
|
||||||
|
// Copyright 2019 Google, Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain on member expression in async context
|
||||||
|
info: |
|
||||||
|
Left-Hand-Side Expressions
|
||||||
|
OptionalExpression:
|
||||||
|
MemberExpression [PrimaryExpression literal] OptionalChain
|
||||||
|
features: [optional-chaining]
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function checkAssertions() {
|
||||||
|
assert.sameValue(await "hello"?.[0], 'h');
|
||||||
|
assert.sameValue(await null?.a, undefined);
|
||||||
|
}
|
||||||
|
checkAssertions().then($DONE, $DONE);
|
|
@ -0,0 +1,20 @@
|
||||||
|
// Copyright 2019 Google, Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain on member expression in async context
|
||||||
|
info: |
|
||||||
|
Left-Hand-Side Expressions
|
||||||
|
OptionalExpression:
|
||||||
|
MemberExpression [PrimaryExpression this] OptionalChain
|
||||||
|
features: [optional-chaining]
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function thisFn() {
|
||||||
|
return await this?.a
|
||||||
|
}
|
||||||
|
thisFn.call({a: Promise.resolve(33)}).then(function(arg) {
|
||||||
|
assert.sameValue(33, arg);
|
||||||
|
}).then($DONE, $DONE);
|
|
@ -0,0 +1,28 @@
|
||||||
|
// Copyright 2019 Google, Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain expansions in an async context
|
||||||
|
info: |
|
||||||
|
Left-Hand-Side Expressions
|
||||||
|
OptionalExpression
|
||||||
|
MemberExpression [PrimaryExpression Identifier] OptionalChain
|
||||||
|
OptionalChain OptionalChain ?.[Expression]
|
||||||
|
features: [optional-chaining]
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function checkAssertions() {
|
||||||
|
assert.sameValue(await {a: [11]}?.a[0], 11);
|
||||||
|
const b = {c: [22, 33]};
|
||||||
|
assert.sameValue(b?.c[await Promise.resolve(1)], 33);
|
||||||
|
function e(val) {
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
assert.sameValue({d: e}?.d(await Promise.resolve([44, 55]))[1], 55);
|
||||||
|
assert.sameValue(undefined?.arr[
|
||||||
|
await Promise.reject(new Error('unreachable'))
|
||||||
|
], undefined);
|
||||||
|
}
|
||||||
|
checkAssertions().then($DONE, $DONE);
|
|
@ -0,0 +1,24 @@
|
||||||
|
// Copyright 2019 Google, Inc. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: prod-OptionalExpression
|
||||||
|
description: >
|
||||||
|
optional chain expansions in an async context
|
||||||
|
info: |
|
||||||
|
Left-Hand-Side Expressions
|
||||||
|
OptionalExpression
|
||||||
|
MemberExpression [PrimaryExpression Identifier] OptionalChain
|
||||||
|
OptionalChain ?.[Expression]
|
||||||
|
features: [optional-chaining]
|
||||||
|
flags: [async]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
async function checkAssertions() {
|
||||||
|
assert.sameValue(await [11]?.[0], 11);
|
||||||
|
assert.sameValue([22, 33]?.[await Promise.resolve(1)], 33);
|
||||||
|
assert.sameValue([44, await Promise.resolve(55)]?.[1], 55);
|
||||||
|
assert.sameValue(undefined?.[
|
||||||
|
await Promise.reject(new Error('unreachable'))
|
||||||
|
], undefined);
|
||||||
|
}
|
||||||
|
checkAssertions().then($DONE, $DONE);
|
Loading…
Reference in New Issue