]> git.saurik.com Git - apple/javascriptcore.git/blame - runtime/StringObject.cpp
JavaScriptCore-903.5.tar.gz
[apple/javascriptcore.git] / runtime / StringObject.cpp
CommitLineData
9dae56ea
A
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
26namespace JSC {
27
28ASSERT_CLASS_FITS_IN_CELL(StringObject);
29
14957cd0 30const ClassInfo StringObject::s_info = { "String", &JSWrapperObject::s_info, 0, 0 };
9dae56ea 31
14957cd0
A
32StringObject::StringObject(ExecState* exec, Structure* structure)
33 : JSWrapperObject(exec->globalData(), structure)
9dae56ea 34{
14957cd0
A
35 ASSERT(inherits(&s_info));
36 setInternalValue(exec->globalData(), jsEmptyString(exec));
9dae56ea
A
37}
38
14957cd0
A
39StringObject::StringObject(JSGlobalData& globalData, Structure* structure, JSString* string)
40 : JSWrapperObject(globalData, structure)
9dae56ea 41{
14957cd0
A
42 ASSERT(inherits(&s_info));
43 setInternalValue(globalData, string);
9dae56ea
A
44}
45
14957cd0
A
46StringObject::StringObject(ExecState* exec, Structure* structure, const UString& string)
47 : JSWrapperObject(exec->globalData(), structure)
9dae56ea 48{
14957cd0
A
49 ASSERT(inherits(&s_info));
50 setInternalValue(exec->globalData(), jsString(exec, string));
9dae56ea
A
51}
52
53bool StringObject::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
54{
55 if (internalValue()->getStringPropertySlot(exec, propertyName, slot))
56 return true;
57 return JSObject::getOwnPropertySlot(exec, propertyName, slot);
58}
59
60bool StringObject::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
61{
62 if (internalValue()->getStringPropertySlot(exec, propertyName, slot))
63 return true;
64 return JSObject::getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);
65}
66
f9bf01c6
A
67bool StringObject::getOwnPropertyDescriptor(ExecState* exec, const Identifier& propertyName, PropertyDescriptor& descriptor)
68{
69 if (internalValue()->getStringPropertyDescriptor(exec, propertyName, descriptor))
70 return true;
71 return JSObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
72}
73
ba379fdc 74void StringObject::put(ExecState* exec, const Identifier& propertyName, JSValue value, PutPropertySlot& slot)
9dae56ea
A
75{
76 if (propertyName == exec->propertyNames().length)
77 return;
78 JSObject::put(exec, propertyName, value, slot);
79}
80
81bool StringObject::deleteProperty(ExecState* exec, const Identifier& propertyName)
82{
83 if (propertyName == exec->propertyNames().length)
84 return false;
f9bf01c6 85 bool isStrictUInt32;
14957cd0 86 unsigned i = propertyName.toUInt32(isStrictUInt32);
f9bf01c6
A
87 if (isStrictUInt32 && internalValue()->canGetIndex(i))
88 return false;
9dae56ea
A
89 return JSObject::deleteProperty(exec, propertyName);
90}
91
f9bf01c6 92void StringObject::getOwnPropertyNames(ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)
9dae56ea 93{
f9bf01c6 94 int size = internalValue()->length();
9dae56ea 95 for (int i = 0; i < size; ++i)
14957cd0 96 propertyNames.add(Identifier(exec, UString::number(i)));
f9bf01c6
A
97 if (mode == IncludeDontEnumProperties)
98 propertyNames.add(exec->propertyNames().length);
99 return JSObject::getOwnPropertyNames(exec, propertyNames, mode);
9dae56ea
A
100}
101
102} // namespace JSC