PropertyNameArray.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * Copyright (C) 2006, 2008, 2012 Apple Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public License
  15. * along with this library; see the file COPYING.LIB. If not, write to
  16. * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  17. * Boston, MA 02110-1301, USA.
  18. *
  19. */
  20. #ifndef PropertyNameArray_h
  21. #define PropertyNameArray_h
  22. #include "CallFrame.h"
  23. #include "Identifier.h"
  24. #include <wtf/HashSet.h>
  25. #include <wtf/OwnArrayPtr.h>
  26. #include <wtf/Vector.h>
  27. namespace JSC {
  28. class Structure;
  29. class StructureChain;
  30. // FIXME: Rename to PropertyNameArray.
  31. class PropertyNameArrayData : public RefCounted<PropertyNameArrayData> {
  32. public:
  33. typedef Vector<Identifier, 20> PropertyNameVector;
  34. static PassRefPtr<PropertyNameArrayData> create() { return adoptRef(new PropertyNameArrayData); }
  35. PropertyNameVector& propertyNameVector() { return m_propertyNameVector; }
  36. private:
  37. PropertyNameArrayData()
  38. {
  39. }
  40. PropertyNameVector m_propertyNameVector;
  41. };
  42. // FIXME: Rename to PropertyNameArrayBuilder.
  43. class PropertyNameArray {
  44. public:
  45. PropertyNameArray(VM* vm)
  46. : m_data(PropertyNameArrayData::create())
  47. , m_vm(vm)
  48. , m_numCacheableSlots(0)
  49. , m_baseObject(0)
  50. {
  51. }
  52. PropertyNameArray(ExecState* exec)
  53. : m_data(PropertyNameArrayData::create())
  54. , m_vm(&exec->vm())
  55. , m_numCacheableSlots(0)
  56. , m_baseObject(0)
  57. {
  58. }
  59. VM* vm() { return m_vm; }
  60. void add(const Identifier& identifier) { add(identifier.impl()); }
  61. JS_EXPORT_PRIVATE void add(StringImpl*);
  62. void addKnownUnique(StringImpl* identifier) { m_data->propertyNameVector().append(Identifier(m_vm, identifier)); }
  63. Identifier& operator[](unsigned i) { return m_data->propertyNameVector()[i]; }
  64. const Identifier& operator[](unsigned i) const { return m_data->propertyNameVector()[i]; }
  65. void setData(PassRefPtr<PropertyNameArrayData> data) { m_data = data; }
  66. PropertyNameArrayData* data() { return m_data.get(); }
  67. PassRefPtr<PropertyNameArrayData> releaseData() { return m_data.release(); }
  68. // FIXME: Remove these functions.
  69. typedef PropertyNameArrayData::PropertyNameVector::const_iterator const_iterator;
  70. size_t size() const { return m_data->propertyNameVector().size(); }
  71. const_iterator begin() const { return m_data->propertyNameVector().begin(); }
  72. const_iterator end() const { return m_data->propertyNameVector().end(); }
  73. size_t numCacheableSlots() const { return m_numCacheableSlots; }
  74. void setNumCacheableSlotsForObject(JSObject* object, size_t numCacheableSlots)
  75. {
  76. if (object != m_baseObject)
  77. return;
  78. m_numCacheableSlots = numCacheableSlots;
  79. }
  80. void setBaseObject(JSObject* object)
  81. {
  82. if (m_baseObject)
  83. return;
  84. m_baseObject = object;
  85. }
  86. private:
  87. typedef HashSet<StringImpl*, PtrHash<StringImpl*> > IdentifierSet;
  88. RefPtr<PropertyNameArrayData> m_data;
  89. IdentifierSet m_set;
  90. VM* m_vm;
  91. size_t m_numCacheableSlots;
  92. JSObject* m_baseObject;
  93. };
  94. } // namespace JSC
  95. #endif // PropertyNameArray_h