]> git.saurik.com Git - apple/javascriptcore.git/blob - qt/api/qscriptengine.cpp
f12f4103287ca522206667a192b92382a2149f4a
[apple/javascriptcore.git] / qt / api / qscriptengine.cpp
1 /*
2 Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies)
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Library General Public
6 License as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
13
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
18 */
19
20 #include "config.h"
21
22 #include "qscriptengine.h"
23
24 #include "qscriptengine_p.h"
25 #include "qscriptvalue_p.h"
26
27 /*!
28 Constructs a QScriptEngine object.
29
30 The globalObject() is initialized to have properties as described in ECMA-262, Section 15.1.
31 */
32 QScriptEngine::QScriptEngine()
33 : d_ptr(new QScriptEnginePrivate(this))
34 {
35 }
36
37 /*!
38 Destroys this QScriptEngine.
39 */
40 QScriptEngine::~QScriptEngine()
41 {
42 }
43
44 /*!
45 Evaluates \a program, using \a lineNumber as the base line number,
46 and returns the result of the evaluation.
47
48 The script code will be evaluated in the current context.
49
50 The evaluation of \a program can cause an exception in the
51 engine; in this case the return value will be the exception
52 that was thrown (typically an \c{Error} object). You can call
53 hasUncaughtException() to determine if an exception occurred in
54 the last call to evaluate().
55
56 \a lineNumber is used to specify a starting line number for \a
57 program; line number information reported by the engine that pertain
58 to this evaluation (e.g. uncaughtExceptionLineNumber()) will be
59 based on this argument. For example, if \a program consists of two
60 lines of code, and the statement on the second line causes a script
61 exception, uncaughtExceptionLineNumber() would return the given \a
62 lineNumber plus one. When no starting line number is specified, line
63 numbers will be 1-based.
64
65 \a fileName is used for error reporting. For example in error objects
66 the file name is accessible through the "fileName" property if it's
67 provided with this function.
68 */
69 QScriptValue QScriptEngine::evaluate(const QString& program, const QString& fileName, int lineNumber)
70 {
71 return QScriptValuePrivate::get(d_ptr->evaluate(program, fileName, lineNumber));
72 }
73
74 /*!
75 Runs the garbage collector.
76
77 The garbage collector will attempt to reclaim memory by locating and disposing of objects that are
78 no longer reachable in the script environment.
79
80 Normally you don't need to call this function; the garbage collector will automatically be invoked
81 when the QScriptEngine decides that it's wise to do so (i.e. when a certain number of new objects
82 have been created). However, you can call this function to explicitly request that garbage
83 collection should be performed as soon as possible.
84 */
85 void QScriptEngine::collectGarbage()
86 {
87 d_ptr->collectGarbage();
88 }