tizen beta release
[framework/web/webkit-efl.git] / Source / JavaScriptCore / runtime / StringObject.cpp
1 /*
2  *  Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3  *  Copyright (C) 2004, 2005, 2006, 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
21 #include "config.h"
22 #include "StringObject.h"
23
24 #include "PropertyNameArray.h"
25
26 namespace JSC {
27
28 ASSERT_CLASS_FITS_IN_CELL(StringObject);
29
30 const ClassInfo StringObject::s_info = { "String", &JSWrapperObject::s_info, 0, 0, CREATE_METHOD_TABLE(StringObject) };
31
32 StringObject::StringObject(JSGlobalData& globalData, Structure* structure)
33     : JSWrapperObject(globalData, structure)
34 {
35 }
36
37 void StringObject::vtableAnchor()
38 {
39 }
40
41 void StringObject::finishCreation(JSGlobalData& globalData, JSString* string)
42 {
43     Base::finishCreation(globalData);
44     ASSERT(inherits(&s_info));
45     setInternalValue(globalData, string);
46 }
47
48 bool StringObject::getOwnPropertySlot(JSCell* cell, ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
49 {
50     StringObject* thisObject = jsCast<StringObject*>(cell);
51     if (thisObject->internalValue()->getStringPropertySlot(exec, propertyName, slot))
52         return true;
53     return JSObject::getOwnPropertySlot(thisObject, exec, propertyName, slot);
54 }
55     
56 bool StringObject::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned propertyName, PropertySlot& slot)
57 {
58     StringObject* thisObject = jsCast<StringObject*>(cell);
59     if (thisObject->internalValue()->getStringPropertySlot(exec, propertyName, slot))
60         return true;    
61     return JSObject::getOwnPropertySlot(thisObject, exec, Identifier::from(exec, propertyName), slot);
62 }
63
64 bool StringObject::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
65 {
66     StringObject* thisObject = jsCast<StringObject*>(object);
67     if (thisObject->internalValue()->getStringPropertyDescriptor(exec, propertyName, descriptor))
68         return true;    
69     return JSObject::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);
70 }
71
72 void StringObject::put(JSCell* cell, ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
73 {
74     if (propertyName == exec->propertyNames().length)
75         return;
76     JSObject::put(cell, exec, propertyName, value, slot);
77 }
78
79 bool StringObject::deleteProperty(JSCell* cell, ExecState* exec, const Identifier& propertyName)
80 {
81     StringObject* thisObject = jsCast<StringObject*>(cell);
82     if (propertyName == exec->propertyNames().length)
83         return false;
84     bool isStrictUInt32;
85     unsigned i = propertyName.toUInt32(isStrictUInt32);
86     if (isStrictUInt32 && thisObject->internalValue()->canGetIndex(i))
87         return false;
88     return JSObject::deleteProperty(thisObject, exec, propertyName);
89 }
90
91 void StringObject::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
92 {
93     StringObject* thisObject = jsCast<StringObject*>(object);
94     int size = thisObject->internalValue()->length();
95     for (int i = 0; i < size; ++i)
96         propertyNames.add(Identifier(exec, UString::number(i)));
97     if (mode == IncludeDontEnumProperties)
98         propertyNames.add(exec->propertyNames().length);
99     return JSObject::getOwnPropertyNames(thisObject, exec, propertyNames, mode);
100 }
101
102 } // namespace JSC