Debian Codegraph @

js/src/tests/test262/language/expressions/optional-chaining/optional-call-preserves-this.js

raw
1 // Copyright (C) 2019 Sony Interactive Entertainment Inc. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3 /*---
4 esid: sec-optional-chaining-chain-evaluation
5 description: >
6 optional call must preserve this context, as with a non-optional call
7 info: |
8 OptionalChain : ?. Arguments
9 1. Let thisChain be this OptionalChain.
10 2. Let tailCall be IsInTailPosition(thisChain).
11 3. Return ? EvaluateCall(baseValue, baseReference, Arguments, tailCall).
12 features: [optional-chaining]
13 ---*/
14
15 const a = {
16 b() { return this._b; },
17 _b: { c: 42 }
18 };
19
20 assert.sameValue(a?.b().c, 42);
21 assert.sameValue((a?.b)().c, 42);
22
23 assert.sameValue(a.b?.().c, 42);
24 assert.sameValue((a.b)?.().c, 42);
25
26 assert.sameValue(a?.b?.().c, 42);
27 assert.sameValue((a?.b)?.().c, 42);
28
29 reportCompare(0, 0);