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"
|
2014-03-03 20:00:30 +00:00
|
|
|
#include "qv4function_p.h"
|
2013-04-15 09:50:16 +00:00
|
|
|
#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 {
|
2014-04-29 08:48:39 +00:00
|
|
|
struct Data : Object::Data {
|
2014-05-08 13:32:31 +00:00
|
|
|
Data(ExecutionContext *scope, String *name, bool createProto = false);
|
|
|
|
Data(ExecutionContext *scope, const QString &name = QString(), bool createProto = false);
|
|
|
|
Data(ExecutionContext *scope, const ReturnedValue name);
|
|
|
|
Data(InternalClass *ic);
|
|
|
|
~Data();
|
|
|
|
|
2014-04-29 08:48:39 +00:00
|
|
|
ExecutionContext *scope;
|
|
|
|
Function *function;
|
|
|
|
};
|
|
|
|
struct {
|
|
|
|
ExecutionContext *scope;
|
|
|
|
Function *function;
|
|
|
|
|
|
|
|
} __data;
|
2014-04-30 18:50:42 +00:00
|
|
|
V4_OBJECT
|
2013-12-06 09:28:50 +00:00
|
|
|
Q_MANAGED_TYPE(FunctionObject)
|
|
|
|
enum {
|
|
|
|
IsFunctionObject = true
|
|
|
|
};
|
2013-05-24 15:02:48 +00:00
|
|
|
// Used with Managed::subType
|
|
|
|
enum FunctionType {
|
|
|
|
RegularFunction = 0,
|
2013-11-14 21:08:00 +00:00
|
|
|
WrappedQtMethod = 1,
|
|
|
|
BoundFunction
|
2013-05-24 15:02:48 +00:00
|
|
|
};
|
|
|
|
|
2013-09-01 19:22:57 +00:00
|
|
|
enum {
|
|
|
|
Index_Prototype = 0,
|
|
|
|
Index_ProtoConstructor = 0
|
|
|
|
};
|
|
|
|
|
2014-04-05 22:29:53 +00:00
|
|
|
|
2014-04-29 08:48:39 +00:00
|
|
|
ExecutionContext *scope() { return d()->scope; }
|
|
|
|
Function *function() { return d()->function; }
|
2014-04-05 22:29:53 +00:00
|
|
|
|
2014-03-04 12:19:27 +00:00
|
|
|
ReturnedValue name();
|
2014-04-05 22:29:53 +00:00
|
|
|
unsigned int formalParameterCount() { return function() ? function()->compiledFunction->nFormals : 0; }
|
|
|
|
unsigned int varCount() { return function() ? function()->compiledFunction->nLocals : 0; }
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2014-05-07 11:33:24 +00:00
|
|
|
void init(String *name, bool createProto);
|
2013-09-19 14:05:25 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
ReturnedValue newInstance();
|
2013-05-06 10:43:39 +00:00
|
|
|
|
2014-01-20 12:51:00 +00:00
|
|
|
using Object::construct;
|
|
|
|
using Object::call;
|
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);
|
2014-05-08 13:32:31 +00:00
|
|
|
static void destroy(Managed *m) {
|
|
|
|
static_cast<FunctionObject *>(m)->d()->~Data();
|
|
|
|
}
|
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();
|
|
|
|
}
|
|
|
|
|
2014-05-09 09:35:47 +00:00
|
|
|
static Data *createScriptFunction(ExecutionContext *scope, Function *function, bool createProto = true);
|
2013-08-21 12:52:15 +00:00
|
|
|
|
2014-04-05 18:47:36 +00:00
|
|
|
ReturnedValue protoProperty() { return memberData()[Index_Prototype].asReturnedValue(); }
|
2013-11-14 21:08:00 +00:00
|
|
|
|
2014-04-30 18:55:41 +00:00
|
|
|
bool needsActivation() const { return d()->needsActivation; }
|
|
|
|
bool strictMode() const { return d()->strictMode; }
|
|
|
|
bool bindingKeyFlag() const { return d()->bindingKeyFlag; }
|
2014-04-05 18:23:20 +00:00
|
|
|
|
2013-11-02 15:30:26 +00:00
|
|
|
static void markObjects(Managed *that, ExecutionEngine *e);
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2013-09-16 20:02:27 +00:00
|
|
|
template<>
|
|
|
|
inline FunctionObject *value_cast(const Value &v) {
|
|
|
|
return v.asFunctionObject();
|
|
|
|
}
|
|
|
|
|
2013-01-21 20:26:25 +00:00
|
|
|
struct FunctionCtor: FunctionObject
|
|
|
|
{
|
2014-05-09 09:35:47 +00:00
|
|
|
struct Data : FunctionObject::Data {
|
|
|
|
Data(ExecutionContext *scope);
|
|
|
|
};
|
|
|
|
|
2014-04-30 18:50:42 +00:00
|
|
|
V4_OBJECT
|
2013-01-21 20:26:25 +00:00
|
|
|
|
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-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct FunctionPrototype: FunctionObject
|
|
|
|
{
|
2014-05-09 10:15:23 +00:00
|
|
|
struct Data : FunctionObject::Data {
|
|
|
|
Data(InternalClass *ic);
|
|
|
|
};
|
|
|
|
V4_OBJECT
|
|
|
|
|
2014-05-07 14:14:08 +00:00
|
|
|
void init(ExecutionEngine *engine, Object *ctor);
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2013-11-03 14:23:05 +00:00
|
|
|
static ReturnedValue method_toString(CallContext *ctx);
|
|
|
|
static ReturnedValue method_apply(CallContext *ctx);
|
|
|
|
static ReturnedValue method_call(CallContext *ctx);
|
|
|
|
static ReturnedValue method_bind(CallContext *ctx);
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2013-09-12 07:23:34 +00:00
|
|
|
struct BuiltinFunction: FunctionObject {
|
2014-04-29 08:48:39 +00:00
|
|
|
struct Data : FunctionObject::Data {
|
2014-05-09 09:35:47 +00:00
|
|
|
Data(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *));
|
2014-04-05 22:36:23 +00:00
|
|
|
ReturnedValue (*code)(CallContext *);
|
|
|
|
};
|
2014-04-29 08:48:39 +00:00
|
|
|
struct {
|
|
|
|
ReturnedValue (*code)(CallContext *);
|
|
|
|
} __data;
|
2014-04-30 18:50:42 +00:00
|
|
|
V4_OBJECT
|
2013-01-21 20:26:25 +00:00
|
|
|
|
2014-05-09 09:35:47 +00:00
|
|
|
static BuiltinFunction::Data *create(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *))
|
|
|
|
{
|
|
|
|
return new (scope->engine()) Data(scope, name, code);
|
|
|
|
}
|
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-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2013-06-07 05:53:21 +00:00
|
|
|
struct IndexedBuiltinFunction: FunctionObject
|
|
|
|
{
|
2014-04-29 08:48:39 +00:00
|
|
|
struct Data : FunctionObject::Data {
|
2014-05-08 13:32:31 +00:00
|
|
|
Data(ExecutionContext *scope, uint index, ReturnedValue (*code)(CallContext *ctx, uint index))
|
|
|
|
: FunctionObject::Data(scope),
|
|
|
|
code(code)
|
|
|
|
, index(index)
|
|
|
|
{
|
|
|
|
setVTable(staticVTable());
|
|
|
|
}
|
2014-04-29 08:48:39 +00:00
|
|
|
ReturnedValue (*code)(CallContext *, uint index);
|
2014-04-05 22:36:23 +00:00
|
|
|
uint index;
|
|
|
|
};
|
2014-04-29 08:48:39 +00:00
|
|
|
struct {
|
|
|
|
ReturnedValue (*code)(CallContext *, uint index);
|
|
|
|
uint index;
|
|
|
|
} __data;
|
2014-04-30 18:50:42 +00:00
|
|
|
V4_OBJECT
|
2013-06-07 05:53:21 +00:00
|
|
|
|
2013-09-11 13:09:25 +00:00
|
|
|
static ReturnedValue construct(Managed *m, CallData *)
|
2013-06-07 05:53:21 +00:00
|
|
|
{
|
2013-11-21 15:41:32 +00:00
|
|
|
return m->engine()->currentContext()->throwTypeError();
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
2014-03-05 07:40:11 +00:00
|
|
|
struct SimpleScriptFunction: FunctionObject {
|
2014-05-09 09:35:47 +00:00
|
|
|
struct Data : FunctionObject::Data {
|
|
|
|
Data(ExecutionContext *scope, Function *function, bool createProto);
|
|
|
|
};
|
2014-04-30 18:50:42 +00:00
|
|
|
V4_OBJECT
|
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);
|
2014-03-05 07:40:11 +00:00
|
|
|
|
|
|
|
InternalClass *internalClassForConstructor();
|
2013-01-21 20:26:25 +00:00
|
|
|
};
|
|
|
|
|
2014-03-05 07:40:11 +00:00
|
|
|
struct ScriptFunction: SimpleScriptFunction {
|
2014-05-09 09:35:47 +00:00
|
|
|
struct Data : SimpleScriptFunction::Data {
|
|
|
|
Data(ExecutionContext *scope, Function *function);
|
|
|
|
};
|
2014-04-30 18:50:42 +00:00
|
|
|
V4_OBJECT
|
2013-08-21 12:52:15 +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-08-21 12:52:15 +00:00
|
|
|
};
|
|
|
|
|
2014-03-05 07:40:11 +00:00
|
|
|
|
2013-01-21 20:26:25 +00:00
|
|
|
struct BoundFunction: FunctionObject {
|
2014-04-29 08:48:39 +00:00
|
|
|
struct Data : FunctionObject::Data {
|
2014-05-09 09:35:47 +00:00
|
|
|
Data(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const Members &boundArgs);
|
2014-04-05 22:36:23 +00:00
|
|
|
FunctionObject *target;
|
|
|
|
Value boundThis;
|
|
|
|
Members boundArgs;
|
|
|
|
};
|
2014-04-29 08:48:39 +00:00
|
|
|
struct {
|
|
|
|
FunctionObject *target;
|
|
|
|
Value boundThis;
|
|
|
|
Members boundArgs;
|
|
|
|
} __data;
|
2014-04-30 18:50:42 +00:00
|
|
|
V4_OBJECT
|
2014-04-05 22:36:23 +00:00
|
|
|
|
2014-05-09 09:35:47 +00:00
|
|
|
static BoundFunction::Data *create(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const QV4::Members &boundArgs)
|
|
|
|
{
|
|
|
|
return new (scope->engine()) Data(scope, target, boundThis, boundArgs);
|
|
|
|
}
|
|
|
|
|
2014-04-29 08:48:39 +00:00
|
|
|
FunctionObject *target() { return d()->target; }
|
|
|
|
Value boundThis() const { return d()->boundThis; }
|
|
|
|
Members boundArgs() const { return d()->boundArgs; }
|
2013-01-21 20:26:25 +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
|
|
|
|
2013-11-02 15:30:26 +00:00
|
|
|
static void markObjects(Managed *that, ExecutionEngine *e);
|
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
|