mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 16:12:44 +00:00 
			
		
		
		
	 565a26808d
			
		
	
	
		565a26808d
		
	
	
	
	
		
			
			Two issues:
- throw_exception() with ErrorType::InstanceOfOperatorBadPrototype would
  receive rhs_prototype.to_string_without_side_effects(), which would
  ASSERT_NOT_REACHED() as to_string_without_side_effects() must not be
  called on an empty value. It should (and now does) receive the RHS
  value instead as the message is "'prototype' property of {} is not an
  object".
- Value::instance_of() was missing an exception check after calling
  has_instance_method, to_boolean() on an empty value result would crash
  as well.
Fixes #3930.
		
	
			
		
			
				
	
	
		
			36 lines
		
	
	
	
		
			750 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			36 lines
		
	
	
	
		
			750 B
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| test("basic functionality", () => {
 | |
|     function Foo() {
 | |
|         this.x = 123;
 | |
|     }
 | |
| 
 | |
|     const foo = new Foo();
 | |
|     expect(foo instanceof Foo).toBeTrue();
 | |
| });
 | |
| 
 | |
| test("derived ES5 classes", () => {
 | |
|     function Base() {
 | |
|         this.is_base = true;
 | |
|     }
 | |
| 
 | |
|     function Derived() {
 | |
|         this.is_derived = true;
 | |
|     }
 | |
| 
 | |
|     Object.setPrototypeOf(Derived.prototype, Base.prototype);
 | |
| 
 | |
|     const d = new Derived();
 | |
|     expect(d instanceof Derived).toBeTrue();
 | |
|     expect(d instanceof Base).toBeTrue();
 | |
| });
 | |
| 
 | |
| test("issue #3930, instanceof on arrow function", () => {
 | |
|     function f() {}
 | |
|     const a = () => {};
 | |
| 
 | |
|     expect(() => {
 | |
|         f instanceof a;
 | |
|     }).toThrow(TypeError);
 | |
|     expect(() => {
 | |
|         a instanceof a;
 | |
|     }).toThrow(TypeError);
 | |
| });
 |