Browse Source

LibJS/Bytecode: Make construct Call throw if callee isn't a constructor

Luke Wilde 3 years ago
parent
commit
096d2bb772
1 changed files with 5 additions and 1 deletions
  1. 5 1
      Userland/Libraries/LibJS/Bytecode/Op.cpp

+ 5 - 1
Userland/Libraries/LibJS/Bytecode/Op.cpp

@@ -411,9 +411,13 @@ ThrowCompletionOr<void> JumpUndefined::execute_impl(Bytecode::Interpreter& inter
 ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) const
 ThrowCompletionOr<void> Call::execute_impl(Bytecode::Interpreter& interpreter) const
 {
 {
     auto callee = interpreter.reg(m_callee);
     auto callee = interpreter.reg(m_callee);
-    if (!callee.is_function())
+
+    if (m_type == CallType::Call && !callee.is_function())
         return interpreter.vm().throw_completion<TypeError>(interpreter.global_object(), ErrorType::IsNotA, callee.to_string_without_side_effects(), "function"sv);
         return interpreter.vm().throw_completion<TypeError>(interpreter.global_object(), ErrorType::IsNotA, callee.to_string_without_side_effects(), "function"sv);
 
 
+    if (m_type == CallType::Construct && !callee.is_constructor())
+        return interpreter.vm().throw_completion<TypeError>(interpreter.global_object(), ErrorType::IsNotA, callee.to_string_without_side_effects(), "constructor"sv);
+
     auto& function = callee.as_function();
     auto& function = callee.as_function();
 
 
     auto this_value = interpreter.reg(m_this_value);
     auto this_value = interpreter.reg(m_this_value);