Debian Codegraph @

js/src/tests/test262/language/expressions/in/private-field-rhs-non-object.js

raw
1 // Copyright 2021 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 description: Algorithm interrupted by non-object right-hand side
6 info: |
7 Syntax
8 RelationalExpression[In, Yield, Await]:
9 [...]
10 [+In]PrivateIdentifier in ShiftExpression[?Yield, ?Await]
11
12 [...]
13
14 1. Let privateIdentifier be the StringValue of PrivateIdentifier.
15 2. Let rref be the result of evaluating ShiftExpression.
16 3. Let rval be ? GetValue(rref).
17 4. If Type(rval) is not Object, throw a TypeError exception.
18 esid: sec-relational-operators-runtime-semantics-evaluation
19 features: [class-fields-private, class-fields-private-in]
20 ---*/
21
22 let caught = null;
23
24 class C {
25 #field;
26
27 constructor() {
28 try {
29 /**
30 * Using a ShiftExpression to produce the non-object value verifies that
31 * the implementation uses the operator precedence implied by the
32 * syntactic grammar. In other words, the following statement should be
33 * interpreted as:
34 *
35 * #field in ({} << 0);
36 *
37 * ...rather than:
38 *
39 * (#field in {}) << 0;
40 */
41 #field in {} << 0;
42 } catch (error) {
43 caught = error;
44 }
45 }
46 }
47
48 new C();
49
50 assert.notSameValue(caught, null);
51 assert.sameValue(caught.constructor, TypeError);
52
53 reportCompare(0, 0);