diff --git a/Userland/Libraries/LibJS/AST.cpp b/Userland/Libraries/LibJS/AST.cpp index 0b62e408481..edbaa72dec9 100644 --- a/Userland/Libraries/LibJS/AST.cpp +++ b/Userland/Libraries/LibJS/AST.cpp @@ -364,7 +364,7 @@ Value SuperCall::execute(Interpreter& interpreter, GlobalObject& global_object) return {}; // 5. If IsConstructor(func) is false, throw a TypeError exception. - if (!func || !func->value_of().is_constructor()) { + if (!func || !Value(func).is_constructor()) { vm.throw_exception(global_object, ErrorType::NotAConstructor, "Super constructor"); return {}; } diff --git a/Userland/Libraries/LibJS/Runtime/BigIntObject.h b/Userland/Libraries/LibJS/Runtime/BigIntObject.h index 461f109d799..62fd9f000c2 100644 --- a/Userland/Libraries/LibJS/Runtime/BigIntObject.h +++ b/Userland/Libraries/LibJS/Runtime/BigIntObject.h @@ -23,11 +23,6 @@ public: BigInt const& bigint() const { return m_bigint; } BigInt& bigint() { return m_bigint; } - virtual Value value_of() const override - { - return Value(&m_bigint); - } - private: virtual void visit_edges(Visitor&) override; diff --git a/Userland/Libraries/LibJS/Runtime/BooleanObject.h b/Userland/Libraries/LibJS/Runtime/BooleanObject.h index a99556865cf..27fc816648b 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanObject.h +++ b/Userland/Libraries/LibJS/Runtime/BooleanObject.h @@ -18,10 +18,7 @@ public: BooleanObject(bool, Object& prototype); virtual ~BooleanObject() override; - virtual Value value_of() const override - { - return Value(m_value); - } + bool boolean() const { return m_value; } private: bool m_value { false }; diff --git a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp index fd5abfed307..4cbae969ff5 100644 --- a/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/BooleanPrototype.cpp @@ -39,7 +39,7 @@ JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::to_string) if (!this_value.is_object() || !is(this_value.as_object())) return vm.throw_completion(global_object, ErrorType::NotAnObjectOfType, "Boolean"); - bool bool_value = static_cast(this_value.as_object()).value_of().as_bool(); + bool bool_value = static_cast(this_value.as_object()).boolean(); return js_string(vm, bool_value ? "true" : "false"); } @@ -52,6 +52,6 @@ JS_DEFINE_NATIVE_FUNCTION(BooleanPrototype::value_of) if (!this_value.is_object() || !is(this_value.as_object())) return vm.throw_completion(global_object, ErrorType::NotAnObjectOfType, "Boolean"); - return static_cast(this_value.as_object()).value_of(); + return Value(static_cast(this_value.as_object()).boolean()); } } diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h index 9251a4074bb..1b91d022ae2 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.h +++ b/Userland/Libraries/LibJS/Runtime/Date.h @@ -73,9 +73,13 @@ public: String locale_string() const { return m_datetime.to_string(); } String locale_time_string() const { return m_datetime.to_string("%H:%M:%S"); } - virtual Value value_of() const override + // https://tc39.es/ecma262/#sec-properties-of-date-instances + // [[DateValue]] + double date_value() const { - return Value(static_cast(m_datetime.timestamp() * 1000 + m_milliseconds)); + return m_is_invalid + ? NAN + : static_cast(m_datetime.timestamp() * 1000 + m_milliseconds); } private: diff --git a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp index c7b5c3f854b..a62caa3f8d5 100644 --- a/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/DatePrototype.cpp @@ -689,7 +689,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_date_string) // 1. Let x be ? thisTimeValue(this value). auto* this_object = TRY(typed_this_object(global_object)); - auto time = this_object->is_invalid() ? js_nan() : this_object->value_of(); + auto time = Value(this_object->date_value()); // 2. If x is NaN, return "Invalid Date". if (time.is_nan()) @@ -714,7 +714,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_string) // 1. Let x be ? thisTimeValue(this value). auto* this_object = TRY(typed_this_object(global_object)); - auto time = this_object->is_invalid() ? js_nan() : this_object->value_of(); + auto time = Value(this_object->date_value()); // 2. If x is NaN, return "Invalid Date". if (time.is_nan()) @@ -739,7 +739,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_locale_time_string) // 1. Let x be ? thisTimeValue(this value). auto* this_object = TRY(typed_this_object(global_object)); - auto time = this_object->is_invalid() ? js_nan() : this_object->value_of(); + auto time = Value(this_object->date_value()); // 2. If x is NaN, return "Invalid Date". if (time.is_nan()) @@ -798,7 +798,7 @@ JS_DEFINE_NATIVE_FUNCTION(DatePrototype::to_temporal_instant) { // 1. Let t be ? thisTimeValue(this value). auto* this_object = TRY(typed_this_object(global_object)); - auto t = this_object->value_of(); + auto t = Value(this_object->date_value()); // 2. Let ns be ? NumberToBigInt(t) × 10^6. auto* ns = TRY(number_to_bigint(global_object, t)); diff --git a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp index ac3fc9cd3ff..3e6dd849263 100644 --- a/Userland/Libraries/LibJS/Runtime/JSONObject.cpp +++ b/Userland/Libraries/LibJS/Runtime/JSONObject.cpp @@ -145,9 +145,9 @@ ThrowCompletionOr JSONObject::serialize_json_property(GlobalObject& glob else if (is(value_object)) value = TRY(value.to_primitive_string(global_object)); else if (is(value_object)) - value = static_cast(value_object).value_of(); + value = Value(static_cast(value_object).boolean()); else if (is(value_object)) - value = static_cast(value_object).value_of(); + value = Value(&static_cast(value_object).bigint()); } if (value.is_null()) diff --git a/Userland/Libraries/LibJS/Runtime/NumberObject.h b/Userland/Libraries/LibJS/Runtime/NumberObject.h index 5ac9e47ff4a..db96cb0ddbc 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberObject.h +++ b/Userland/Libraries/LibJS/Runtime/NumberObject.h @@ -19,8 +19,6 @@ public: NumberObject(double, Object& prototype); virtual ~NumberObject() override; - virtual Value value_of() const override { return Value(m_value); } - double number() const { return m_value; } private: diff --git a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp index 07ddaf2f40f..9f0bb63ed38 100644 --- a/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp +++ b/Userland/Libraries/LibJS/Runtime/NumberPrototype.cpp @@ -55,7 +55,7 @@ static ThrowCompletionOr this_number_value(GlobalObject& global_object, V if (value.is_number()) return value; if (value.is_object() && is(value.as_object())) - return static_cast(value.as_object()).value_of(); + return Value(static_cast(value.as_object()).number()); auto& vm = global_object.vm(); return vm.throw_completion(global_object, ErrorType::NotAnObjectOfType, "Number"); } diff --git a/Userland/Libraries/LibJS/Runtime/Object.h b/Userland/Libraries/LibJS/Runtime/Object.h index 7395291b188..7cf5615cb9e 100644 --- a/Userland/Libraries/LibJS/Runtime/Object.h +++ b/Userland/Libraries/LibJS/Runtime/Object.h @@ -167,7 +167,6 @@ public: virtual const char* class_name() const override { return "Object"; } virtual void visit_edges(Cell::Visitor&) override; - virtual Value value_of() const { return Value(const_cast(this)); } Value get_direct(size_t index) const { return m_storage[index]; } diff --git a/Userland/Libraries/LibJS/Runtime/StringObject.h b/Userland/Libraries/LibJS/Runtime/StringObject.h index 5ffef5da216..e21203128c8 100644 --- a/Userland/Libraries/LibJS/Runtime/StringObject.h +++ b/Userland/Libraries/LibJS/Runtime/StringObject.h @@ -23,11 +23,6 @@ public: PrimitiveString const& primitive_string() const { return m_string; } PrimitiveString& primitive_string() { return m_string; } - virtual Value value_of() const override - { - return Value(&m_string); - } - private: virtual ThrowCompletionOr> internal_get_own_property(PropertyKey const&) const override; virtual ThrowCompletionOr internal_define_own_property(PropertyKey const&, PropertyDescriptor const&) override; diff --git a/Userland/Libraries/LibJS/Runtime/SymbolObject.h b/Userland/Libraries/LibJS/Runtime/SymbolObject.h index a3d3adf5b44..9c255032a76 100644 --- a/Userland/Libraries/LibJS/Runtime/SymbolObject.h +++ b/Userland/Libraries/LibJS/Runtime/SymbolObject.h @@ -26,11 +26,6 @@ public: String description() const { return m_symbol.description(); } bool is_global() const { return m_symbol.is_global(); } - virtual Value value_of() const override - { - return Value(&m_symbol); - } - private: virtual void visit_edges(Visitor&) override; diff --git a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp index 01d290d96bd..85eaf2632d9 100644 --- a/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp +++ b/Userland/Libraries/LibWeb/Bindings/WindowObject.cpp @@ -166,9 +166,8 @@ static JS::ThrowCompletionOr impl_from(JS::VM& vm, JS::GlobalObjec // the global object we make an exception here. // This allows calls like `setTimeout(f, 10)` to work. auto this_value = vm.this_value(global_object); - if (this_value.is_nullish()) { - this_value = global_object.value_of(); - } + if (this_value.is_nullish()) + this_value = &global_object; auto* this_object = MUST(this_value.to_object(global_object)); diff --git a/Userland/Utilities/js.cpp b/Userland/Utilities/js.cpp index 8770f4fe2e2..1ebfd28c279 100644 --- a/Userland/Utilities/js.cpp +++ b/Userland/Utilities/js.cpp @@ -760,7 +760,7 @@ static void print_primitive_wrapper_object(FlyString const& name, JS::Object con // BooleanObject, NumberObject, StringObject print_type(name); js_out(" "); - print_value(object.value_of(), seen_objects); + print_value(&object, seen_objects); } static void print_value(JS::Value value, HashTable& seen_objects)