1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibJS: Remove Object(Object& prototype) footgun

This constructor was easily confused with a copy constructor, and it was
possible to accidentally copy-construct Objects in at least one way that
we dicovered (via generic ThrowCompletionOr construction).

This patch adds a mandatory ConstructWithPrototypeTag parameter to the
constructor to disambiguate it.
This commit is contained in:
Andreas Kling 2022-12-14 12:17:58 +01:00
parent 42b5c896e8
commit 4abdb68655
90 changed files with 100 additions and 99 deletions

View file

@ -34,7 +34,7 @@ NonnullGCPtr<Object> Object::create(Realm& realm, Object* prototype)
else if (prototype == realm.intrinsics().object_prototype())
return *realm.heap().allocate<Object>(realm, *realm.intrinsics().new_object_shape());
else
return *realm.heap().allocate<Object>(realm, *prototype);
return *realm.heap().allocate<Object>(realm, ConstructWithPrototypeTag::Tag, *prototype);
}
Object::Object(GlobalObjectTag, Realm& realm)
@ -56,7 +56,7 @@ Object::Object(Realm& realm, Object* prototype)
set_prototype(prototype);
}
Object::Object(Object& prototype)
Object::Object(ConstructWithPrototypeTag, Object& prototype)
{
m_shape = prototype.shape().realm().intrinsics().empty_object_shape();
VERIFY(m_shape);