DateInstance.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
  3. * Copyright (C) 2008 Apple Inc. All rights reserved.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2 of the License, or (at your option) any later version.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with this library; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  18. *
  19. */
  20. #ifndef DateInstance_h
  21. #define DateInstance_h
  22. #include "JSWrapperObject.h"
  23. namespace JSC {
  24. class DateInstance : public JSWrapperObject {
  25. protected:
  26. JS_EXPORT_PRIVATE DateInstance(ExecState*, Structure*);
  27. void finishCreation(VM&);
  28. JS_EXPORT_PRIVATE void finishCreation(VM&, double);
  29. static void destroy(JSCell*);
  30. public:
  31. typedef JSWrapperObject Base;
  32. static DateInstance* create(ExecState* exec, Structure* structure, double date)
  33. {
  34. DateInstance* instance = new (NotNull, allocateCell<DateInstance>(*exec->heap())) DateInstance(exec, structure);
  35. instance->finishCreation(exec->vm(), date);
  36. return instance;
  37. }
  38. static DateInstance* create(ExecState* exec, Structure* structure)
  39. {
  40. DateInstance* instance = new (NotNull, allocateCell<DateInstance>(*exec->heap())) DateInstance(exec, structure);
  41. instance->finishCreation(exec->vm());
  42. return instance;
  43. }
  44. double internalNumber() const { return internalValue().asNumber(); }
  45. static JS_EXPORTDATA const ClassInfo s_info;
  46. const GregorianDateTime* gregorianDateTime(ExecState* exec) const
  47. {
  48. if (m_data && m_data->m_gregorianDateTimeCachedForMS == internalNumber())
  49. return &m_data->m_cachedGregorianDateTime;
  50. return calculateGregorianDateTime(exec);
  51. }
  52. const GregorianDateTime* gregorianDateTimeUTC(ExecState* exec) const
  53. {
  54. if (m_data && m_data->m_gregorianDateTimeUTCCachedForMS == internalNumber())
  55. return &m_data->m_cachedGregorianDateTimeUTC;
  56. return calculateGregorianDateTimeUTC(exec);
  57. }
  58. static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
  59. {
  60. return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
  61. }
  62. private:
  63. const GregorianDateTime* calculateGregorianDateTime(ExecState*) const;
  64. const GregorianDateTime* calculateGregorianDateTimeUTC(ExecState*) const;
  65. mutable RefPtr<DateInstanceData> m_data;
  66. };
  67. DateInstance* asDateInstance(JSValue);
  68. inline DateInstance* asDateInstance(JSValue value)
  69. {
  70. ASSERT(asObject(value)->inherits(&DateInstance::s_info));
  71. return static_cast<DateInstance*>(asObject(value));
  72. }
  73. } // namespace JSC
  74. #endif // DateInstance_h