File indexing completed on 2023-11-26 07:35:09
0001 /* This file is part of the KDE libraries 0002 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org> 0003 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com> 0004 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org> 0005 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 Boston, MA 02110-1301, USA. 0021 */ 0022 #include "binding_support.h" 0023 #include <kjs/interpreter.h> 0024 0025 using namespace KJSEmbed; 0026 0027 ProxyBinding::ProxyBinding(KJS::ExecState *exec) 0028 : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) 0029 { 0030 0031 } 0032 0033 QString KJSEmbed::extractQString(KJS::ExecState *exec, const KJS::List &args, int idx, const QString defaultValue) 0034 { 0035 if (args.size() > idx) { 0036 return extractQString(exec, args[idx]); 0037 } 0038 return defaultValue; 0039 } 0040 0041 QString KJSEmbed::extractQString(KJS::ExecState *exec, KJS::JSValue *value, const QString defaultValue) 0042 { 0043 if (!value) { 0044 return defaultValue; 0045 } 0046 return toQString(value->toString(exec)); 0047 } 0048 0049 QByteArray KJSEmbed::extractQByteArray(KJS::ExecState *exec, const KJS::List &args, int idx, const QByteArray &defaultValue) 0050 { 0051 if (args.size() > idx) { 0052 return extractQByteArray(exec, args[idx]); 0053 } 0054 return defaultValue; 0055 } 0056 0057 QByteArray KJSEmbed::extractQByteArray(KJS::ExecState *exec, KJS::JSValue *value, const QByteArray &defaultValue) 0058 { 0059 if (!value) { 0060 return defaultValue; 0061 } 0062 return toQString(value->toString(exec)).toLatin1(); 0063 } 0064 0065 KJS::JSValue *KJSEmbed::createQByteArray(KJS::ExecState *exec, const QByteArray &value) 0066 { 0067 Q_UNUSED(exec); 0068 return KJS::jsString(value.data()); 0069 } 0070 0071 int KJSEmbed::extractInt(KJS::ExecState *exec, const KJS::List &args, int idx, int defaultValue) 0072 { 0073 if (args.size() > idx) { 0074 return extractInt(exec, args[idx]); 0075 } 0076 return defaultValue; 0077 } 0078 0079 int KJSEmbed::extractInt(KJS::ExecState *exec, KJS::JSValue *value, int defaultValue) 0080 { 0081 if (!value) { 0082 return defaultValue; 0083 } 0084 return int(value->toInteger(exec)); 0085 } 0086 0087 KJS::JSValue *KJSEmbed::createQString(KJS::ExecState *exec, const QString &value) 0088 { 0089 Q_UNUSED(exec); 0090 return KJS::jsString(toUString(value)); 0091 } 0092 0093 KJS::JSValue *KJSEmbed::createInt(KJS::ExecState *exec, int value) 0094 { 0095 Q_UNUSED(exec); 0096 return KJS::jsNumber(value); 0097 } 0098 0099 double KJSEmbed::extractDouble(KJS::ExecState *exec, const KJS::List &args, int idx, double defaultValue) 0100 { 0101 if (args.size() > idx) { 0102 return extractDouble(exec, args[idx]); 0103 } 0104 return defaultValue; 0105 } 0106 0107 double KJSEmbed::extractDouble(KJS::ExecState *exec, KJS::JSValue *value, double defaultValue) 0108 { 0109 if (!value) { 0110 return defaultValue; 0111 } 0112 return (double) value->toNumber(exec); 0113 } 0114 0115 KJS::JSValue *KJSEmbed::createDouble(KJS::ExecState *exec, double value) 0116 { 0117 Q_UNUSED(exec); 0118 return KJS::jsNumber(value); 0119 } 0120 0121 float KJSEmbed::extractFloat(KJS::ExecState *exec, const KJS::List &args, int idx, float defaultValue) 0122 { 0123 if (args.size() > idx) { 0124 return extractFloat(exec, args[idx]); 0125 } 0126 return defaultValue; 0127 } 0128 0129 float KJSEmbed::extractFloat(KJS::ExecState *exec, KJS::JSValue *value, float defaultValue) 0130 { 0131 if (!value) { 0132 return defaultValue; 0133 } 0134 return (float) value->toNumber(exec); 0135 } 0136 0137 KJS::JSValue *KJSEmbed::createFloat(KJS::ExecState *exec, float value) 0138 { 0139 Q_UNUSED(exec); 0140 return KJS::jsNumber(value); 0141 } 0142 0143 bool KJSEmbed::extractBool(KJS::ExecState *exec, const KJS::List &args, int idx, bool defaultValue) 0144 { 0145 if (args.size() > idx) { 0146 return extractBool(exec, args[idx]); 0147 } 0148 return defaultValue; 0149 } 0150 0151 bool KJSEmbed::extractBool(KJS::ExecState *exec, KJS::JSValue *value, bool defaultValue) 0152 { 0153 if (!value) { 0154 return defaultValue; 0155 } 0156 return value->toBoolean(exec); 0157 } 0158 0159 KJS::JSValue *KJSEmbed::createBool(KJS::ExecState *exec, bool value) 0160 { 0161 Q_UNUSED(exec); 0162 return KJS::jsBoolean(value); 0163 } 0164 0165 QDateTime KJSEmbed::extractQDateTime(KJS::ExecState * /* exec */, const KJS::List & /* args */, int /* idx */, const QDateTime & /* defaultValue */) 0166 { 0167 return QDateTime(); 0168 } 0169 0170 QDateTime KJSEmbed::extractQDateTime(KJS::ExecState * /* exec */, KJS::JSValue * /* value */, const QDateTime & /* defaultValue */) 0171 { 0172 return QDateTime(); 0173 } 0174 0175 KJS::JSValue *KJSEmbed::createQDateTime(KJS::ExecState * /* exec */, const QDateTime & /* value */) 0176 { 0177 // return new KJS::JSValue(); 0178 return nullptr; 0179 } 0180 0181 QDate KJSEmbed::extractQDate(KJS::ExecState * /* exec */, const KJS::List & /* args */, int /* idx */, const QDate & /* defaultValue */) 0182 { 0183 return QDate(); 0184 } 0185 0186 QDate KJSEmbed::extractQDate(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QDate & /*defaultValue*/) 0187 { 0188 return QDate(); 0189 } 0190 0191 KJS::JSValue *KJSEmbed::createQDate(KJS::ExecState * /*exec*/, const QDate & /*value*/) 0192 { 0193 // return new KJS::JSValue(); 0194 return nullptr; 0195 } 0196 0197 QTime KJSEmbed::extractQTime(KJS::ExecState * /*exec*/, const KJS::List & /*args*/, int /*idx*/, const QTime & /*defaultValue*/) 0198 { 0199 return QTime(); 0200 } 0201 0202 QTime KJSEmbed::extractQTime(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QTime &/*defaultValue*/) 0203 { 0204 return QTime(); 0205 } 0206 0207 KJS::JSValue *KJSEmbed::createQTime(KJS::ExecState * /*exec*/, const QTime &/*value*/) 0208 { 0209 // return new KJS::JSValue(); 0210 return nullptr; 0211 } 0212 0213 QStringList KJSEmbed::extractQStringList(KJS::ExecState * /*exec*/, const KJS::List &/*args*/, int /*idx*/, const QStringList &/*defaultValue*/) 0214 { 0215 return QStringList(); 0216 } 0217 0218 QStringList KJSEmbed::extractQStringList(KJS::ExecState * /*exec*/, KJS::JSValue * /*value*/, const QStringList &/*defaultValue*/) 0219 { 0220 return QStringList(); 0221 } 0222 0223 KJS::JSValue *KJSEmbed::createQStringList(KJS::ExecState * /*exec*/, const QStringList &/*value*/) 0224 { 0225 // return new KJS::JSValue(); 0226 return nullptr; 0227 } 0228