mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:52:43 +00:00 
			
		
		
		
	 d218a68296
			
		
	
	
		d218a68296
		
	
	
	
	
		
			
			Although not quite like the spec says the web reality is that a lhs target of CallExpression should not give a SyntaxError but only a ReferenceError once executed.
		
			
				
	
	
		
			55 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			55 lines
		
	
	
	
		
			1.7 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| test("assignment to function call", () => {
 | |
|     expect(() => {
 | |
|         function foo() {}
 | |
|         foo() = "foo";
 | |
|     }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
 | |
| });
 | |
| 
 | |
| test("assignment to function call in strict mode", () => {
 | |
|     expect("'use strict'; foo() = 'foo'").toEval();
 | |
| });
 | |
| 
 | |
| test("assignment to inline function call", () => {
 | |
|     expect(() => {
 | |
|         (function () {})() = "foo";
 | |
|     }).toThrowWithMessage(ReferenceError, "Invalid left-hand side in assignment");
 | |
| });
 | |
| 
 | |
| test("assignment to invalid LHS is syntax error", () => {
 | |
|     expect("1 += 1").not.toEval();
 | |
|     expect("1 -= 1").not.toEval();
 | |
|     expect("1 *= 1").not.toEval();
 | |
|     expect("1 /= 1").not.toEval();
 | |
|     expect("1 %= 1").not.toEval();
 | |
|     expect("1 **= 1").not.toEval();
 | |
|     expect("1 &= 1").not.toEval();
 | |
|     expect("1 |= 1").not.toEval();
 | |
|     expect("1 ^= 1").not.toEval();
 | |
|     expect("1 <<= 1").not.toEval();
 | |
|     expect("1 >>= 1").not.toEval();
 | |
|     expect("1 >>>= 1").not.toEval();
 | |
|     expect("1 = 1").not.toEval();
 | |
|     expect("1 &&= 1").not.toEval();
 | |
|     expect("1 ||= 1").not.toEval();
 | |
|     expect("1 ??= 1").not.toEval();
 | |
| });
 | |
| 
 | |
| test("assignment to call LHS is only syntax error for new operators", () => {
 | |
|     expect("f() += 1").toEval();
 | |
|     expect("f() -= 1").toEval();
 | |
|     expect("f() *= 1").toEval();
 | |
|     expect("f() /= 1").toEval();
 | |
|     expect("f() %= 1").toEval();
 | |
|     expect("f() **= 1").toEval();
 | |
|     expect("f() &= 1").toEval();
 | |
|     expect("f() |= 1").toEval();
 | |
|     expect("f() ^= 1").toEval();
 | |
|     expect("f() <<= 1").toEval();
 | |
|     expect("f() >>= 1").toEval();
 | |
|     expect("f() >>>= 1").toEval();
 | |
|     expect("f() = 1").toEval();
 | |
| 
 | |
|     expect("f() &&= 1").not.toEval();
 | |
|     expect("f() ||= 1").not.toEval();
 | |
|     expect("f() ??= 1").not.toEval();
 | |
| });
 |