KJsEmbed

binding_support.cpp
1 /* This file is part of the KDE libraries
2  Copyright (C) 2005, 2006 Ian Reinhart Geiser <[email protected]>
3  Copyright (C) 2005, 2006 Matt Broadstone <[email protected]>
4  Copyright (C) 2005, 2006 Richard J. Moore <[email protected]>
5  Copyright (C) 2005, 2006 Erik L. Bunce <[email protected]>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 #include "binding_support.h"
23 #include <kjs/interpreter.h>
24 
25 using namespace KJSEmbed;
26 
27 ProxyBinding::ProxyBinding(KJS::ExecState *exec)
28  : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype())
29 {
30 
31 }
32 
33 QString KJSEmbed::extractQString(KJS::ExecState *exec, const KJS::List &args, int idx, const QString defaultValue)
34 {
35  if (args.size() > idx) {
36  return extractQString(exec, args[idx]);
37  }
38  return defaultValue;
39 }
40 
41 QString KJSEmbed::extractQString(KJS::ExecState *exec, KJS::JSValue *value, const QString defaultValue)
42 {
43  if (!value) {
44  return defaultValue;
45  }
46  return toQString(value->toString(exec));
47 }
48 
49 QByteArray KJSEmbed::extractQByteArray(KJS::ExecState *exec, const KJS::List &args, int idx, const QByteArray &defaultValue)
50 {
51  if (args.size() > idx) {
52  return extractQByteArray(exec, args[idx]);
53  }
54  return defaultValue;
55 }
56 
57 QByteArray KJSEmbed::extractQByteArray(KJS::ExecState *exec, KJS::JSValue *value, const QByteArray &defaultValue)
58 {
59  if (!value) {
60  return defaultValue;
61  }
62  return toQString(value->toString(exec)).toLatin1();
63 }
64 
65 KJS::JSValue *KJSEmbed::createQByteArray(KJS::ExecState *exec, const QByteArray &value)
66 {
67  Q_UNUSED(exec);
68  return KJS::jsString(value.data());
69 }
70 
71 int KJSEmbed::extractInt(KJS::ExecState *exec, const KJS::List &args, int idx, int defaultValue)
72 {
73  if (args.size() > idx) {
74  return extractInt(exec, args[idx]);
75  }
76  return defaultValue;
77 }
78 
79 int KJSEmbed::extractInt(KJS::ExecState *exec, KJS::JSValue *value, int defaultValue)
80 {
81  if (!value) {
82  return defaultValue;
83  }
84  return int(value->toInteger(exec));
85 }
86 
87 KJS::JSValue *KJSEmbed::createQString(KJS::ExecState *exec, const QString &value)
88 {
89  Q_UNUSED(exec);
90  return KJS::jsString(toUString(value));
91 }
92 
93 KJS::JSValue *KJSEmbed::createInt(KJS::ExecState *exec, int value)
94 {
95  Q_UNUSED(exec);
96  return KJS::jsNumber(value);
97 }
98 
99 double KJSEmbed::extractDouble(KJS::ExecState *exec, const KJS::List &args, int idx, double defaultValue)
100 {
101  if (args.size() > idx) {
102  return extractDouble(exec, args[idx]);
103  }
104  return defaultValue;
105 }
106 
107 double KJSEmbed::extractDouble(KJS::ExecState *exec, KJS::JSValue *value, double defaultValue)
108 {
109  if (!value) {
110  return defaultValue;
111  }
112  return (double) value->toNumber(exec);
113 }
114 
115 KJS::JSValue *KJSEmbed::createDouble(KJS::ExecState *exec, double value)
116 {
117  Q_UNUSED(exec);
118  return KJS::jsNumber(value);
119 }
120 
121 float KJSEmbed::extractFloat(KJS::ExecState *exec, const KJS::List &args, int idx, float defaultValue)
122 {
123  if (args.size() > idx) {
124  return extractFloat(exec, args[idx]);
125  }
126  return defaultValue;
127 }
128 
129 float KJSEmbed::extractFloat(KJS::ExecState *exec, KJS::JSValue *value, float defaultValue)
130 {
131  if (!value) {
132  return defaultValue;
133  }
134  return (float) value->toNumber(exec);
135 }
136 
137 KJS::JSValue *KJSEmbed::createFloat(KJS::ExecState *exec, float value)
138 {
139  Q_UNUSED(exec);
140  return KJS::jsNumber(value);
141 }
142 
143 bool KJSEmbed::extractBool(KJS::ExecState *exec, const KJS::List &args, int idx, bool defaultValue)
144 {
145  if (args.size() > idx) {
146  return extractBool(exec, args[idx]);
147  }
148  return defaultValue;
149 }
150 
151 bool KJSEmbed::extractBool(KJS::ExecState *exec, KJS::JSValue *value, bool defaultValue)
152 {
153  if (!value) {
154  return defaultValue;
155  }
156  return value->toBoolean(exec);
157 }
158 
159 KJS::JSValue *KJSEmbed::createBool(KJS::ExecState *exec, bool value)
160 {
161  Q_UNUSED(exec);
162  return KJS::jsBoolean(value);
163 }
164 
165 QDateTime KJSEmbed::extractQDateTime(KJS::ExecState * /* exec */, const KJS::List & /* args */, int /* idx */, const QDateTime & /* defaultValue */)
166 {
167  return QDateTime();
168 }
169 
170 QDateTime KJSEmbed::extractQDateTime(KJS::ExecState * /* exec */, KJS::JSValue * /* value */, const QDateTime & /* defaultValue */)
171 {
172  return QDateTime();
173 }
174 
175 KJS::JSValue *KJSEmbed::createQDateTime(KJS::ExecState * /* exec */, const QDateTime & /* value */)
176 {
177 // return new KJS::JSValue();
178  return nullptr;
179 }
180 
181 QDate KJSEmbed::extractQDate(KJS::ExecState * /* exec */, const KJS::List & /* args */, int /* idx */, const QDate & /* defaultValue */)
182 {
183  return QDate();
184 }
185 
186 QDate KJSEmbed::extractQDate(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QDate & /*defaultValue*/)
187 {
188  return QDate();
189 }
190 
191 KJS::JSValue *KJSEmbed::createQDate(KJS::ExecState * /*exec*/, const QDate & /*value*/)
192 {
193 // return new KJS::JSValue();
194  return nullptr;
195 }
196 
197 QTime KJSEmbed::extractQTime(KJS::ExecState * /*exec*/, const KJS::List & /*args*/, int /*idx*/, const QTime & /*defaultValue*/)
198 {
199  return QTime();
200 }
201 
202 QTime KJSEmbed::extractQTime(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QTime &/*defaultValue*/)
203 {
204  return QTime();
205 }
206 
207 KJS::JSValue *KJSEmbed::createQTime(KJS::ExecState * /*exec*/, const QTime &/*value*/)
208 {
209 // return new KJS::JSValue();
210  return nullptr;
211 }
212 
213 QStringList KJSEmbed::extractQStringList(KJS::ExecState * /*exec*/, const KJS::List &/*args*/, int /*idx*/, const QStringList &/*defaultValue*/)
214 {
215  return QStringList();
216 }
217 
218 QStringList KJSEmbed::extractQStringList(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QStringList &/*defaultValue*/)
219 {
220  return QStringList();
221 }
222 
223 KJS::JSValue *KJSEmbed::createQStringList(KJS::ExecState * /*exec*/, const QStringList &/*value*/)
224 {
225 // return new KJS::JSValue();
226  return nullptr;
227 }
228 
Implement QString-KJS::UString conversion methods.
QByteArray toLatin1() const const
int size() const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Sun Dec 10 2023 03:59:19 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.