mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 1 | // -*- c-basic-offset: 2 -*- |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 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 |
mjs | cdff33b | 2006-01-23 21:41:36 +0000 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 19 | * |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
darin | 36d1136 | 2006-04-11 16:30:21 +0000 | [diff] [blame] | 22 | #ifndef STRING_OBJECT_H_ |
| 23 | #define STRING_OBJECT_H_ |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 24 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 25 | #include "function_object.h" |
mjs | 308be5a | 2006-08-14 03:06:14 +0000 | [diff] [blame] | 26 | #include "JSWrapperObject.h" |
mjs | 06ed466 | 2007-07-25 21:50:00 +0000 | [diff] [blame] | 27 | #include "internal.h" |
weinig@apple.com | a73c15f | 2007-11-08 20:31:26 +0000 | [diff] [blame] | 28 | #include "lookup.h" |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 29 | |
| 30 | namespace KJS { |
| 31 | |
mjs | 308be5a | 2006-08-14 03:06:14 +0000 | [diff] [blame] | 32 | class StringInstance : public JSWrapperObject { |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 33 | public: |
ap@webkit.org | 53f9919 | 2008-05-12 07:12:31 +0000 | [diff] [blame] | 34 | StringInstance(JSObject *proto); |
eseidel | 74efded | 2007-10-29 07:55:34 +0000 | [diff] [blame] | 35 | StringInstance(JSObject *proto, StringImp*); |
ap@webkit.org | 53f9919 | 2008-05-12 07:12:31 +0000 | [diff] [blame] | 36 | StringInstance(JSObject *proto, const UString&); |
darin | a6cae2c | 2002-11-19 06:53:35 +0000 | [diff] [blame] | 37 | |
mjs | b3598b8 | 2006-07-16 21:06:28 +0000 | [diff] [blame] | 38 | virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&); |
eseidel | 74efded | 2007-10-29 07:55:34 +0000 | [diff] [blame] | 39 | virtual bool getOwnPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); |
| 40 | |
darin@apple.com | e25e04e | 2008-02-24 05:01:27 +0000 | [diff] [blame] | 41 | virtual void put(ExecState* exec, const Identifier& propertyName, JSValue*); |
mjs | b3598b8 | 2006-07-16 21:06:28 +0000 | [diff] [blame] | 42 | virtual bool deleteProperty(ExecState* exec, const Identifier& propertyName); |
| 43 | virtual void getPropertyNames(ExecState*, PropertyNameArray&); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 44 | |
| 45 | virtual const ClassInfo *classInfo() const { return &info; } |
| 46 | static const ClassInfo info; |
mjs | 0b00317 | 2007-08-05 05:20:35 +0000 | [diff] [blame] | 47 | |
| 48 | StringImp* internalValue() const { return static_cast<StringImp*>(JSWrapperObject::internalValue());} |
| 49 | |
mjs | 70d7421 | 2005-08-07 06:17:49 +0000 | [diff] [blame] | 50 | private: |
eseidel | 74efded | 2007-10-29 07:55:34 +0000 | [diff] [blame] | 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&); |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 55 | }; |
| 56 | |
ggaren | b7d1906 | 2006-07-21 18:50:24 +0000 | [diff] [blame] | 57 | // WebCore uses this to make style.filter undetectable |
| 58 | class StringInstanceThatMasqueradesAsUndefined : public StringInstance { |
| 59 | public: |
ap@webkit.org | 53f9919 | 2008-05-12 07:12:31 +0000 | [diff] [blame] | 60 | StringInstanceThatMasqueradesAsUndefined(JSObject* proto, const UString& string) |
| 61 | : StringInstance(proto, string) { } |
ggaren | b7d1906 | 2006-07-21 18:50:24 +0000 | [diff] [blame] | 62 | virtual bool masqueradeAsUndefined() const { return true; } |
| 63 | virtual bool toBoolean(ExecState*) const { return false; } |
| 64 | }; |
| 65 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 66 | /** |
| 67 | * @internal |
| 68 | * |
| 69 | * The initial value of String.prototype (and thus all objects created |
| 70 | * with the String constructor |
| 71 | */ |
darin | 35940e8 | 2005-12-11 02:06:17 +0000 | [diff] [blame] | 72 | class StringPrototype : public StringInstance { |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 73 | public: |
darin | 35940e8 | 2005-12-11 02:06:17 +0000 | [diff] [blame] | 74 | StringPrototype(ExecState *exec, |
| 75 | ObjectPrototype *objProto); |
mjs | 70d7421 | 2005-08-07 06:17:49 +0000 | [diff] [blame] | 76 | virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 77 | virtual const ClassInfo *classInfo() const { return &info; } |
| 78 | static const ClassInfo info; |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 79 | }; |
| 80 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 81 | /** |
| 82 | * @internal |
| 83 | * |
weinig@apple.com | 5902380 | 2008-01-16 06:43:15 +0000 | [diff] [blame] | 84 | * Functions to implement all methods that are properties of the |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 85 | * String.prototype object |
| 86 | */ |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 87 | |
weinig@apple.com | 5902380 | 2008-01-16 06:43:15 +0000 | [diff] [blame] | 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&); |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 107 | |
weinig@apple.com | 5902380 | 2008-01-16 06:43:15 +0000 | [diff] [blame] | 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&); |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 121 | |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 122 | /** |
| 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.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame^] | 129 | StringObjectImp(ExecState*, FunctionPrototype*, StringPrototype*); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 130 | |
mrowe@apple.com | 2f6dfdf | 2008-05-22 01:20:45 +0000 | [diff] [blame^] | 131 | virtual ConstructType getConstructData(ConstructData&); |
| 132 | virtual JSObject* construct(ExecState*, const List&); |
| 133 | |
| 134 | virtual JSValue* callAsFunction(ExecState*, JSObject* thisObj, const List& args); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 135 | }; |
| 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: |
mjs | 3e13aa6 | 2006-02-21 07:54:55 +0000 | [diff] [blame] | 145 | StringObjectFuncImp(ExecState*, FunctionPrototype*, const Identifier&); |
darin | 35940e8 | 2005-12-11 02:06:17 +0000 | [diff] [blame] | 146 | virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args); |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 147 | }; |
| 148 | |
ggaren | 07d4ce6 | 2005-07-14 18:27:04 +0000 | [diff] [blame] | 149 | } // namespace |
kocienda | 66a6d36 | 2001-08-24 14:24:45 +0000 | [diff] [blame] | 150 | |
| 151 | #endif |
mjs | 6f821c8 | 2002-03-22 00:31:57 +0000 | [diff] [blame] | 152 | |