From e1bbc7c07515a3ba69f9433818b2f78c6b25389b Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 28 Nov 2020 15:57:25 +0100 Subject: [PATCH] LibJS: Make JS::Value constructors take const cell pointers Taking non-const cell pointers is asking for trouble, since passing e.g a "const Object*" to Value(Object*) will actually call Value(bool), which is most likely not what you want. --- Libraries/LibJS/Runtime/Value.h | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/Libraries/LibJS/Runtime/Value.h b/Libraries/LibJS/Runtime/Value.h index e86ec76124..c7a0c3d078 100644 --- a/Libraries/LibJS/Runtime/Value.h +++ b/Libraries/LibJS/Runtime/Value.h @@ -120,40 +120,40 @@ public: m_value.as_double = value; } - Value(Object* object) + Value(const Object* object) : m_type(object ? Type::Object : Type::Null) { - m_value.as_object = object; + m_value.as_object = const_cast(object); } - Value(PrimitiveString* string) + Value(const PrimitiveString* string) : m_type(Type::String) { - m_value.as_string = string; + m_value.as_string = const_cast(string); } - Value(Symbol* symbol) + Value(const Symbol* symbol) : m_type(Type::Symbol) { - m_value.as_symbol = symbol; + m_value.as_symbol = const_cast(symbol); } - Value(Accessor* accessor) + Value(const Accessor* accessor) : m_type(Type::Accessor) { - m_value.as_accessor = accessor; + m_value.as_accessor = const_cast(accessor); } - Value(BigInt* bigint) + Value(const BigInt* bigint) : m_type(Type::BigInt) { - m_value.as_bigint = bigint; + m_value.as_bigint = const_cast(bigint); } - Value(NativeProperty* native_property) + Value(const NativeProperty* native_property) : m_type(Type::NativeProperty) { - m_value.as_native_property = native_property; + m_value.as_native_property = const_cast(native_property); } explicit Value(Type type)