JSWrapperObject.h 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /*
  2. * Copyright (C) 2006 Maks Orlovich
  3. * Copyright (C) 2006, 2007, 2008, 2009 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 Library 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. * Library General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Library General Public License
  16. * along with this library; see the file COPYING.LIB. If not, write to
  17. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18. * Boston, MA 02110-1301, USA.
  19. *
  20. */
  21. #ifndef JSWrapperObject_h
  22. #define JSWrapperObject_h
  23. #include "JSDestructibleObject.h"
  24. namespace JSC {
  25. // This class is used as a base for classes such as String,
  26. // Number, Boolean and Date which are wrappers for primitive types.
  27. class JSWrapperObject : public JSDestructibleObject {
  28. public:
  29. typedef JSDestructibleObject Base;
  30. static size_t allocationSize(size_t inlineCapacity)
  31. {
  32. ASSERT_UNUSED(inlineCapacity, !inlineCapacity);
  33. return sizeof(JSWrapperObject);
  34. }
  35. JSValue internalValue() const;
  36. void setInternalValue(VM&, JSValue);
  37. #if !(ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT)
  38. static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
  39. {
  40. return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
  41. }
  42. #endif
  43. static ptrdiff_t internalValueOffset() { return OBJECT_OFFSETOF(JSWrapperObject, m_internalValue); }
  44. static ptrdiff_t internalValueCellOffset()
  45. {
  46. #if USE(JSVALUE64)
  47. return internalValueOffset();
  48. #else
  49. return internalValueOffset() + OBJECT_OFFSETOF(EncodedValueDescriptor, asBits.payload);
  50. #endif
  51. }
  52. protected:
  53. explicit JSWrapperObject(VM&, Structure*);
  54. static const unsigned StructureFlags = OverridesVisitChildren | Base::StructureFlags;
  55. static void visitChildren(JSCell*, SlotVisitor&);
  56. private:
  57. WriteBarrier<Unknown> m_internalValue;
  58. };
  59. inline JSWrapperObject::JSWrapperObject(VM& vm, Structure* structure)
  60. : JSDestructibleObject(vm, structure)
  61. {
  62. }
  63. inline JSValue JSWrapperObject::internalValue() const
  64. {
  65. return m_internalValue.get();
  66. }
  67. inline void JSWrapperObject::setInternalValue(VM& vm, JSValue value)
  68. {
  69. ASSERT(value);
  70. ASSERT(!value.isObject());
  71. m_internalValue.set(vm, this, value);
  72. }
  73. } // namespace JSC
  74. #endif // JSWrapperObject_h