Explorar o código

LibJS: Add Value::to_double() for convenience

Andreas Kling %!s(int64=5) %!d(string=hai) anos
pai
achega
2ffa054574
Modificáronse 2 ficheiros con 6 adicións e 0 borrados
  1. 5 0
      Libraries/LibJS/Runtime/Value.cpp
  2. 1 0
      Libraries/LibJS/Runtime/Value.h

+ 5 - 0
Libraries/LibJS/Runtime/Value.cpp

@@ -170,6 +170,11 @@ i32 Value::to_i32() const
     return static_cast<i32>(to_number().as_double());
 }
 
+double Value::to_double() const
+{
+    return to_number().as_double();
+}
+
 Value greater_than(Value lhs, Value rhs)
 {
     return Value(lhs.to_number().as_double() > rhs.to_number().as_double());

+ 1 - 0
Libraries/LibJS/Runtime/Value.h

@@ -146,6 +146,7 @@ public:
     bool to_boolean() const;
     Value to_number() const;
     i32 to_i32() const;
+    double to_double() const;
 
     Object* to_object(Heap&) const;