2013-01-21 20:26:25 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
|
2013-01-21 20:26:25 +00:00
|
|
|
** Contact: http://www.qt-project.org/legal
|
|
|
|
**
|
2013-06-24 11:50:51 +00:00
|
|
|
** This file is part of the QtQml module of the Qt Toolkit.
|
2013-01-21 20:26:25 +00:00
|
|
|
**
|
|
|
|
** $QT_BEGIN_LICENSE:LGPL$
|
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
** a written agreement between you and Digia. For licensing terms and
|
|
|
|
** conditions see http://qt.digia.com/licensing. For further information
|
|
|
|
** use the contact form at http://qt.digia.com/contact-us.
|
|
|
|
**
|
|
|
|
** GNU Lesser General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|
|
|
**
|
|
|
|
** In addition, as a special exception, Digia gives you certain additional
|
|
|
|
** rights. These rights are described in the Digia Qt LGPL Exception
|
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
**
|
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3.0 as published by the Free Software
|
|
|
|
** Foundation and appearing in the file LICENSE.GPL included in the
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
** ensure the GNU General Public License version 3.0 requirements will be
|
|
|
|
** met: http://www.gnu.org/copyleft/gpl.html.
|
|
|
|
**
|
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef QV4FUNCTIONOBJECT_H
|
|
|
|
#define QV4FUNCTIONOBJECT_H
|
|
|
|
|
2013-04-15 09:50:16 +00:00
|
|
|
#include "qv4global_p.h"
|
|
|
|
#include "qv4runtime_p.h"
|
|
|
|
#include "qv4engine_p.h"
|
|
|
|
#include "qv4context_p.h"
|
|
|
|
#include "qv4object_p.h"
|
|
|
|
#include "qv4string_p.h"
|
|
|
|
#include "qv4managed_p.h"
|
|
|
|
#include "qv4property_p.h"
|
|
|
|
#include "qv4objectiterator_p.h"
|
2013-01-21 20:26:25 +00:00
|
|
|
|
|
|
|
#include <QtCore/QString>
|
|
|
|
#include <QtCore/QHash>
|
|
|
|
#include <QtCore/QScopedPointer>
|
|
|
|
#include <cstdio>
|
|
|
|
#include <cassert>
|
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
namespace QV4 {
|
2013-01-21 20:26:25 +00:00
|
|
|
|
|
|
|
struct Function;
|
|
|
|
struct Object;
|
|
|
|
struct BooleanObject;
|
|
|
|
struct NumberObject;
|
|
|
|
struct StringObject;
|
|
|
|
struct ArrayObject;
|
|
|
|
struct DateObject;
|
|
|
|
struct FunctionObject;
|
|
|
|
struct ErrorObject;
|
|
|
|
struct ArgumentsObject;
|
|
|
|
struct ExecutionContext;
|
|
|
|
struct ExecutionEngine;
|
|
|
|
class MemoryManager;
|
|
|
|
|
|
|
|
struct ObjectPrototype;
|
|
|
|
struct StringPrototype;
|
|
|
|
struct NumberPrototype;
|
|
|
|
struct BooleanPrototype;
|
|
|
|
struct ArrayPrototype;
|
|
|
|
struct FunctionPrototype;
|
|
|
|
struct DatePrototype;
|
|
|
|
struct ErrorPrototype;
|
|
|
|
struct EvalErrorPrototype;
|
|
|
|
struct RangeErrorPrototype;
|
|
|
|
struct ReferenceErrorPrototype;
|
|
|
|
struct SyntaxErrorPrototype;
|
|
|
|
struct TypeErrorPrototype;
|
|
|
|
struct URIErrorPrototype;
|
2013-02-12 15:23:52 +00:00
|
|
|
struct InternalClass;
|
2013-04-12 15:26:44 +00:00
|
|
|
struct Lookup;
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-04-16 15:03:00 +00:00
|
|
|
struct Q_QML_EXPORT FunctionObject: Object {
|
2013-05-24 15:02:48 +00:00
|
|
|
// Used with Managed::subType
|
|
|
|
enum FunctionType {
|
|
|
|
RegularFunction = 0,
|
|
|
|
WrappedQtMethod = 1
|
|
|
|
};
|
|
|
|
|
2013-09-01 19:22:57 +00:00
|
|
|
enum {
|
|
|
|
Index_Prototype = 0,
|
|
|
|
Index_ProtoConstructor = 0
|
|
|
|
};
|
|
|
|
|
2013-01-21 20:26:25 +00:00
|
|
|
ExecutionContext *scope;
|
|
|
|
String *name;
|
2013-01-29 10:24:43 +00:00
|
|
|
String * const *formalParameterList;
|
|
|
|
String * const *varList;
|
2013-01-21 20:26:25 +00:00
|
|
|
unsigned int formalParameterCount;
|
|
|
|
unsigned int varCount;
|
2013-04-19 11:03:42 +00:00
|
|
|
Function *function;
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-09-01 19:22:57 +00:00
|
|
|
FunctionObject(ExecutionContext *scope, String *name = 0, bool createProto = false);
|
2013-08-09 14:45:02 +00:00
|
|
|
~FunctionObject();
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
ReturnedValue newInstance();
|
2013-05-06 10:43:39 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *that, CallData *);
|
2013-09-11 11:55:01 +00:00
|
|
|
static ReturnedValue call(Managed *that, CallData *d);
|
2013-09-11 13:09:25 +00:00
|
|
|
inline ReturnedValue construct(CallData *callData) {
|
2013-09-06 10:44:12 +00:00
|
|
|
return vtbl->construct(this, callData);
|
2013-05-08 12:24:30 +00:00
|
|
|
}
|
2013-09-11 11:55:01 +00:00
|
|
|
inline ReturnedValue call(CallData *callData) {
|
2013-09-06 10:44:12 +00:00
|
|
|
return vtbl->call(this, callData);
|
2013-05-08 12:24:30 +00:00
|
|
|
}
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-09-11 14:28:17 +00:00
|
|
|
static FunctionObject *cast(const Value &v) {
|
|
|
|
return v.asFunctionObject();
|
|
|
|
}
|
|
|
|
|
2013-08-21 12:52:15 +00:00
|
|
|
static FunctionObject *creatScriptFunction(ExecutionContext *scope, Function *function);
|
|
|
|
|
2013-01-21 20:26:25 +00:00
|
|
|
protected:
|
2013-08-29 19:23:04 +00:00
|
|
|
FunctionObject(InternalClass *ic);
|
|
|
|
|
2013-02-13 22:00:10 +00:00
|
|
|
static const ManagedVTable static_vtbl;
|
|
|
|
static void markObjects(Managed *that);
|
2013-06-21 18:53:13 +00:00
|
|
|
static bool hasInstance(Managed *that, const Value &value);
|
2013-08-09 14:45:02 +00:00
|
|
|
static void destroy(Managed *that)
|
|
|
|
{ static_cast<FunctionObject*>(that)->~FunctionObject(); }
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FunctionCtor: FunctionObject
|
|
|
|
{
|
|
|
|
FunctionCtor(ExecutionContext *scope);
|
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *that, CallData *callData);
|
2013-09-11 11:55:01 +00:00
|
|
|
static ReturnedValue call(Managed *that, CallData *callData);
|
2013-02-14 13:07:57 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static const ManagedVTable static_vtbl;
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FunctionPrototype: FunctionObject
|
|
|
|
{
|
2013-08-29 12:31:32 +00:00
|
|
|
FunctionPrototype(InternalClass *ic);
|
2013-01-21 20:26:25 +00:00
|
|
|
void init(ExecutionContext *ctx, const Value &ctor);
|
|
|
|
|
2013-04-05 19:15:58 +00:00
|
|
|
static Value method_toString(SimpleCallContext *ctx);
|
|
|
|
static Value method_apply(SimpleCallContext *ctx);
|
|
|
|
static Value method_call(SimpleCallContext *ctx);
|
|
|
|
static Value method_bind(SimpleCallContext *ctx);
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2013-09-12 07:23:34 +00:00
|
|
|
struct BuiltinFunction: FunctionObject {
|
2013-04-05 19:15:58 +00:00
|
|
|
Value (*code)(SimpleCallContext *);
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-09-12 07:23:34 +00:00
|
|
|
BuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(SimpleCallContext *));
|
2013-02-14 13:07:57 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *, CallData *);
|
2013-09-11 11:55:01 +00:00
|
|
|
static ReturnedValue call(Managed *that, CallData *callData);
|
2013-02-14 13:07:57 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static const ManagedVTable static_vtbl;
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2013-06-07 05:53:21 +00:00
|
|
|
struct IndexedBuiltinFunction: FunctionObject
|
|
|
|
{
|
|
|
|
Q_MANAGED
|
|
|
|
|
|
|
|
Value (*code)(SimpleCallContext *ctx, uint index);
|
|
|
|
uint index;
|
|
|
|
|
|
|
|
IndexedBuiltinFunction(ExecutionContext *scope, uint index, Value (*code)(SimpleCallContext *ctx, uint index))
|
2013-07-04 13:44:40 +00:00
|
|
|
: FunctionObject(scope, /*name*/0)
|
2013-06-07 05:53:21 +00:00
|
|
|
, code(code)
|
|
|
|
, index(index)
|
|
|
|
{
|
|
|
|
vtbl = &static_vtbl;
|
|
|
|
isBuiltinFunction = true;
|
|
|
|
}
|
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *m, CallData *)
|
2013-06-07 05:53:21 +00:00
|
|
|
{
|
2013-06-22 07:29:23 +00:00
|
|
|
m->engine()->current->throwTypeError();
|
2013-09-11 13:09:25 +00:00
|
|
|
return Value::undefinedValue().asReturnedValue();
|
2013-06-07 05:53:21 +00:00
|
|
|
}
|
|
|
|
|
2013-09-11 11:55:01 +00:00
|
|
|
static ReturnedValue call(Managed *that, CallData *callData);
|
2013-06-07 05:53:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-01-21 20:26:25 +00:00
|
|
|
struct ScriptFunction: FunctionObject {
|
2013-04-19 11:03:42 +00:00
|
|
|
ScriptFunction(ExecutionContext *scope, Function *function);
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *, CallData *callData);
|
2013-09-11 11:55:01 +00:00
|
|
|
static ReturnedValue call(Managed *that, CallData *callData);
|
2013-02-14 13:07:57 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static const ManagedVTable static_vtbl;
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2013-08-21 12:52:15 +00:00
|
|
|
struct SimpleScriptFunction: FunctionObject {
|
|
|
|
SimpleScriptFunction(ExecutionContext *scope, Function *function);
|
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *, CallData *callData);
|
2013-09-11 11:55:01 +00:00
|
|
|
static ReturnedValue call(Managed *that, CallData *callData);
|
2013-08-21 12:52:15 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
static const ManagedVTable static_vtbl;
|
|
|
|
};
|
|
|
|
|
2013-01-21 20:26:25 +00:00
|
|
|
struct BoundFunction: FunctionObject {
|
|
|
|
FunctionObject *target;
|
|
|
|
Value boundThis;
|
|
|
|
QVector<Value> boundArgs;
|
|
|
|
|
|
|
|
BoundFunction(ExecutionContext *scope, FunctionObject *target, Value boundThis, const QVector<Value> &boundArgs);
|
2013-02-14 13:07:57 +00:00
|
|
|
~BoundFunction() {}
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-02-14 14:00:06 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *, CallData *d);
|
2013-09-11 11:55:01 +00:00
|
|
|
static ReturnedValue call(Managed *that, CallData *dd);
|
2013-02-13 22:00:10 +00:00
|
|
|
|
|
|
|
static const ManagedVTable static_vtbl;
|
2013-02-14 14:00:06 +00:00
|
|
|
static void destroy(Managed *);
|
2013-02-13 22:00:10 +00:00
|
|
|
static void markObjects(Managed *that);
|
2013-06-21 18:53:13 +00:00
|
|
|
static bool hasInstance(Managed *that, const Value &value);
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2013-04-19 11:03:42 +00:00
|
|
|
}
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-01-31 09:00:06 +00:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
2013-01-21 20:26:25 +00:00
|
|
|
#endif // QMLJS_OBJECTS_H
|