• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

kjsembed

  • kjsembed
  • kjsembed
builtins.cpp
Go to the documentation of this file.
1/* This file is part of the KDE libraries
2 Copyright (C) 2005, 2006 Ian Reinhart Geiser <geiseri@kde.org>
3 Copyright (C) 2005, 2006 Matt Broadstone <mbroadst@gmail.com>
4 Copyright (C) 2005, 2006 Richard J. Moore <rich@kde.org>
5 Copyright (C) 2005, 2006 Erik L. Bunce <kde@bunce.us>
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
23#include "builtins.h"
24
25#include <QtCore/QCoreApplication>
26#include <QtCore/QFile>
27#include <QtGui/QMessageBox>
28#include <QtCore/QTextStream>
29#include <QtCore/QDebug>
30#include <QtCore/QMetaType>
31
32#ifndef QT_ONLY
33#include <kstandarddirs.h>
34#endif // QT_ONLY
35
36
37#include "variant_binding.h"
38#include "object_binding.h"
39#include "static_binding.h"
40#include "kjsembed.h"
41
42using namespace KJSEmbed;
43
44KJS::JSValue *callExec( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
45{
46 Q_UNUSED(exec);
47 Q_UNUSED(self);
48 Q_UNUSED(args);
49 return KJS::jsBoolean( QCoreApplication::exec() );
50}
51
52KJS::JSValue *callDump( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
53{
54 Q_UNUSED(self);
55 if( args.size() == 1)
56 {
57 KJS::JSObject *object = args[0]->toObject(exec);
58 Q_UNUSED(object);
59 }
60 return KJS::jsNull();
61}
62
63KJS::JSValue *callInclude( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
64{
65 Q_UNUSED(self);
66 if( args.size() == 1)
67 {
68 KJS::UString filename = args[0]->toString(exec);
69 qDebug() << "include: " << toQString(filename);
70
71 KJS::Completion c = Engine::runFile( exec->dynamicInterpreter(), filename );
72
73 if ( c.complType() == KJS::Normal )
74 return KJS::jsNull();
75
76 if (c.complType() == KJS::ReturnValue)
77 {
78 if (c.isValueCompletion())
79 return c.value();
80
81 return KJS::jsNull();
82 }
83
84 if (c.complType() == KJS::Throw)
85 {
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)));
90 }
91 }
92 else
93 {
94 return throwError(exec, KJS::URIError,
95 toUString(i18n("include only takes 1 argument, not %1.", args.size())));
96 }
97
98 return KJS::jsNull();
99}
100
101#ifndef QT_ONLY
102
103KJS::JSValue *callLibrary( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
104{
105 Q_UNUSED(self);
106 if( args.size() == 1)
107 {
108 KJS::UString filename = args[0]->toString(exec);
109 QString qualifiedFilename = KStandardDirs::locate( "scripts", toQString(filename) );
110 if ( !qualifiedFilename.isEmpty() )
111 {
112 KJS::Completion c = Engine::runFile( exec->dynamicInterpreter(), toUString(qualifiedFilename) );
113 if ( c.complType() == KJS::Normal )
114 return KJS::jsNull();
115
116 if (c.complType() == KJS::ReturnValue)
117 {
118 if (c.isValueCompletion())
119 return c.value();
120
121 return KJS::jsNull();
122 }
123
124 if (c.complType() == KJS::Throw)
125 {
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)));
130 }
131 }
132 else {
133 QString msg = i18n( "File %1 not found.", toQString(filename) );
134 return throwError( exec, KJS::URIError, toUString(msg) );
135 }
136 }
137 else {
138 return throwError(exec, KJS::URIError,
139 toUString(i18n("library only takes 1 argument, not %1.", args.size())));
140 }
141
142 return KJS::jsNull();
143}
144
145#endif // QT_ONLY
146
147KJS::JSValue *callAlert( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
148{
149 Q_UNUSED(self)
150 if (args.size() == 1)
151 {
152 (*KJSEmbed::conerr()) << "callAlert";
153 QString message = toQString(args[0]->toString(exec));
154 QMessageBox::warning(0, i18n("Alert"), message, QMessageBox::Ok, QMessageBox::NoButton);
155 }
156 return KJS::jsNull();
157}
158
159KJS::JSValue *callConfirm( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
160{
161 Q_UNUSED(self)
162 if (args.size() == 1)
163 {
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);
168 }
169 return KJS::jsBoolean(false);
170}
171
172KJS::JSValue *callIsVariantType( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
173{
174 Q_UNUSED(self)
175 if (args.size() == 1)
176 {
177 QString thetypename = toQString(args[0]->toString(exec));
178 return KJS::jsBoolean( QMetaType::type( thetypename.toLatin1().data() ) );
179 }
180 return KJS::jsBoolean(false);
181}
182
183KJS::JSValue *callIsVariant( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
184{
185 Q_UNUSED(self)
186 if (args.size() == 1)
187 {
188 KJS::JSObject *obj = args[0]->toObject(exec);
189 if (obj->inherits(&VariantBinding::info))
190 {
191 return KJS::jsBoolean(true);
192 }
193 }
194 return KJS::jsBoolean(false);
195}
196
197KJS::JSValue *callIsObject( KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args )
198{
199 Q_UNUSED(self)
200 if (args.size() == 1)
201 {
202 KJS::JSObject *obj = args[0]->toObject(exec);
203 if (obj->inherits(&ObjectBinding::info))
204 {
205 return KJS::jsBoolean(true);
206 }
207 }
208 return KJS::jsBoolean(false);
209}
210
211const Method BuiltinsFactory::BuiltinMethods[] =
212{
213 {"exec", 0, KJS::DontDelete|KJS::ReadOnly, &callExec},
214 {"dump", 1, KJS::DontDelete|KJS::ReadOnly, &callDump},
215 {"include", 1, KJS::DontDelete|KJS::ReadOnly, &callInclude},
216#ifndef QT_ONLY
217 {"library", 1, KJS::DontDelete|KJS::ReadOnly, &callLibrary},
218#endif // QT_ONLY
219 {"alert", 1, KJS::DontDelete|KJS::ReadOnly, &callAlert},
220 {"confirm", 1, KJS::DontDelete|KJS::ReadOnly, &callConfirm},
221 {"isVariantType", 1, KJS::DontDelete|KJS::ReadOnly, &callIsVariantType},
222 {"isVariant", 1, KJS::DontDelete|KJS::ReadOnly, &callIsVariant},
223 {"isObject", 1, KJS::DontDelete|KJS::ReadOnly, &callIsObject},
224 {0, 0, 0, 0 }
225};
226//kate: indent-spaces on; indent-width 4; replace-tabs on; indent-mode cstyle;
callIsObject
KJS::JSValue * callIsObject(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:197
callLibrary
KJS::JSValue * callLibrary(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:103
callDump
KJS::JSValue * callDump(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:52
callIsVariant
KJS::JSValue * callIsVariant(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:183
callIsVariantType
KJS::JSValue * callIsVariantType(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:172
callExec
KJS::JSValue * callExec(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:44
callAlert
KJS::JSValue * callAlert(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:147
callConfirm
KJS::JSValue * callConfirm(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:159
callInclude
KJS::JSValue * callInclude(KJS::ExecState *exec, KJS::JSObject *self, const KJS::List &args)
Definition: builtins.cpp:63
builtins.h
KJSEmbed::BuiltinsFactory::BuiltinMethods
static const Method BuiltinMethods[]
Definition: builtins.h:36
KJSEmbed::Engine::runFile
ExitStatus runFile(const KJS::UString &file)
Execute the file with the specified name using the current interpreter.
Definition: kjsembed.cpp:233
KJSEmbed::ObjectBinding::info
static const KJS::ClassInfo info
Definition: object_binding.h:92
KJSEmbed::VariantBinding::info
static const KJS::ClassInfo info
Definition: variant_binding.h:123
result
END_VARIANT_METHOD result
Definition: color.cpp:85
kjsembed.h
KJSEmbed
Definition: application.h:33
KJSEmbed::toQString
QString toQString(const KJS::UString &u)
Definition: kjseglobal.h:58
KJSEmbed::conerr
KJSEMBED_EXPORT QTextStream * conerr()
Definition: kjseglobal.cpp:143
KJSEmbed::toUString
KJS::UString toUString(const QString &qs)
Definition: kjseglobal.h:66
object_binding.h
static_binding.h
KJSEmbed::Method
Method structure.
Definition: binding_support.h:295
variant_binding.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal