]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | // -*- c-basic-offset: 2 -*- |
2 | /* | |
3 | * This file is part of the KDE libraries | |
4 | * Copyright (C) 1999-2000 Harri Porten (porten@kde.org) | |
5 | * | |
6 | * This library is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU Lesser 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 | * Lesser General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU Lesser General Public | |
17 | * License along with this library; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | * | |
20 | */ | |
21 | ||
22 | #ifndef STRING_OBJECT_H_ | |
23 | #define STRING_OBJECT_H_ | |
24 | ||
25 | #include "function_object.h" | |
26 | #include "JSWrapperObject.h" | |
27 | #include "internal.h" | |
28 | #include "lookup.h" | |
29 | ||
30 | namespace KJS { | |
31 | ||
32 | class StringInstance : public JSWrapperObject { | |
33 | public: | |
34 | StringInstance(JSObject *proto); | |
35 | StringInstance(JSObject *proto, StringImp*); | |
36 | StringInstance(JSObject *proto, const UString&); | |
37 | ||
38 | virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); | |
39 | virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); | |
40 | ||
41 | virtual void put(ExecState* exec, const Identifier& propertyName, JSValue*, int attr = None); | |
42 | virtual bool deleteProperty(ExecState* exec, const Identifier& propertyName); | |
43 | virtual void getPropertyNames(ExecState*, PropertyNameArray&); | |
44 | ||
45 | virtual const ClassInfo *classInfo() const { return &info; } | |
46 | static const ClassInfo info; | |
47 | ||
48 | StringImp* internalValue() const { return static_cast<StringImp*>(JSWrapperObject::internalValue());} | |
49 | ||
50 | private: | |
51 | bool inlineGetOwnPropertySlot(ExecState*, unsigned, PropertySlot&); | |
52 | ||
53 | static JSValue* lengthGetter(ExecState*, JSObject *, const Identifier&, const PropertySlot&); | |
54 | static JSValue* indexGetter(ExecState*, JSObject *, const Identifier&, const PropertySlot&); | |
55 | }; | |
56 | ||
57 | // WebCore uses this to make style.filter undetectable | |
58 | class StringInstanceThatMasqueradesAsUndefined : public StringInstance { | |
59 | public: | |
60 | StringInstanceThatMasqueradesAsUndefined(JSObject* proto, const UString& string) | |
61 | : StringInstance(proto, string) { } | |
62 | virtual bool masqueradeAsUndefined() const { return true; } | |
63 | virtual bool toBoolean(ExecState*) const { return false; } | |
64 | }; | |
65 | ||
66 | /** | |
67 | * @internal | |
68 | * | |
69 | * The initial value of String.prototype (and thus all objects created | |
70 | * with the String constructor | |
71 | */ | |
72 | class StringPrototype : public StringInstance { | |
73 | public: | |
74 | StringPrototype(ExecState *exec, | |
75 | ObjectPrototype *objProto); | |
76 | virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); | |
77 | virtual const ClassInfo *classInfo() const { return &info; } | |
78 | static const ClassInfo info; | |
79 | }; | |
80 | ||
81 | /** | |
82 | * @internal | |
83 | * | |
84 | * Functions to implement all methods that are properties of the | |
85 | * String.prototype object | |
86 | */ | |
87 | ||
88 | JSValue* stringProtoFuncToString(ExecState*, JSObject*, const List&); | |
89 | JSValue* stringProtoFuncValueOf(ExecState*, JSObject*, const List&); | |
90 | JSValue* stringProtoFuncCharAt(ExecState*, JSObject*, const List&); | |
91 | JSValue* stringProtoFuncCharCodeAt(ExecState*, JSObject*, const List&); | |
92 | JSValue* stringProtoFuncConcat(ExecState*, JSObject*, const List&); | |
93 | JSValue* stringProtoFuncIndexOf(ExecState*, JSObject*, const List&); | |
94 | JSValue* stringProtoFuncLastIndexOf(ExecState*, JSObject*, const List&); | |
95 | JSValue* stringProtoFuncMatch(ExecState*, JSObject*, const List&); | |
96 | JSValue* stringProtoFuncReplace(ExecState*, JSObject*, const List&); | |
97 | JSValue* stringProtoFuncSearch(ExecState*, JSObject*, const List&); | |
98 | JSValue* stringProtoFuncSlice(ExecState*, JSObject*, const List&); | |
99 | JSValue* stringProtoFuncSplit(ExecState*, JSObject*, const List&); | |
100 | JSValue* stringProtoFuncSubstr(ExecState*, JSObject*, const List&); | |
101 | JSValue* stringProtoFuncSubstring(ExecState*, JSObject*, const List&); | |
102 | JSValue* stringProtoFuncToLowerCase(ExecState*, JSObject*, const List&); | |
103 | JSValue* stringProtoFuncToUpperCase(ExecState*, JSObject*, const List&); | |
104 | JSValue* stringProtoFuncToLocaleLowerCase(ExecState*, JSObject*, const List&); | |
105 | JSValue* stringProtoFuncToLocaleUpperCase(ExecState*, JSObject*, const List&); | |
106 | JSValue* stringProtoFuncLocaleCompare(ExecState*, JSObject*, const List&); | |
107 | ||
108 | JSValue* stringProtoFuncBig(ExecState*, JSObject*, const List&); | |
109 | JSValue* stringProtoFuncSmall(ExecState*, JSObject*, const List&); | |
110 | JSValue* stringProtoFuncBlink(ExecState*, JSObject*, const List&); | |
111 | JSValue* stringProtoFuncBold(ExecState*, JSObject*, const List&); | |
112 | JSValue* stringProtoFuncFixed(ExecState*, JSObject*, const List&); | |
113 | JSValue* stringProtoFuncItalics(ExecState*, JSObject*, const List&); | |
114 | JSValue* stringProtoFuncStrike(ExecState*, JSObject*, const List&); | |
115 | JSValue* stringProtoFuncSub(ExecState*, JSObject*, const List&); | |
116 | JSValue* stringProtoFuncSup(ExecState*, JSObject*, const List&); | |
117 | JSValue* stringProtoFuncFontcolor(ExecState*, JSObject*, const List&); | |
118 | JSValue* stringProtoFuncFontsize(ExecState*, JSObject*, const List&); | |
119 | JSValue* stringProtoFuncAnchor(ExecState*, JSObject*, const List&); | |
120 | JSValue* stringProtoFuncLink(ExecState*, JSObject*, const List&); | |
121 | ||
122 | /** | |
123 | * @internal | |
124 | * | |
125 | * The initial value of the the global variable's "String" property | |
126 | */ | |
127 | class StringObjectImp : public InternalFunctionImp { | |
128 | public: | |
129 | StringObjectImp(ExecState *exec, | |
130 | FunctionPrototype *funcProto, | |
131 | StringPrototype *stringProto); | |
132 | ||
133 | virtual bool implementsConstruct() const; | |
134 | virtual JSObject *construct(ExecState *exec, const List &args); | |
135 | virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args); | |
136 | }; | |
137 | ||
138 | /** | |
139 | * @internal | |
140 | * | |
141 | * Class to implement all methods that are properties of the | |
142 | * String object | |
143 | */ | |
144 | class StringObjectFuncImp : public InternalFunctionImp { | |
145 | public: | |
146 | StringObjectFuncImp(ExecState*, FunctionPrototype*, const Identifier&); | |
147 | virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args); | |
148 | }; | |
149 | ||
150 | } // namespace | |
151 | ||
152 | #endif | |
153 |