kjsembed
binding_support.cpp
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org> 00003 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com> 00004 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org> 00005 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us> 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Library General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Library General Public License for more details. 00016 00017 You should have received a copy of the GNU Library General Public License 00018 along with this library; see the file COPYING.LIB. If not, write to 00019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00020 Boston, MA 02110-1301, USA. 00021 */ 00022 #include "binding_support.h" 00023 #include <kjs/interpreter.h> 00024 00025 00026 using namespace KJSEmbed; 00027 00028 ProxyBinding::ProxyBinding( KJS::ExecState *exec ) 00029 : KJS::JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()) 00030 { 00031 00032 } 00033 00034 QString KJSEmbed::extractQString( KJS::ExecState *exec, const KJS::List &args, int idx, const QString defaultValue ) 00035 { 00036 if( args.size() > idx ) 00037 { 00038 return extractQString( exec, args[idx] ); 00039 } 00040 return defaultValue; 00041 } 00042 00043 QString KJSEmbed::extractQString( KJS::ExecState *exec, KJS::JSValue *value, const QString defaultValue ) 00044 { 00045 if( !value ) 00046 return defaultValue; 00047 return toQString(value->toString(exec)); 00048 } 00049 00050 QByteArray KJSEmbed::extractQByteArray( KJS::ExecState *exec, const KJS::List &args, int idx, const QByteArray &defaultValue ) 00051 { 00052 if( args.size() > idx ) 00053 { 00054 return extractQByteArray( exec, args[idx] ); 00055 } 00056 return defaultValue; 00057 } 00058 00059 QByteArray KJSEmbed::extractQByteArray( KJS::ExecState *exec, KJS::JSValue *value, const QByteArray &defaultValue ) 00060 { 00061 if( !value ) 00062 return defaultValue; 00063 return toQString(value->toString(exec)).toLatin1(); 00064 } 00065 00066 KJS::JSValue *KJSEmbed::createQByteArray( KJS::ExecState *exec, const QByteArray &value ) 00067 { 00068 Q_UNUSED( exec ); 00069 return KJS::jsString( value.data() ); 00070 } 00071 00072 int KJSEmbed::extractInt( KJS::ExecState *exec, const KJS::List &args, int idx, int defaultValue ) 00073 { 00074 if( args.size() > idx ) 00075 { 00076 return extractInt( exec, args[idx] ); 00077 } 00078 return defaultValue; 00079 } 00080 00081 int KJSEmbed::extractInt( KJS::ExecState *exec, KJS::JSValue *value, int defaultValue ) 00082 { 00083 if( !value ) 00084 return defaultValue; 00085 return int( value->toInteger(exec) ); 00086 } 00087 00088 KJS::JSValue *KJSEmbed::createQString( KJS::ExecState *exec, const QString &value ) 00089 { 00090 Q_UNUSED( exec ); 00091 return KJS::jsString( toUString(value) ); 00092 } 00093 00094 KJS::JSValue *KJSEmbed::createInt( KJS::ExecState *exec, int value ) 00095 { 00096 Q_UNUSED( exec ); 00097 return KJS::jsNumber( value ); 00098 } 00099 00100 double KJSEmbed::extractDouble( KJS::ExecState *exec, const KJS::List &args, int idx, double defaultValue ) 00101 { 00102 if( args.size() > idx ) 00103 { 00104 return extractDouble( exec, args[idx] ); 00105 } 00106 return defaultValue; 00107 } 00108 00109 double KJSEmbed::extractDouble( KJS::ExecState *exec, KJS::JSValue *value, double defaultValue ) 00110 { 00111 if( !value ) 00112 return defaultValue; 00113 return (double) value->toNumber(exec); 00114 } 00115 00116 00117 KJS::JSValue *KJSEmbed::createDouble( KJS::ExecState *exec, double value ) 00118 { 00119 Q_UNUSED( exec ); 00120 return KJS::jsNumber( value ); 00121 } 00122 00123 00124 float KJSEmbed::extractFloat( KJS::ExecState *exec, const KJS::List &args, int idx, float defaultValue ) 00125 { 00126 if( args.size() > idx ) 00127 { 00128 return extractFloat( exec, args[idx] ); 00129 } 00130 return defaultValue; 00131 } 00132 00133 00134 float KJSEmbed::extractFloat( KJS::ExecState *exec, KJS::JSValue *value, float defaultValue ) 00135 { 00136 if( !value ) 00137 return defaultValue; 00138 return (float) value->toNumber(exec); 00139 } 00140 00141 00142 KJS::JSValue *KJSEmbed::createFloat( KJS::ExecState *exec, float value ) 00143 { 00144 Q_UNUSED( exec ); 00145 return KJS::jsNumber( value ); 00146 } 00147 00148 00149 bool KJSEmbed::extractBool( KJS::ExecState *exec, const KJS::List &args, int idx, bool defaultValue ) 00150 { 00151 if( args.size() > idx ) 00152 { 00153 return extractBool( exec, args[idx] ); 00154 } 00155 return defaultValue; 00156 } 00157 00158 00159 bool KJSEmbed::extractBool( KJS::ExecState *exec, KJS::JSValue *value, bool defaultValue ) 00160 { 00161 if( !value ) 00162 return defaultValue; 00163 return value->toBoolean(exec); 00164 } 00165 00166 00167 KJS::JSValue *KJSEmbed::createBool( KJS::ExecState *exec, bool value ) 00168 { 00169 Q_UNUSED( exec ); 00170 return KJS::jsBoolean( value ); 00171 } 00172 00173 00174 QDateTime KJSEmbed::extractQDateTime( KJS::ExecState* /* exec */, const KJS::List& /* args */, int /* idx */, const QDateTime& /* defaultValue */ ) 00175 { 00176 return QDateTime(); 00177 } 00178 00179 00180 QDateTime KJSEmbed::extractQDateTime( KJS::ExecState* /* exec */, KJS::JSValue* /* value */, const QDateTime& /* defaultValue */ ) 00181 { 00182 return QDateTime(); 00183 } 00184 00185 00186 KJS::JSValue *KJSEmbed::createQDateTime( KJS::ExecState* /* exec */, const QDateTime& /* value */ ) 00187 { 00188 // return new KJS::JSValue(); 00189 return 0; 00190 } 00191 00192 00193 QDate KJSEmbed::extractQDate( KJS::ExecState* /* exec */, const KJS::List& /* args */, int /* idx */, const QDate& /* defaultValue */ ) 00194 { 00195 return QDate(); 00196 } 00197 00198 00199 QDate KJSEmbed::extractQDate( KJS::ExecState* /*exec*/, KJS::JSValue* /*value*/, const QDate& /*defaultValue*/ ) 00200 { 00201 return QDate(); 00202 } 00203 00204 00205 KJS::JSValue *KJSEmbed::createQDate( KJS::ExecState* /*exec*/, const QDate& /*value*/ ) 00206 { 00207 // return new KJS::JSValue(); 00208 return 0; 00209 } 00210 00211 00212 QTime KJSEmbed::extractQTime( KJS::ExecState* /*exec*/, const KJS::List& /*args*/, int /*idx*/, const QTime& /*defaultValue*/ ) 00213 { 00214 return QTime(); 00215 } 00216 00217 00218 QTime KJSEmbed::extractQTime( KJS::ExecState * /*exec*/, KJS::JSValue* /*value*/, const QTime &/*defaultValue*/ ) 00219 { 00220 return QTime(); 00221 } 00222 00223 00224 KJS::JSValue *KJSEmbed::createQTime( KJS::ExecState * /*exec*/, const QTime &/*value*/ ) 00225 { 00226 // return new KJS::JSValue(); 00227 return 0; 00228 } 00229 00230 00231 QStringList KJSEmbed::extractQStringList( KJS::ExecState * /*exec*/, const KJS::List &/*args*/, int /*idx*/, const QStringList &/*defaultValue*/ ) 00232 { 00233 return QStringList(); 00234 } 00235 00236 00237 QStringList KJSEmbed::extractQStringList( KJS::ExecState * /*exec*/, KJS::JSValue* /*value*/, const QStringList &/*defaultValue*/ ) 00238 { 00239 return QStringList(); 00240 } 00241 00242 00243 KJS::JSValue *KJSEmbed::createQStringList( KJS::ExecState * /*exec*/, const QStringList &/*value*/ ) 00244 { 00245 // return new KJS::JSValue(); 00246 return 0; 00247 } 00248 //kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle; 00249 00250
KDE 4.6 API Reference