1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 21:28:14 +00:00

AK: Simplify constructors and conversions from nullptr_t

Problem:
- Many constructors are defined as `{}` rather than using the ` =
  default` compiler-provided constructor.
- Some types provide an implicit conversion operator from `nullptr_t`
  instead of requiring the caller to default construct. This violates
  the C++ Core Guidelines suggestion to declare single-argument
  constructors explicit
  (https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c46-by-default-declare-single-argument-constructors-explicit).

Solution:
- Change default constructors to use the compiler-provided default
  constructor.
- Remove implicit conversion operators from `nullptr_t` and change
  usage to enforce type consistency without conversion.
This commit is contained in:
Lenny Maiorani 2021-01-10 16:29:28 -07:00 committed by Andreas Kling
parent 9dc44bf8c4
commit e6f907a155
105 changed files with 300 additions and 244 deletions

View file

@ -43,7 +43,7 @@ void ArrayBufferPrototype::initialize(GlobalObject& global_object)
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_function(vm.names.slice, slice, 2, attr);
// FIXME: This should be an accessor property
define_native_property(vm.names.byteLength, byte_length_getter, nullptr, Attribute::Configurable);
define_native_property(vm.names.byteLength, byte_length_getter, {}, Attribute::Configurable);
define_property(vm.well_known_symbol_to_string_tag(), js_string(vm.heap(), "ArrayBuffer"), Attribute::Configurable);
}

View file

@ -45,7 +45,7 @@ void ErrorPrototype::initialize(GlobalObject& global_object)
Object::initialize(global_object);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_property(vm.names.name, name_getter, name_setter, attr);
define_native_property(vm.names.message, message_getter, nullptr, attr);
define_native_property(vm.names.message, message_getter, {}, attr);
define_native_function(vm.names.toString, to_string, 0, attr);
}

View file

@ -50,11 +50,11 @@ void RegExpPrototype::initialize(GlobalObject& global_object)
define_native_function(vm.names.exec, exec, 1, attr);
u8 readable_attr = Attribute::Configurable;
define_native_property(vm.names.flags, flags, nullptr, readable_attr);
define_native_property(vm.names.source, source, nullptr, readable_attr);
define_native_property(vm.names.flags, flags, {}, readable_attr);
define_native_property(vm.names.source, source, {}, readable_attr);
#define __JS_ENUMERATE(flagName, flag_name, flag_char, ECMAScriptFlagName) \
define_native_property(vm.names.flagName, flag_name, nullptr, readable_attr);
define_native_property(vm.names.flagName, flag_name, {}, readable_attr);
JS_ENUMERATE_REGEXP_FLAGS
#undef __JS_ENUMERATE
}

View file

@ -73,8 +73,8 @@ void ScriptFunction::initialize(GlobalObject& global_object)
prototype->define_property(vm.names.constructor, this, Attribute::Writable | Attribute::Configurable);
define_property(vm.names.prototype, prototype, Attribute::Writable);
}
define_native_property(vm.names.length, length_getter, nullptr, Attribute::Configurable);
define_native_property(vm.names.name, name_getter, nullptr, Attribute::Configurable);
define_native_property(vm.names.length, length_getter, {}, Attribute::Configurable);
define_native_property(vm.names.name, name_getter, {}, Attribute::Configurable);
}
ScriptFunction::~ScriptFunction()

View file

@ -82,7 +82,7 @@ void StringPrototype::initialize(GlobalObject& global_object)
StringObject::initialize(global_object);
u8 attr = Attribute::Writable | Attribute::Configurable;
define_native_property(vm.names.length, length_getter, nullptr, 0);
define_native_property(vm.names.length, length_getter, {}, 0);
define_native_function(vm.names.charAt, char_at, 1, attr);
define_native_function(vm.names.charCodeAt, char_code_at, 1, attr);
define_native_function(vm.names.repeat, repeat, 1, attr);

View file

@ -47,7 +47,7 @@ void SymbolPrototype::initialize(GlobalObject& global_object)
{
auto& vm = this->vm();
Object::initialize(global_object);
define_native_property(vm.names.description, description_getter, nullptr, Attribute::Configurable);
define_native_property(vm.names.description, description_getter, {}, Attribute::Configurable);
define_native_function(vm.names.toString, to_string, 0, Attribute::Writable | Attribute::Configurable);
define_native_function(vm.names.valueOf, value_of, 0, Attribute::Writable | Attribute::Configurable);

View file

@ -40,7 +40,7 @@ void TypedArrayPrototype::initialize(GlobalObject& object)
auto& vm = this->vm();
Object::initialize(object);
// FIXME: This should be an accessor property
define_native_property(vm.names.length, length_getter, nullptr, Attribute::Configurable);
define_native_property(vm.names.length, length_getter, {}, Attribute::Configurable);
}
TypedArrayPrototype::~TypedArrayPrototype()

View file

@ -42,7 +42,7 @@ Uint8ClampedArray::Uint8ClampedArray(u32 length, Object& prototype)
, m_length(length)
{
auto& vm = this->vm();
define_native_property(vm.names.length, length_getter, nullptr);
define_native_property(vm.names.length, length_getter, {});
m_data = (u8*)calloc(m_length, 1);
}