KJS

string_object.h
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 1999-2000 Harri Porten ([email protected])
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 #ifndef STRING_OBJECT_H_
22 #define STRING_OBJECT_H_
23 
24 #include "function_object.h"
25 #include "JSWrapperObject.h"
26 #include "internal.h"
27 
28 namespace KJS
29 {
30 
31 class StringInstance : public JSWrapperObject
32 {
33 public:
34  StringInstance(JSObject *proto);
35  StringInstance(JSObject *proto, StringImp *);
36  StringInstance(JSObject *proto, const UString &);
37 
38  bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override;
39  bool getOwnPropertySlot(ExecState *, unsigned propertyName, PropertySlot &) override;
40 
41  using KJS::JSObject::put;
42  void put(ExecState *exec, const Identifier &propertyName, JSValue *, int attr = None) override;
43  using KJS::JSObject::deleteProperty;
44  bool deleteProperty(ExecState *exec, const Identifier &propertyName) override;
45  void getOwnPropertyNames(ExecState *, PropertyNameArray &, PropertyMap::PropertyMode mode) override;
46  bool getOwnPropertyDescriptor(ExecState *, const Identifier &, PropertyDescriptor &) override;
47 
48  UString toString(ExecState *exec) const override;
49  JSObject *valueClone(Interpreter *targetCtx) const override;
50 
51  const ClassInfo *classInfo() const override
52  {
53  return &info;
54  }
55  static const ClassInfo info;
56 
57  StringImp *internalValue() const
58  {
59  return static_cast<StringImp *>(JSWrapperObject::internalValue());
60  }
61 
62  bool conversionsCustomized() const
63  {
64  return m_conversionsCustomized;
65  }
66 private:
67  bool inlineGetOwnPropertySlot(ExecState *, unsigned, PropertySlot &);
68 
69  static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const PropertySlot &);
70  static JSValue *indexGetter(ExecState *, JSObject *, unsigned, const PropertySlot &);
71 
72  bool m_conversionsCustomized;
73 };
74 
75 /**
76  * @internal
77  *
78  * The initial value of String.prototype (and thus all objects created
79  * with the String constructor
80  */
81 class StringPrototype : public StringInstance
82 {
83 public:
85  ObjectPrototype *objProto);
86  using KJS::StringInstance::getOwnPropertySlot;
87  bool getOwnPropertySlot(ExecState *, const Identifier &, PropertySlot &) override;
88  const ClassInfo *classInfo() const override
89  {
90  return &info;
91  }
92  static const ClassInfo info;
93 };
94 
95 /**
96  * @internal
97  *
98  * Class to implement all methods that are properties of the
99  * String.prototype object
100  */
101 class StringProtoFunc : public InternalFunctionImp
102 {
103 public:
104  StringProtoFunc(ExecState *exec, int i, int len, const Identifier &);
105 
106  JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override;
107 
108  enum { ToString, ValueOf, CharAt, CharCodeAt, Concat, IndexOf, LastIndexOf,
109  Match, Replace, Search, Slice, Split,
110  Substr, Substring, FromCharCode, ToLowerCase, ToUpperCase,
111  ToLocaleLowerCase, ToLocaleUpperCase, Trim, LocaleCompare,
112  StartsWith, EndsWith, Includes,
113  // ES6 (Draft 08.11.2013
114  Repeat
115 #ifndef KJS_PURE_ECMA
116  , Big, Small, Blink, Bold, Fixed, Italics, Strike, Sub, Sup,
117  Fontcolor, Fontsize, Anchor, Link, TrimLeft, TrimRight
118 #endif
119  };
120 
121  static void setToLowerFunction(UnicodeSupport::StringConversionFunction f);
122  static void setToUpperFunction(UnicodeSupport::StringConversionFunction f);
123 private:
124  int id;
125 };
126 
127 /**
128  * @internal
129  *
130  * The initial value of the global variable's "String" property
131  */
132 class StringObjectImp : public InternalFunctionImp
133 {
134 public:
136  FunctionPrototype *funcProto,
137  StringPrototype *stringProto);
138 
139  bool implementsConstruct() const override;
140  using KJS::JSObject::construct;
141  JSObject *construct(ExecState *exec, const List &args) override;
142  JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override;
143 };
144 
145 /**
146  * @internal
147  *
148  * Class to implement all methods that are properties of the
149  * String object
150  */
151 class StringObjectFuncImp : public InternalFunctionImp
152 {
153 public:
155  JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) override;
156 };
157 
158 } // namespace
159 
160 #endif
161 
Class Information.
Definition: object.h:48
JSValue is the base type for all primitives (Undefined, Null, Boolean, String, Number) and objects in...
Definition: value.h:58
JSValue * internalValue() const
Returns the internal value of the object.
Represents the current state of script execution.
Definition: ExecState.h:53
Represents an Identifier for a Javascript object.
Definition: identifier.h:36
Native list type.
Definition: list.h:52
virtual bool put(ScriptableExtension *callerPrincipal, quint64 objId, const QString &propName, const QVariant &value)
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Tue Sep 26 2023 03:48:57 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.