Debian Codegraph @

js/src/tests/test262/language/expressions/logical-assignment/lgcl-and-assignment-operator-lhs-before-rhs.js

raw
1 // Copyright (c) 2020 Ecma International. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
3
4 /*---
5 esid: sec-assignment-operators-runtime-semantics-evaluation
6 description: >
7 The LeftHandSideExpression is evaluated before the AssignmentExpression.
8 features: [logical-assignment-operators]
9
10 ---*/
11
12 function DummyError() { }
13
14 assert.throws(DummyError, function() {
15 var base = null;
16 var prop = function() {
17 throw new DummyError();
18 };
19 var expr = function() {
20 throw new Test262Error("right-hand side expression evaluated");
21 };
22
23 base[prop()] &&= expr();
24 });
25
26 assert.throws(TypeError, function() {
27 var base = null;
28 var prop = {
29 toString: function() {
30 throw new Test262Error("property key evaluated");
31 }
32 };
33 var expr = function() {
34 throw new Test262Error("right-hand side expression evaluated");
35 };
36
37 base[prop] &&= expr();
38 });
39
40 var count = 0;
41 var obj = {};
42 function incr() {
43 return ++count;
44 }
45
46 assert.sameValue(obj[incr()] &&= incr(), undefined, "obj[incr()] &&= incr()");
47 assert.sameValue(obj[1], undefined, "obj[1]");
48 assert.sameValue(count, 1, "count");
49
50 obj[2] = 1;
51 assert.sameValue(obj[incr()] &&= incr(), 3, "obj[incr()] &&= incr()");
52 assert.sameValue(obj[2], 3, "obj[2]");
53 assert.sameValue(count, 3, "count");
54
55 reportCompare(0, 0);