From 368af9ad6e9f545b88c4662a16b104a4c5a07539 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Wed, 9 Feb 2022 19:34:33 +0000 Subject: [PATCH] LibJS: Add Object constructor allowing null prototype --- Userland/Libraries/LibJS/Runtime/Object.cpp | 9 ++++++++- Userland/Libraries/LibJS/Runtime/Object.h | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibJS/Runtime/Object.cpp b/Userland/Libraries/LibJS/Runtime/Object.cpp index f78bd56b87..53c819a4a7 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.cpp +++ b/Userland/Libraries/LibJS/Runtime/Object.cpp @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling - * Copyright (c) 2020-2021, Linus Groh + * Copyright (c) 2020-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -44,6 +44,13 @@ Object::Object(ConstructWithoutPrototypeTag, GlobalObject& global_object) m_shape = heap().allocate_without_global_object(global_object); } +Object::Object(GlobalObject& global_object, Object* prototype) +{ + m_shape = global_object.empty_object_shape(); + if (prototype != nullptr) + set_prototype(prototype); +} + Object::Object(Object& prototype) { m_shape = prototype.global_object().empty_object_shape(); diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 75662d7236..49369d10b7 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2020, Andreas Kling - * Copyright (c) 2020-2021, Linus Groh + * Copyright (c) 2020-2022, Linus Groh * * SPDX-License-Identifier: BSD-2-Clause */ @@ -45,6 +45,7 @@ class Object : public Cell { public: static Object* create(GlobalObject&, Object* prototype); + Object(GlobalObject&, Object* prototype); explicit Object(Object& prototype); explicit Object(Shape&); virtual void initialize(GlobalObject&) override;