| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com)
|
|---|
| 5 | **
|
|---|
| 6 | ** This file is part of the QtScript module of the Qt Toolkit.
|
|---|
| 7 | **
|
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 9 | ** Commercial Usage
|
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 13 | ** a written agreement between you and Nokia.
|
|---|
| 14 | **
|
|---|
| 15 | ** GNU Lesser General Public License Usage
|
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 19 | ** packaging of this file. Please review the following information to
|
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 22 | **
|
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain
|
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL
|
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
|
|---|
| 26 | ** package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please
|
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com.
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | #include "qscriptfunction_p.h"
|
|---|
| 43 |
|
|---|
| 44 | #ifndef QT_NO_SCRIPT
|
|---|
| 45 |
|
|---|
| 46 | #include "qscriptengine_p.h"
|
|---|
| 47 | #include "qscriptvalueimpl_p.h"
|
|---|
| 48 | #include "qscriptcontext_p.h"
|
|---|
| 49 | #include "qscriptmember_p.h"
|
|---|
| 50 | #include "qscriptobject_p.h"
|
|---|
| 51 |
|
|---|
| 52 | QT_BEGIN_NAMESPACE
|
|---|
| 53 |
|
|---|
| 54 | QScriptFunction::~QScriptFunction()
|
|---|
| 55 | {
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | QString QScriptFunction::toString(QScriptContextPrivate *) const
|
|---|
| 59 | {
|
|---|
| 60 | QString result;
|
|---|
| 61 | result += QLatin1String("function () { [native] }");
|
|---|
| 62 | return result;
|
|---|
| 63 | }
|
|---|
| 64 |
|
|---|
| 65 | QString QScriptFunction::fileName() const
|
|---|
| 66 | {
|
|---|
| 67 | return QString();
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | QString QScriptFunction::functionName() const
|
|---|
| 71 | {
|
|---|
| 72 | return QString();
|
|---|
| 73 | }
|
|---|
| 74 |
|
|---|
| 75 | int QScriptFunction::startLineNumber() const
|
|---|
| 76 | {
|
|---|
| 77 | return -1;
|
|---|
| 78 | }
|
|---|
| 79 |
|
|---|
| 80 | int QScriptFunction::endLineNumber() const
|
|---|
| 81 | {
|
|---|
| 82 | return -1;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | void QScriptFunction::mark(QScriptEnginePrivate *engine, int generation)
|
|---|
| 86 | {
|
|---|
| 87 | for (int i = 0; i < formals.count(); ++i)
|
|---|
| 88 | engine->markString(formals.at(i), generation);
|
|---|
| 89 | }
|
|---|
| 90 |
|
|---|
| 91 | // public API function
|
|---|
| 92 | void QScript::CFunction::execute(QScriptContextPrivate *context)
|
|---|
| 93 | {
|
|---|
| 94 | QScriptEnginePrivate *eng_p = context->engine();
|
|---|
| 95 |
|
|---|
| 96 | context->m_result = eng_p->undefinedValue();
|
|---|
| 97 |
|
|---|
| 98 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 99 | eng_p->notifyFunctionEntry(context);
|
|---|
| 100 | #endif
|
|---|
| 101 |
|
|---|
| 102 | QScriptContext *publicContext = QScriptContextPrivate::get(eng_p->currentContext());
|
|---|
| 103 | QScriptEngine *publicEngine = QScriptEnginePrivate::get(eng_p);
|
|---|
| 104 | QScriptValueImpl result = eng_p->toImpl((*m_funPtr)(publicContext, publicEngine));
|
|---|
| 105 | if (result.isValid() && !eng_p->shouldAbort()
|
|---|
| 106 | && (context->state() == QScriptContext::NormalState)) {
|
|---|
| 107 | context->m_result = result;
|
|---|
| 108 | }
|
|---|
| 109 |
|
|---|
| 110 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 111 | eng_p->notifyFunctionExit(context);
|
|---|
| 112 | #endif
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | QString QScript::CFunction::functionName() const
|
|---|
| 116 | {
|
|---|
| 117 | return QString();
|
|---|
| 118 | }
|
|---|
| 119 |
|
|---|
| 120 | // internal API function
|
|---|
| 121 | void QScript::C2Function::execute(QScriptContextPrivate *context)
|
|---|
| 122 | {
|
|---|
| 123 | QScriptEnginePrivate *eng_p = context->engine();
|
|---|
| 124 |
|
|---|
| 125 | bool blocked = eng_p->blockGC(true);
|
|---|
| 126 |
|
|---|
| 127 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 128 | eng_p->notifyFunctionEntry(context);
|
|---|
| 129 | #endif
|
|---|
| 130 |
|
|---|
| 131 | context->m_result = (*m_funPtr)(context, eng_p, m_classInfo);
|
|---|
| 132 | Q_ASSERT(context->m_result.isValid());
|
|---|
| 133 |
|
|---|
| 134 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 135 | eng_p->notifyFunctionExit(context);
|
|---|
| 136 | #endif
|
|---|
| 137 |
|
|---|
| 138 | eng_p->blockGC(blocked);
|
|---|
| 139 | }
|
|---|
| 140 |
|
|---|
| 141 | QString QScript::C2Function::functionName() const
|
|---|
| 142 | {
|
|---|
| 143 | if (!m_name.isEmpty())
|
|---|
| 144 | return m_name;
|
|---|
| 145 | return QString();
|
|---|
| 146 | }
|
|---|
| 147 |
|
|---|
| 148 | void QScript::C3Function::execute(QScriptContextPrivate *context)
|
|---|
| 149 | {
|
|---|
| 150 | QScriptEnginePrivate *eng_p = context->engine();
|
|---|
| 151 |
|
|---|
| 152 | context->m_result = eng_p->undefinedValue();
|
|---|
| 153 |
|
|---|
| 154 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 155 | eng_p->notifyFunctionEntry(context);
|
|---|
| 156 | #endif
|
|---|
| 157 |
|
|---|
| 158 | QScriptContext *publicContext = QScriptContextPrivate::get(eng_p->currentContext());
|
|---|
| 159 | QScriptEngine *publicEngine = QScriptEnginePrivate::get(eng_p);
|
|---|
| 160 | QScriptValueImpl result = eng_p->toImpl((*m_funPtr)(publicContext, publicEngine, m_arg));
|
|---|
| 161 | if (result.isValid() && !eng_p->shouldAbort())
|
|---|
| 162 | context->m_result = result;
|
|---|
| 163 |
|
|---|
| 164 | #ifndef Q_SCRIPT_NO_EVENT_NOTIFY
|
|---|
| 165 | eng_p->notifyFunctionExit(context);
|
|---|
| 166 | #endif
|
|---|
| 167 | }
|
|---|
| 168 |
|
|---|
| 169 | QT_END_NAMESPACE
|
|---|
| 170 |
|
|---|
| 171 | #endif // QT_NO_SCRIPT
|
|---|