StringObject.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright (C) 1999-2000 Harri Porten (porten@kde.org)
  3. * Copyright (C) 2007, 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 StringObject_h
  21. #define StringObject_h
  22. #include "JSWrapperObject.h"
  23. #include "JSString.h"
  24. namespace JSC {
  25. class StringObject : public JSWrapperObject {
  26. public:
  27. typedef JSWrapperObject Base;
  28. static StringObject* create(ExecState* exec, Structure* structure)
  29. {
  30. JSString* string = jsEmptyString(exec);
  31. StringObject* object = new (NotNull, allocateCell<StringObject>(*exec->heap())) StringObject(exec->vm(), structure);
  32. object->finishCreation(exec->vm(), string);
  33. return object;
  34. }
  35. static StringObject* create(ExecState* exec, Structure* structure, JSString* string)
  36. {
  37. StringObject* object = new (NotNull, allocateCell<StringObject>(*exec->heap())) StringObject(exec->vm(), structure);
  38. object->finishCreation(exec->vm(), string);
  39. return object;
  40. }
  41. static StringObject* create(ExecState*, JSGlobalObject*, JSString*);
  42. static bool getOwnPropertySlot(JSCell*, ExecState*, PropertyName, PropertySlot&);
  43. static bool getOwnPropertySlotByIndex(JSCell*, ExecState*, unsigned propertyName, PropertySlot&);
  44. static bool getOwnPropertyDescriptor(JSObject*, ExecState*, PropertyName, PropertyDescriptor&);
  45. static void put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
  46. static void putByIndex(JSCell*, ExecState*, unsigned propertyName, JSValue, bool shouldThrow);
  47. static bool deleteProperty(JSCell*, ExecState*, PropertyName);
  48. static bool deletePropertyByIndex(JSCell*, ExecState*, unsigned propertyName);
  49. static void getOwnPropertyNames(JSObject*, ExecState*, PropertyNameArray&, EnumerationMode);
  50. static bool defineOwnProperty(JSObject*, ExecState*, PropertyName, PropertyDescriptor&, bool shouldThrow);
  51. #if ENABLE(DETACHED_JIT) && BUILDING_DETACHED_JIT
  52. private:
  53. static const JS_EXPORTDATA ClassInfo s_info;
  54. #else
  55. public:
  56. static const JS_EXPORTDATA ClassInfo s_info;
  57. #endif
  58. JSString* internalValue() const { return asString(JSWrapperObject::internalValue());}
  59. static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
  60. {
  61. return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), &s_info);
  62. }
  63. protected:
  64. JS_EXPORT_PRIVATE void finishCreation(VM&, JSString*);
  65. static const unsigned StructureFlags = OverridesGetOwnPropertySlot | InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero | OverridesGetPropertyNames | JSWrapperObject::StructureFlags;
  66. JS_EXPORT_PRIVATE StringObject(VM&, Structure*);
  67. };
  68. StringObject* asStringObject(JSValue);
  69. inline StringObject* asStringObject(JSValue value)
  70. {
  71. #if !BUILDING_DETACHED_JIT
  72. ASSERT(asObject(value)->inherits(&StringObject::s_info));
  73. #endif
  74. return static_cast<StringObject*>(asObject(value));
  75. }
  76. JS_EXPORT_PRIVATE StringObject* constructString(ExecState*, JSGlobalObject*, JSValue);
  77. } // namespace JSC
  78. #endif // StringObject_h