diff --git a/Libraries/LibJS/Runtime/Value.cpp b/Libraries/LibJS/Runtime/Value.cpp index 7c05fe3468..953a3b70ad 100644 --- a/Libraries/LibJS/Runtime/Value.cpp +++ b/Libraries/LibJS/Runtime/Value.cpp @@ -711,8 +711,10 @@ Value instance_of(GlobalObject& global_object, Value lhs, Value rhs) vm.throw_exception(global_object, ErrorType::NotAFunction, has_instance_method.to_string_without_side_effects()); return {}; } - - return Value(vm.call(has_instance_method.as_function(), rhs, lhs).to_boolean()); + auto has_instance_result = vm.call(has_instance_method.as_function(), rhs, lhs); + if (vm.exception()) + return {}; + return Value(has_instance_result.to_boolean()); } if (!rhs.is_function()) { @@ -743,7 +745,7 @@ Value ordinary_has_instance(GlobalObject& global_object, Value lhs, Value rhs) return {}; if (!rhs_prototype.is_object()) { - vm.throw_exception(global_object, ErrorType::InstanceOfOperatorBadPrototype, rhs_prototype.to_string_without_side_effects()); + vm.throw_exception(global_object, ErrorType::InstanceOfOperatorBadPrototype, rhs.to_string_without_side_effects()); return {}; } while (true) { diff --git a/Libraries/LibJS/Tests/operators/instanceof-basic.js b/Libraries/LibJS/Tests/operators/instanceof-basic.js index e1050b7c02..3d2b38c496 100644 --- a/Libraries/LibJS/Tests/operators/instanceof-basic.js +++ b/Libraries/LibJS/Tests/operators/instanceof-basic.js @@ -22,3 +22,15 @@ test("derived ES5 classes", () => { 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); +});