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