Skip to content

Commit 37fe16a

Browse files
committed
LibJS: Add Function.prototype and make "new" Objects delegate to it
1 parent 0593ce4 commit 37fe16a

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

Libraries/LibJS/AST.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ Value CallExpression::execute(Interpreter& interpreter) const
8383
Object* new_object = nullptr;
8484
if (is_new_expression()) {
8585
new_object = interpreter.heap().allocate<Object>();
86+
auto prototype = function->get("prototype");
87+
if (prototype.has_value() && prototype.value().is_object())
88+
new_object->set_prototype(prototype.value().as_object());
8689
call_frame.this_value = new_object;
8790
} else {
8891
if (m_callee->is_member_expression()) {

Libraries/LibJS/Runtime/Function.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,16 @@
2424
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2525
*/
2626

27+
#include <AK/FlyString.h>
28+
#include <LibJS/Heap/Heap.h>
2729
#include <LibJS/Runtime/Function.h>
2830
#include <LibJS/Runtime/Value.h>
2931

3032
namespace JS {
3133

3234
Function::Function()
3335
{
36+
put("prototype", heap().allocate<Object>());
3437
}
3538

3639
Function::~Function()

0 commit comments

Comments
 (0)