blob: d53b1dbcd07eb23343bce9d0fd9e64d63eea5358 [file] [log] [blame]
mjs6f821c82002-03-22 00:31:57 +00001// -*- c-basic-offset: 2 -*-
kocienda66a6d362001-08-24 14:24:45 +00002/*
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
mjscdff33b2006-01-23 21:41:36 +000018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
mjs6f821c82002-03-22 00:31:57 +000019 *
kocienda66a6d362001-08-24 14:24:45 +000020 */
21
darin36d11362006-04-11 16:30:21 +000022#ifndef STRING_OBJECT_H_
23#define STRING_OBJECT_H_
kocienda66a6d362001-08-24 14:24:45 +000024
mjs6f821c82002-03-22 00:31:57 +000025#include "function_object.h"
mjs308be5a2006-08-14 03:06:14 +000026#include "JSWrapperObject.h"
mjs06ed4662007-07-25 21:50:00 +000027#include "internal.h"
weinig@apple.coma73c15f2007-11-08 20:31:26 +000028#include "lookup.h"
kocienda66a6d362001-08-24 14:24:45 +000029
30namespace KJS {
31
mjs308be5a2006-08-14 03:06:14 +000032 class StringInstance : public JSWrapperObject {
kocienda66a6d362001-08-24 14:24:45 +000033 public:
ap@webkit.org53f99192008-05-12 07:12:31 +000034 StringInstance(JSObject *proto);
eseidel74efded2007-10-29 07:55:34 +000035 StringInstance(JSObject *proto, StringImp*);
ap@webkit.org53f99192008-05-12 07:12:31 +000036 StringInstance(JSObject *proto, const UString&);
darina6cae2c2002-11-19 06:53:35 +000037
mjsb3598b82006-07-16 21:06:28 +000038 virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
eseidel74efded2007-10-29 07:55:34 +000039 virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
40
darin@apple.come25e04e2008-02-24 05:01:27 +000041 virtual void put(ExecState* exec, const Identifier& propertyName, JSValue*);
mjsb3598b82006-07-16 21:06:28 +000042 virtual bool deleteProperty(ExecState* exec, const Identifier& propertyName);
43 virtual void getPropertyNames(ExecState*, PropertyNameArray&);
mjs6f821c82002-03-22 00:31:57 +000044
45 virtual const ClassInfo *classInfo() const { return &info; }
46 static const ClassInfo info;
mjs0b003172007-08-05 05:20:35 +000047
48 StringImp* internalValue() const { return static_cast<StringImp*>(JSWrapperObject::internalValue());}
49
mjs70d74212005-08-07 06:17:49 +000050 private:
eseidel74efded2007-10-29 07:55:34 +000051 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&);
kocienda66a6d362001-08-24 14:24:45 +000055 };
56
ggarenb7d19062006-07-21 18:50:24 +000057 // WebCore uses this to make style.filter undetectable
58 class StringInstanceThatMasqueradesAsUndefined : public StringInstance {
59 public:
ap@webkit.org53f99192008-05-12 07:12:31 +000060 StringInstanceThatMasqueradesAsUndefined(JSObject* proto, const UString& string)
61 : StringInstance(proto, string) { }
ggarenb7d19062006-07-21 18:50:24 +000062 virtual bool masqueradeAsUndefined() const { return true; }
63 virtual bool toBoolean(ExecState*) const { return false; }
64 };
65
mjs6f821c82002-03-22 00:31:57 +000066 /**
67 * @internal
68 *
69 * The initial value of String.prototype (and thus all objects created
70 * with the String constructor
71 */
darin35940e82005-12-11 02:06:17 +000072 class StringPrototype : public StringInstance {
kocienda66a6d362001-08-24 14:24:45 +000073 public:
darin35940e82005-12-11 02:06:17 +000074 StringPrototype(ExecState *exec,
75 ObjectPrototype *objProto);
mjs70d74212005-08-07 06:17:49 +000076 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
mjs6f821c82002-03-22 00:31:57 +000077 virtual const ClassInfo *classInfo() const { return &info; }
78 static const ClassInfo info;
kocienda66a6d362001-08-24 14:24:45 +000079 };
80
mjs6f821c82002-03-22 00:31:57 +000081 /**
82 * @internal
83 *
weinig@apple.com59023802008-01-16 06:43:15 +000084 * Functions to implement all methods that are properties of the
mjs6f821c82002-03-22 00:31:57 +000085 * String.prototype object
86 */
kocienda66a6d362001-08-24 14:24:45 +000087
weinig@apple.com59023802008-01-16 06:43:15 +000088 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&);
kocienda66a6d362001-08-24 14:24:45 +0000107
weinig@apple.com59023802008-01-16 06:43:15 +0000108 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&);
kocienda66a6d362001-08-24 14:24:45 +0000121
mjs6f821c82002-03-22 00:31:57 +0000122 /**
123 * @internal
124 *
125 * The initial value of the the global variable's "String" property
126 */
127 class StringObjectImp : public InternalFunctionImp {
128 public:
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +0000129 StringObjectImp(ExecState*, FunctionPrototype*, StringPrototype*);
mjs6f821c82002-03-22 00:31:57 +0000130
mrowe@apple.com2f6dfdf2008-05-22 01:20:45 +0000131 virtual ConstructType getConstructData(ConstructData&);
132 virtual JSObject* construct(ExecState*, const List&);
133
134 virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args);
mjs6f821c82002-03-22 00:31:57 +0000135 };
136
137 /**
138 * @internal
139 *
140 * Class to implement all methods that are properties of the
141 * String object
142 */
143 class StringObjectFuncImp : public InternalFunctionImp {
144 public:
mjs3e13aa62006-02-21 07:54:55 +0000145 StringObjectFuncImp(ExecState*, FunctionPrototype*, const Identifier&);
darin35940e82005-12-11 02:06:17 +0000146 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
mjs6f821c82002-03-22 00:31:57 +0000147 };
148
ggaren07d4ce62005-07-14 18:27:04 +0000149} // namespace
kocienda66a6d362001-08-24 14:24:45 +0000150
151#endif
mjs6f821c82002-03-22 00:31:57 +0000152