]> git.saurik.com Git - apple/javascriptcore.git/blobdiff - runtime/DateInstance.h
JavaScriptCore-1218.33.tar.gz
[apple/javascriptcore.git] / runtime / DateInstance.h
index 398f2995bb8d2ee140b1020fabf01d08d516f6c3..8707772407528f8dc193c9388d74ab324a121a1f 100644 (file)
 
 namespace JSC {
 
-    struct GregorianDateTime;
-
     class DateInstance : public JSWrapperObject {
-    public:
-        explicit DateInstance(PassRefPtr<Structure>);
-        virtual ~DateInstance();
-
-        double internalNumber() const { return internalValue().uncheckedGetNumber(); }
-
-        bool getTime(GregorianDateTime&, int& offset) const;
-        bool getUTCTime(GregorianDateTime&) const;
-        bool getTime(double& milliseconds, int& offset) const;
-        bool getUTCTime(double& milliseconds) const;
+    protected:
+        JS_EXPORT_PRIVATE DateInstance(ExecState*, Structure*);
+        void finishCreation(VM&);
+        JS_EXPORT_PRIVATE void finishCreation(VM&, double);
 
-        static const ClassInfo info;
-
-        void msToGregorianDateTime(double, bool outputIsUTC, GregorianDateTime&) const;
+        static void destroy(JSCell*);
+    public:
+        typedef JSWrapperObject Base;
+
+        static DateInstance* create(ExecState* exec, Structure* structure, double date)
+        {
+            DateInstance* instance = new (NotNull, allocateCell<DateInstance>(*exec->heap())) DateInstance(exec, structure);
+            instance->finishCreation(exec->vm(), date);
+            return instance;
+        }
+
+        static DateInstance* create(ExecState* exec, Structure* structure)
+        {
+            DateInstance* instance = new (NotNull, allocateCell<DateInstance>(*exec->heap())) DateInstance(exec, structure);
+            instance->finishCreation(exec->vm());
+            return instance;
+        }
+
+        double internalNumber() const { return internalValue().asNumber(); }
+
+        static JS_EXPORTDATA const ClassInfo s_info;
+
+        const GregorianDateTime* gregorianDateTime(ExecState* exec) const
+        {
+            if (m_data && m_data->m_gregorianDateTimeCachedForMS == internalNumber())
+                return &m_data->m_cachedGregorianDateTime;
+            return calculateGregorianDateTime(exec);
+        }
+        
+        const GregorianDateTime* gregorianDateTimeUTC(ExecState* exec) const
+        {
+            if (m_data && m_data->m_gregorianDateTimeUTCCachedForMS == internalNumber())
+                return &m_data->m_cachedGregorianDateTimeUTC;
+            return calculateGregorianDateTimeUTC(exec);
+        }
+
+        static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
+        {
+            return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
+        }
 
     private:
-        virtual const ClassInfo* classInfo() const { return &info; }
-
-        using JSWrapperObject::internalValue;
+        const GregorianDateTime* calculateGregorianDateTime(ExecState*) const;
+        const GregorianDateTime* calculateGregorianDateTimeUTC(ExecState*) const;
 
-        struct Cache;
-        mutable Cache* m_cache;
+        mutable RefPtr<DateInstanceData> m_data;
     };
 
-    DateInstance* asDateInstance(JSValuePtr);
+    DateInstance* asDateInstance(JSValue);
 
-    inline DateInstance* asDateInstance(JSValuePtr value)
+    inline DateInstance* asDateInstance(JSValue value)
     {
-        ASSERT(asObject(value)->inherits(&DateInstance::info));
+        ASSERT(asObject(value)->inherits(&DateInstance::s_info));
         return static_cast<DateInstance*>(asObject(value));
     }