source: webkit/trunk/JavaScriptCore/kjs/JSString.h@ 35906

Last change on this file since 35906 was 35900, checked in by [email protected], 17 years ago

2008-08-23 Cameron Zwarich <[email protected]>

Rubber-stamped by Mark Rowe.

Remove modelines.

JavaScriptCore:

  • API/APICast.h:
  • API/JSBase.cpp:
  • API/JSCallbackConstructor.cpp:
  • API/JSCallbackConstructor.h:
  • API/JSCallbackFunction.cpp:
  • API/JSCallbackFunction.h:
  • API/JSCallbackObject.cpp:
  • API/JSCallbackObject.h:
  • API/JSCallbackObjectFunctions.h:
  • API/JSClassRef.cpp:
  • API/JSContextRef.cpp:
  • API/JSObjectRef.cpp:
  • API/JSProfilerPrivate.cpp:
  • API/JSStringRef.cpp:
  • API/JSStringRefBSTR.cpp:
  • API/JSStringRefCF.cpp:
  • API/JSValueRef.cpp:
  • API/tests/JSNode.c:
  • API/tests/JSNode.h:
  • API/tests/JSNodeList.c:
  • API/tests/JSNodeList.h:
  • API/tests/Node.c:
  • API/tests/Node.h:
  • API/tests/NodeList.c:
  • API/tests/NodeList.h:
  • API/tests/minidom.c:
  • API/tests/minidom.js:
  • API/tests/testapi.c:
  • API/tests/testapi.js:
  • JavaScriptCore.pro:
  • kjs/FunctionConstructor.h:
  • kjs/FunctionPrototype.h:
  • kjs/JSArray.h:
  • kjs/JSString.h:
  • kjs/JSWrapperObject.cpp:
  • kjs/NumberConstructor.h:
  • kjs/NumberObject.h:
  • kjs/NumberPrototype.h:
  • kjs/lexer.h:
  • kjs/lookup.h:
  • wtf/Assertions.cpp:
  • wtf/Assertions.h:
  • wtf/HashCountedSet.h:
  • wtf/HashFunctions.h:
  • wtf/HashIterators.h:
  • wtf/HashMap.h:
  • wtf/HashSet.h:
  • wtf/HashTable.h:
  • wtf/HashTraits.h:
  • wtf/ListHashSet.h:
  • wtf/ListRefPtr.h:
  • wtf/Noncopyable.h:
  • wtf/OwnArrayPtr.h:
  • wtf/OwnPtr.h:
  • wtf/PassRefPtr.h:
  • wtf/Platform.h:
  • wtf/RefPtr.h:
  • wtf/RefPtrHashMap.h:
  • wtf/RetainPtr.h:
  • wtf/UnusedParam.h:
  • wtf/Vector.h:
  • wtf/VectorTraits.h:
  • wtf/unicode/Unicode.h:
  • wtf/unicode/icu/UnicodeIcu.h:

WebCore:

  • WebCore.pro:
  • bridge/testbindings.cpp:
  • dom/DocPtr.h:
  • loader/SubstituteData.h:
  • page/Chrome.cpp:
  • page/Chrome.h:
  • page/ChromeClient.h:
  • page/Frame.h:
  • page/FrameLoadRequest.h:
  • page/FrameTree.cpp:
  • page/FrameTree.h:
  • page/Page.h:
  • page/mac/ChromeMac.mm:
  • platform/network/HTTPHeaderMap.h:
  • platform/network/ResourceErrorBase.cpp:
  • platform/network/ResourceErrorBase.h:
  • platform/network/ResourceHandleInternal.h:
  • platform/network/ResourceRequestBase.cpp:
  • platform/network/ResourceRequestBase.h:
  • platform/network/ResourceResponseBase.cpp:
  • platform/network/ResourceResponseBase.h:
  • platform/network/cf/ResourceError.h:
  • platform/network/cf/ResourceRequest.h:
  • platform/network/cf/ResourceRequestCFNet.h:
  • platform/network/cf/ResourceResponse.h:
  • platform/network/cf/ResourceResponseCFNet.h:
  • platform/network/curl/ResourceError.h:
  • platform/network/curl/ResourceRequest.h:
  • platform/network/curl/ResourceResponse.h:
  • platform/network/mac/ResourceError.h:
  • platform/network/mac/ResourceErrorMac.mm:
  • platform/network/mac/ResourceRequest.h:
  • platform/network/mac/ResourceRequestMac.mm:
  • platform/network/mac/ResourceResponse.h:
  • platform/network/mac/ResourceResponseMac.mm:
  • platform/network/qt/ResourceError.h:
  • platform/network/qt/ResourceRequest.h:
  • platform/network/qt/ResourceResponse.h:
  • platform/network/soup/CookieJarSoup.cpp:
  • platform/network/soup/ResourceError.h:
  • platform/network/soup/ResourceRequest.h:
  • platform/network/soup/ResourceResponse.h:
  • Property svn:eol-style set to native
