2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
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.
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.
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
22 #include "StringObject.h"
24 #include "PropertyNameArray.h"
28 ASSERT_CLASS_FITS_IN_CELL(StringObject);
30 const ClassInfo StringObject::s_info = { "String", &JSWrapperObject::s_info, 0, 0 };
32 StringObject::StringObject(JSGlobalData& globalData, Structure* structure)
33 : JSWrapperObject(globalData, structure)
37 void StringObject::finishCreation(JSGlobalData& globalData, JSString* string)
39 Base::finishCreation(globalData);
40 ASSERT(inherits(&s_info));
41 setInternalValue(globalData, string);
44 bool StringObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
46 if (internalValue()->getStringPropertySlot(exec, propertyName, slot))
48 return JSObject::getOwnPropertySlot(exec, propertyName, slot);
51 bool StringObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
53 if (internalValue()->getStringPropertySlot(exec, propertyName, slot))
55 return JSObject::getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
58 bool StringObject::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
60 if (internalValue()->getStringPropertyDescriptor(exec, propertyName, descriptor))
62 return JSObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
65 void StringObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
67 if (propertyName == exec->propertyNames().length)
69 JSObject::put(exec, propertyName, value, slot);
72 bool StringObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
74 if (propertyName == exec->propertyNames().length)
77 unsigned i = propertyName.toUInt32(isStrictUInt32);
78 if (isStrictUInt32 && internalValue()->canGetIndex(i))
80 return JSObject::deleteProperty(exec, propertyName);
83 void StringObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
85 int size = internalValue()->length();
86 for (int i = 0; i < size; ++i)
87 propertyNames.add(Identifier(exec, UString::number(i)));
88 if (mode == IncludeDontEnumProperties)
89 propertyNames.add(exec->propertyNames().length);
90 return JSObject::getOwnPropertyNames(exec, propertyNames, mode);