1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:27:45 +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

@ -10,7 +10,7 @@ namespace JS::Intl {
// 10 Collator Objects, https://tc39.es/ecma402/#collator-objects
Collator::Collator(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -26,7 +26,7 @@ static Crypto::SignedBigInteger const s_one_million_bigint { 1'000'000 };
// 11 DateTimeFormat Objects, https://tc39.es/ecma402/#datetimeformat-objects
DateTimeFormat::DateTimeFormat(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -12,7 +12,7 @@ namespace JS::Intl {
// 12 DisplayNames Objects, https://tc39.es/ecma402/#intl-displaynames-objects
DisplayNames::DisplayNames(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -20,7 +20,7 @@ namespace JS::Intl {
// 1 DurationFormat Objects, https://tc39.es/proposal-intl-duration-format/#durationformat-objects
DurationFormat::DurationFormat(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -28,7 +28,7 @@ namespace JS::Intl {
// 8 The Intl Object, https://tc39.es/ecma402/#intl-object
Intl::Intl(Realm& realm)
: Object(*realm.intrinsics().object_prototype())
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().object_prototype())
{
}

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 13 ListFormat Objects, https://tc39.es/ecma402/#listformat-objects
ListFormat::ListFormat(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -21,12 +21,12 @@ NonnullGCPtr<Locale> Locale::create(Realm& realm, ::Locale::LocaleID const& loca
// 14 Locale Objects, https://tc39.es/ecma402/#locale-objects
Locale::Locale(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}
Locale::Locale(::Locale::LocaleID const& locale_id, Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
set_locale(locale_id.to_deprecated_string());

View file

@ -21,7 +21,7 @@
namespace JS::Intl {
NumberFormatBase::NumberFormatBase(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -17,7 +17,7 @@ namespace JS::Intl {
// 17 RelativeTimeFormat Objects, https://tc39.es/ecma402/#relativetimeformat-objects
RelativeTimeFormat::RelativeTimeFormat(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -24,7 +24,7 @@ NonnullGCPtr<SegmentIterator> SegmentIterator::create(Realm& realm, Segmenter& s
// 18.6 Segment Iterator Objects, https://tc39.es/ecma402/#sec-segment-iterator-objects
SegmentIterator::SegmentIterator(Realm& realm, Segmenter& segmenter, Utf16View const& string, Segments const& segments)
: Object(*realm.intrinsics().intl_segment_iterator_prototype())
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().intl_segment_iterator_prototype())
, m_iterating_segmenter(segmenter)
, m_iterated_string(string)
, m_segments(segments)

View file

@ -14,7 +14,7 @@ namespace JS::Intl {
// 18 Segmenter Objects, https://tc39.es/ecma402/#segmenter-objects
Segmenter::Segmenter(Object& prototype)
: Object(prototype)
: Object(ConstructWithPrototypeTag::Tag, prototype)
{
}

View file

@ -23,7 +23,7 @@ NonnullGCPtr<Segments> Segments::create(Realm& realm, Segmenter& segmenter, Utf1
// 18.5 Segments Objects, https://tc39.es/ecma402/#sec-segments-objects
Segments::Segments(Realm& realm, Segmenter& segmenter, Utf16String string)
: Object(*realm.intrinsics().intl_segments_prototype())
: Object(ConstructWithPrototypeTag::Tag, *realm.intrinsics().intl_segments_prototype())
, m_segments_segmenter(segmenter)
, m_segments_string(move(string))
{