mirror of
				https://github.com/tc39/test262.git
				synced 2025-10-30 19:24:12 +01:00 
			
		
		
		
	There were three things wrong with the 'and', 'or', and 'nullish' tests that I added as part of #2940: 1. They were in the wrong folder (should be expressions/logical-assignment, not expressions/compound-assignment) 2. The tests for ||= and ??= on readonly accessor properties were incorrect. These assignments would short-circuit if the getter returned 1 as it previously did, so PutValue would not throw. 3. The tests for ||= and ??= on private methods were invalid, as a method always evaluates to true in a boolean context, and is not nullish, so these would always short-circuit. I've removed the invalid private method cases, fixed the readonly accessor cases, and added new templates to test the short-circuit behaviour as well as the non-short-circuit behaviour. Closes: #3413
		
			
				
	
	
		
			51 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.8 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // This file was procedurally generated from the following sources:
 | |
| // - src/logical-assignment-private/nullish.case
 | |
| // - src/logical-assignment-private/default/getter.template
 | |
| /*---
 | |
| description: Nullish-coalescing assignment with target being a private reference (to an accessor property with getter)
 | |
| esid: sec-assignment-operators-runtime-semantics-evaluation
 | |
| features: [class-fields-private, logical-assignment-operators]
 | |
| flags: [generated]
 | |
| info: |
 | |
|     sec-property-accessors-runtime-semantics-evaluation
 | |
|     MemberExpression : MemberExpression `.` PrivateIdentifier
 | |
| 
 | |
|       1. Let _baseReference_ be the result of evaluating |MemberExpression|.
 | |
|       2. Let _baseValue_ be ? GetValue(_baseReference_).
 | |
|       3. Let _fieldNameString_ be the StringValue of |PrivateIdentifier|.
 | |
|       4. Return ! MakePrivateReference(_baseValue_, _fieldNameString_).
 | |
| 
 | |
|     PutValue (V, W)
 | |
|       ...
 | |
|       5.b. If IsPrivateReference(_V_) is *true*, then
 | |
|         i. Return ? PrivateSet(_baseObj_, _V_.[[ReferencedName]], _W_).
 | |
| 
 | |
|     PrivateSet (O, P, value)
 | |
|       ...
 | |
|       5.a. Assert: _entry_.[[Kind]] is ~accessor~.
 | |
|       b. If _entry_.[[Set]] is *undefined*, throw a *TypeError* exception.
 | |
| 
 | |
| 
 | |
|     sec-assignment-operators-runtime-semantics-evaluation
 | |
|     AssignmentExpression : LeftHandSideExpression ??= AssignmentExpression
 | |
|       1. Let _lref_ be the result of evaluating |LeftHandSideExpression|.
 | |
|       2. Let _lval_ be ? GetValue(_lref_).
 | |
|       3. If _lval_ is neither *undefined* nor *null*, return _lval_.
 | |
|       ...
 | |
|       6. Perform ? PutValue(_lref_, _rval_).
 | |
|       7. Return _rval_.
 | |
| ---*/
 | |
| 
 | |
| 
 | |
| class C {
 | |
|   get #field() {
 | |
|     return null;
 | |
|   }
 | |
|   compoundAssignment() {
 | |
|     return this.#field ??= 1;
 | |
|   }
 | |
| }
 | |
| 
 | |
| const o = new C();
 | |
| assert.throws(TypeError, () => o.compoundAssignment(), "PutValue throws when storing the result if no setter");
 |