File size: 4.5 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#ifndef JSString_h
24#define JSString_h
25
26#include "CommonIdentifiers.h"
27#include "ExecState.h"
28#include "JSCell.h"
29#include "JSNumberCell.h"
30#include "PropertySlot.h"
31#include "identifier.h"
32#include "ustring.h"
33
34namespace KJS {
35
36 class JSString : public JSCell {
37 public:
38 JSString(const UString& value)
39 : m_value(value)
40 {
41 Heap::heap(this)->reportExtraMemoryCost(value.cost());
42 }
43
44 enum HasOtherOwnerType { HasOtherOwner };
45 JSString(const UString& value, HasOtherOwnerType)
46 : m_value(value)
47 {
48 }
49
50 const UString& value() const { return m_value; }
51
52 bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
53 bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
54
55 bool canGetIndex(unsigned i) { return i < static_cast<unsigned>(m_value.size()); }
56 JSValue* getIndex(ExecState* exec, unsigned i)
57 {
58 ASSERT(canGetIndex(i));
59 return new (exec) JSString(m_value.substr(i, 1));
60 }
61
62 private:
63 virtual bool isString() const;
64
65 virtual JSValue* toPrimitive(ExecState*, PreferredPrimitiveType) const;
66 virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue*& value);
67 virtual bool toBoolean(ExecState*) const;
68 virtual double toNumber(ExecState*) const;
69 virtual JSObject* toObject(ExecState*) const;
70 virtual UString toString(ExecState*) const;
71
72 virtual JSObject* toThisObject(ExecState*) const;
73 virtual UString toThisString(ExecState*) const;
74 virtual JSString* toThisJSString(ExecState*);
75
76 // Actually getPropertySlot, not getOwnPropertySlot (see JSCell).
77 virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
78 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
79
80 UString m_value;
81 };
82
83 JSString* jsString(ExecState*, const UString&); // returns empty string if passed null string
84 JSString* jsString(ExecState*, const char* = ""); // returns empty string if passed 0
85
86 // Should be used for strings that are owned by an object that will
87 // likely outlive the JSValue this makes, such as the parse tree or a
88 // DOM object that contains a UString
89 JSString* jsOwnedString(ExecState*, const UString&);
90
91 ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
92 {
93 if (propertyName == exec->propertyNames().length) {
94 slot.setValue(jsNumber(exec, value().size()));
95 return true;
96 }
97
98 bool isStrictUInt32;
99 unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
100 if (isStrictUInt32 && i < static_cast<unsigned>(m_value.size())) {
101 slot.setValue(jsString(exec, value().substr(i, 1)));
102 return true;
103 }
104
105 return false;
106 }
107
108 ALWAYS_INLINE bool JSString::getStringPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
109 {
110 if (propertyName < static_cast<unsigned>(m_value.size())) {
111 slot.setValue(jsString(exec, value().substr(propertyName, 1)));
112 return true;
113 }
114
115 return false;
116 }
117
118 // --- JSValue inlines ----------------------------
119
120 inline JSString* JSValue::toThisJSString(ExecState* exec)
121 {
122 return JSImmediate::isImmediate(this) ? jsString(exec, JSImmediate::toString(this)) : asCell()->toThisJSString(exec);
123 }
124
125} // namespace KJS
126
127#endif // JSString_h
Note: See TracBrowser for help on using the repository browser.