25#include <QtCore/QCoreApplication>
26#include <QtCore/QFile>
27#include <QtGui/QMessageBox>
28#include <QtCore/QTextStream>
29#include <QtCore/QDebug>
30#include <QtCore/QMetaType>
33#include <kstandarddirs.h>
44KJS::JSValue *
callExec( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
49 return KJS::jsBoolean( QCoreApplication::exec() );
52KJS::JSValue *
callDump( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
57 KJS::JSObject *
object = args[0]->toObject(exec);
63KJS::JSValue *
callInclude( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
68 KJS::UString filename = args[0]->toString(exec);
69 qDebug() <<
"include: " <<
toQString(filename);
71 KJS::Completion c =
Engine::runFile( exec->dynamicInterpreter(), filename );
73 if ( c.complType() == KJS::Normal )
76 if (c.complType() == KJS::ReturnValue)
78 if (c.isValueCompletion())
84 if (c.complType() == KJS::Throw)
86 QString message =
toQString(c.value()->toString(exec));
87 int line = c.value()->toObject(exec)->get(exec,
"line")->toUInt32(exec);
88 return throwError(exec, KJS::EvalError,
89 toUString(i18n(
"Error encountered while processing include '%1' line %2: %3",
toQString(filename), line, message)));
94 return throwError(exec, KJS::URIError,
95 toUString(i18n(
"include only takes 1 argument, not %1.", args.size())));
103KJS::JSValue *
callLibrary( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
106 if( args.size() == 1)
108 KJS::UString filename = args[0]->toString(exec);
109 QString qualifiedFilename = KStandardDirs::locate(
"scripts",
toQString(filename) );
110 if ( !qualifiedFilename.isEmpty() )
113 if ( c.complType() == KJS::Normal )
114 return KJS::jsNull();
116 if (c.complType() == KJS::ReturnValue)
118 if (c.isValueCompletion())
121 return KJS::jsNull();
124 if (c.complType() == KJS::Throw)
126 QString message =
toQString(c.value()->toString(exec));
127 int line = c.value()->toObject(exec)->get(exec,
"line")->toUInt32(exec);
128 return throwError(exec, KJS::EvalError,
129 toUString(i18n(
"Error encountered while processing include '%1' line %2: %3",
toQString(filename), line, message)));
133 QString msg = i18n(
"File %1 not found.",
toQString(filename) );
134 return throwError( exec, KJS::URIError,
toUString(msg) );
138 return throwError(exec, KJS::URIError,
139 toUString(i18n(
"library only takes 1 argument, not %1.", args.size())));
142 return KJS::jsNull();
147KJS::JSValue *
callAlert( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
150 if (args.size() == 1)
153 QString message =
toQString(args[0]->toString(exec));
154 QMessageBox::warning(0, i18n(
"Alert"), message, QMessageBox::Ok, QMessageBox::NoButton);
156 return KJS::jsNull();
159KJS::JSValue *
callConfirm( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
162 if (args.size() == 1)
164 QString message =
toQString(args[0]->toString(exec));
165 int result = QMessageBox::question (0, i18n(
"Confirm"), message, QMessageBox::Yes, QMessageBox::No);
166 if (
result == QMessageBox::Yes)
167 return KJS::jsBoolean(
true);
169 return KJS::jsBoolean(
false);
172KJS::JSValue *
callIsVariantType( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
175 if (args.size() == 1)
177 QString thetypename =
toQString(args[0]->toString(exec));
178 return KJS::jsBoolean( QMetaType::type( thetypename.toLatin1().data() ) );
180 return KJS::jsBoolean(
false);
183KJS::JSValue *
callIsVariant( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
186 if (args.size() == 1)
188 KJS::JSObject *obj = args[0]->toObject(exec);
191 return KJS::jsBoolean(
true);
194 return KJS::jsBoolean(
false);
197KJS::JSValue *
callIsObject( KJS::ExecState *exec, KJS::JSObject *self,
const KJS::List &args )
200 if (args.size() == 1)
202 KJS::JSObject *obj = args[0]->toObject(exec);
205 return KJS::jsBoolean(
true);
208 return KJS::jsBoolean(
false);
213 {
"exec", 0, KJS::DontDelete|KJS::ReadOnly, &
callExec},
214 {
"dump", 1, KJS::DontDelete|KJS::ReadOnly, &
callDump},
215 {
"include", 1, KJS::DontDelete|KJS::ReadOnly, &
callInclude},
217 {
"library", 1, KJS::DontDelete|KJS::ReadOnly, &
callLibrary},
219 {
"alert", 1, KJS::DontDelete|KJS::ReadOnly, &
callAlert},
220 {
"confirm", 1, KJS::DontDelete|KJS::ReadOnly, &
callConfirm},
222 {
"isVariant", 1, KJS::DontDelete|KJS::ReadOnly, &
callIsVariant},
223 {
"isObject", 1, KJS::DontDelete|KJS::ReadOnly, &
callIsObject},
KJS::JSValue * callIsObject(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callLibrary(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callDump(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callIsVariant(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callIsVariantType(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callExec(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callAlert(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callConfirm(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
KJS::JSValue * callInclude(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
static const Method BuiltinMethods[]
ExitStatus runFile(const KJS::UString &file)
Execute the file with the specified name using the current interpreter.
static const KJS::ClassInfo info
static const KJS::ClassInfo info
END_VARIANT_METHOD result
QString toQString(const KJS::UString &u)
KJSEMBED_EXPORT QTextStream * conerr()
KJS::UString toUString(const QString &qs)