mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 09:02:43 +00:00 
			
		
		
		
	LibJS: Allow null or undefined as a bound |this| value in strict mode
This commit is contained in:
		
							parent
							
								
									870bcaeef6
								
							
						
					
					
						commit
						b0932b0aec
					
				
					 2 changed files with 12 additions and 9 deletions
				
			
		|  | @ -57,7 +57,8 @@ BoundFunction* Function::bind(Value bound_this_value, Vector<Value> arguments) | ||||||
|         switch (bound_this_value.type()) { |         switch (bound_this_value.type()) { | ||||||
|         case Value::Type::Undefined: |         case Value::Type::Undefined: | ||||||
|         case Value::Type::Null: |         case Value::Type::Null: | ||||||
|             // FIXME: Null or undefined should be passed through in strict mode.
 |             if (interpreter().in_strict_mode()) | ||||||
|  |                 return bound_this_value; | ||||||
|             return &interpreter().global_object(); |             return &interpreter().global_object(); | ||||||
|         default: |         default: | ||||||
|             return bound_this_value.to_object(interpreter()); |             return bound_this_value.to_object(interpreter()); | ||||||
|  |  | ||||||
|  | @ -103,15 +103,17 @@ try { | ||||||
|     assert(Make5() === 5); |     assert(Make5() === 5); | ||||||
|     assert(new Make5().valueOf() === 5); |     assert(new Make5().valueOf() === 5); | ||||||
| 
 | 
 | ||||||
|     // FIXME: Uncomment me when strict mode is implemented
 |     // Null or undefined should be passed through as a |this| value in strict mode.
 | ||||||
|     //     function strictIdentity() {
 |     (() => { | ||||||
|     //         return this;
 |       "use strict"; | ||||||
|     //     }
 |       function strictIdentity() { | ||||||
|  |         return this; | ||||||
|  |       } | ||||||
| 
 | 
 | ||||||
|     //     assert(strictIdentity.bind()() === undefined);
 |       assert(strictIdentity.bind()() === undefined); | ||||||
|     //     assert(strictIdentity.bind(null)() === null);
 |       assert(strictIdentity.bind(null)() === null); | ||||||
|     //     assert(strictIdentity.bind(undefined)() === undefined);
 |       assert(strictIdentity.bind(undefined)() === undefined); | ||||||
|     // })();
 |     })(); | ||||||
| 
 | 
 | ||||||
|     // Arrow functions can not have their |this| value set.
 |     // Arrow functions can not have their |this| value set.
 | ||||||
|     assert((() => this).bind("foo")() === globalThis) |     assert((() => this).bind("foo")() === globalThis) | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Jack Karamanian
						Jack Karamanian