diff --git a/Libraries/LibJS/AST.cpp b/Libraries/LibJS/AST.cpp index d5f8da6323..196901851d 100644 --- a/Libraries/LibJS/AST.cpp +++ b/Libraries/LibJS/AST.cpp @@ -83,6 +83,9 @@ Value CallExpression::execute(Interpreter& interpreter) const Object* new_object = nullptr; if (is_new_expression()) { new_object = interpreter.heap().allocate(); + auto prototype = function->get("prototype"); + if (prototype.has_value() && prototype.value().is_object()) + new_object->set_prototype(prototype.value().as_object()); call_frame.this_value = new_object; } else { if (m_callee->is_member_expression()) { diff --git a/Libraries/LibJS/Runtime/Function.cpp b/Libraries/LibJS/Runtime/Function.cpp index 5f3d87a25a..c810237e8b 100644 --- a/Libraries/LibJS/Runtime/Function.cpp +++ b/Libraries/LibJS/Runtime/Function.cpp @@ -24,6 +24,8 @@ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ +#include +#include #include #include @@ -31,6 +33,7 @@ namespace JS { Function::Function() { + put("prototype", heap().allocate()); } Function::~Function()