Просмотр исходного кода

LibJS: Add Object constructor allowing null prototype

Linus Groh 3 лет назад
Родитель
Сommit
368af9ad6e
2 измененных файлов с 10 добавлено и 2 удалено
  1. 8 1
      Userland/Libraries/LibJS/Runtime/Object.cpp
  2. 2 1
      Userland/Libraries/LibJS/Runtime/Object.h

+ 8 - 1
Userland/Libraries/LibJS/Runtime/Object.cpp

@@ -1,6 +1,6 @@
 /*
 /*
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
@@ -44,6 +44,13 @@ Object::Object(ConstructWithoutPrototypeTag, GlobalObject& global_object)
     m_shape = heap().allocate_without_global_object<Shape>(global_object);
     m_shape = heap().allocate_without_global_object<Shape>(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)
 Object::Object(Object& prototype)
 {
 {
     m_shape = prototype.global_object().empty_object_shape();
     m_shape = prototype.global_object().empty_object_shape();

+ 2 - 1
Userland/Libraries/LibJS/Runtime/Object.h

@@ -1,6 +1,6 @@
 /*
 /*
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
- * Copyright (c) 2020-2021, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2020-2022, Linus Groh <linusg@serenityos.org>
  *
  *
  * SPDX-License-Identifier: BSD-2-Clause
  * SPDX-License-Identifier: BSD-2-Clause
  */
  */
@@ -45,6 +45,7 @@ class Object : public Cell {
 public:
 public:
     static Object* create(GlobalObject&, Object* prototype);
     static Object* create(GlobalObject&, Object* prototype);
 
 
+    Object(GlobalObject&, Object* prototype);
     explicit Object(Object& prototype);
     explicit Object(Object& prototype);
     explicit Object(Shape&);
     explicit Object(Shape&);
     virtual void initialize(GlobalObject&) override;
     virtual void initialize(GlobalObject&) override;