mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:12:43 +00:00 
			
		
		
		
	 e875513ff7
			
		
	
	
		e875513ff7
		
	
	
	
	
		
			
			This fixes an issue where `undefined.foo = "bar"` would throw a ReferenceError instead of a TypeError as undefined was also used for truly unresolvable references (e.g. `foo() = "bar"`). I also made the various error messages here a bit nicer, just "primitive value" is not very helpful.
		
			
				
	
	
		
			29 lines
		
	
	
	
		
			969 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			29 lines
		
	
	
	
		
			969 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| "use strict";
 | |
| 
 | |
| test("basic functionality", () => {
 | |
|     [true, false, "foo", 123].forEach(primitive => {
 | |
|         expect(() => {
 | |
|             primitive.foo = "bar";
 | |
|         }).toThrowWithMessage(
 | |
|             TypeError,
 | |
|             `Cannot set property 'foo' of ${typeof primitive} '${primitive}'`
 | |
|         );
 | |
|         expect(() => {
 | |
|             primitive[Symbol.hasInstance] = 123;
 | |
|         }).toThrowWithMessage(
 | |
|             TypeError,
 | |
|             `Cannot set property 'Symbol(Symbol.hasInstance)' of ${typeof primitive} '${primitive}'`
 | |
|         );
 | |
|     });
 | |
|     [null, undefined].forEach(primitive => {
 | |
|         expect(() => {
 | |
|             primitive.foo = "bar";
 | |
|         }).toThrowWithMessage(TypeError, `Cannot set property 'foo' of ${primitive}`);
 | |
|         expect(() => {
 | |
|             primitive[Symbol.hasInstance] = 123;
 | |
|         }).toThrowWithMessage(
 | |
|             TypeError,
 | |
|             `Cannot set property 'Symbol(Symbol.hasInstance)' of ${primitive}`
 | |
|         );
 | |
|     });
 | |
| });
 |