diff options
Diffstat (limited to 'js/src/tests/test262/language/expressions/optional-chaining/optional-chain-prod-expression.js')
-rw-r--r-- | js/src/tests/test262/language/expressions/optional-chaining/optional-chain-prod-expression.js | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/js/src/tests/test262/language/expressions/optional-chaining/optional-chain-prod-expression.js b/js/src/tests/test262/language/expressions/optional-chaining/optional-chain-prod-expression.js new file mode 100644 index 0000000000..dfde4d26c2 --- /dev/null +++ b/js/src/tests/test262/language/expressions/optional-chaining/optional-chain-prod-expression.js @@ -0,0 +1,44 @@ +// Copyright 2020 Salesforce.com, Inc. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. +/*--- +esid: prod-OptionalExpression +description: > + Productions for ?. [Expression] +info: | + OptionalChain: + ?.[ Expression ] +features: [optional-chaining] +---*/ + +const $ = 'x'; +const arr = [39, 42]; + +arr.true = 'prop'; +arr[1.1] = 'other prop'; + +const obj = { + a: 'hello', + undefined: 40, + $: 0, + NaN: 41, + null: 42, + x: 43, + true: 44 +}; + +assert.sameValue(arr?.[0], 39, '[0]'); +assert.sameValue(arr?.[0, 1], 42, '[0, 1]'); +assert.sameValue(arr?.[1], 42, '[1]'); +assert.sameValue(arr?.[1, 0], 39, '[1, 0]'); +assert.sameValue(arr?.[{}, NaN, undefined, 2, 0, 10 / 10], 42, '[{}, NaN, undefined, 2, 0, 10 / 10]'); +assert.sameValue(arr?.[true], 'prop', '[true]'); +assert.sameValue(arr?.[1.1], 'other prop', '[1.1]'); + +assert.sameValue(obj?.[undefined], 40, '[undefined]'); +assert.sameValue(obj?.[NaN], 41, '[NaN]'); +assert.sameValue(obj?.[null], 42, '[null]'); +assert.sameValue(obj?.['$'], 0, '["$"]'); +assert.sameValue(obj?.[$], 43, '[$]'); +assert.sameValue(obj?.[true], 44, '[true]'); + +reportCompare(0, 0); |