aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2016-11-29 22:39:28 +0100
committerLars Knoll <lars.knoll@qt.io>2016-12-06 13:01:41 +0000
commit54c79346f1929ff14673e1ab40a1bfd66ba6e2c5 (patch)
tree67261b9c22e0fe6d4ca7ba3c13f5e4d89460766b
parent83aa1933c82333b7ec5128442ac9ee2161387491 (diff)
Use QV4::Function instead of the FunctionObject in CallContext
The prepares for being able to call binding code without having to create a full FunctionObject. Change-Id: I5f0dcaa4d1ae8876554cac82597351801588bc02 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/jsruntime/qv4argumentsobject.cpp9
-rw-r--r--src/qml/jsruntime/qv4context.cpp66
-rw-r--r--src/qml/jsruntime/qv4context_p.h5
-rw-r--r--src/qml/jsruntime/qv4function_p.h8
-rw-r--r--src/qml/jsruntime/qv4functionobject.cpp2
5 files changed, 53 insertions, 37 deletions
diff --git a/src/qml/jsruntime/qv4argumentsobject.cpp b/src/qml/jsruntime/qv4argumentsobject.cpp
index 0dfdf25158..74fcd30632 100644
--- a/src/qml/jsruntime/qv4argumentsobject.cpp
+++ b/src/qml/jsruntime/qv4argumentsobject.cpp
@@ -39,7 +39,8 @@
#include <qv4argumentsobject_p.h>
#include <qv4alloca_p.h>
#include <qv4scopedvalue_p.h>
-#include "qv4string_p.h"
+#include <qv4string_p.h>
+#include <qv4function_p.h>
using namespace QV4;
@@ -83,7 +84,7 @@ void ArgumentsObject::fullyCreate()
return;
uint argCount = context()->callData->argc;
- uint numAccessors = qMin(context()->function->formalParameterCount(), argCount);
+ uint numAccessors = qMin(context()->formalParameterCount(), argCount);
ArrayData::realloc(this, Heap::ArrayData::Sparse, argCount, true);
context()->engine->requireArgumentsAccessors(numAccessors);
@@ -110,7 +111,7 @@ bool ArgumentsObject::defineOwnProperty(ExecutionEngine *engine, uint index, con
ScopedProperty map(scope);
PropertyAttributes mapAttrs;
bool isMapped = false;
- uint numAccessors = qMin((int)context()->function->formalParameterCount(), context()->callData->argc);
+ uint numAccessors = qMin((int)context()->formalParameterCount(), context()->callData->argc);
if (pd && index < (uint)numAccessors)
isMapped = arrayData()->attributes(index).isAccessor() &&
pd->getter() == context()->engine->argumentsAccessors[index].getter();
@@ -193,7 +194,7 @@ PropertyAttributes ArgumentsObject::queryIndexed(const Managed *m, uint index)
if (args->fullyCreated())
return Object::queryIndexed(m, index);
- uint numAccessors = qMin((int)args->context()->function->formalParameterCount(), args->context()->callData->argc);
+ uint numAccessors = qMin((int)args->context()->formalParameterCount(), args->context()->callData->argc);
uint argCount = args->context()->callData->argc;
if (index >= argCount)
return PropertyAttributes();
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index 361d321a1a..5d4a1b07b5 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -66,6 +66,7 @@ Heap::CallContext *ExecutionContext::newCallContext(const FunctionObject *functi
c->init(d()->engine, Heap::ExecutionContext::Type_CallContext);
c->function = function->d();
+ c->v4Function = function->d()->function;
c->strictMode = function->strictMode();
c->outer = function->scope();
@@ -171,22 +172,22 @@ void Heap::CatchContext::init(ExecutionContext *outerContext, String *exceptionV
Identifier * const *CallContext::formals() const
{
- return (d()->function && d()->function->function) ? d()->function->function->internalClass->nameMap.constData() : 0;
+ return d()->v4Function ? d()->v4Function->internalClass->nameMap.constData() : 0;
}
unsigned int CallContext::formalCount() const
{
- return d()->function ? d()->function->formalParameterCount() : 0;
+ return d()->v4Function ? d()->v4Function->nFormals : 0;
}
Identifier * const *CallContext::variables() const
{
- return (d()->function && d()->function->function) ? d()->function->function->internalClass->nameMap.constData() + d()->function->formalParameterCount() : 0;
+ return d()->v4Function ? d()->v4Function->internalClass->nameMap.constData() + d()->v4Function->nFormals : 0;
}
unsigned int CallContext::variableCount() const
{
- return d()->function ? d()->function->varCount() : 0;
+ return d()->v4Function ? d()->v4Function->compiledFunction->nLocals : 0;
}
@@ -220,9 +221,8 @@ bool ExecutionContext::deleteProperty(String *name)
case Heap::ExecutionContext::Type_CallContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
- ScopedFunctionObject f(scope, c->function);
- if (f->needsActivation() || hasWith) {
- uint index = f->function()->internalClass->find(name);
+ if (c->v4Function && (c->v4Function->needsActivation() || hasWith)) {
+ uint index = c->v4Function->internalClass->find(name);
if (index < UINT_MAX)
// ### throw in strict mode?
return false;
@@ -245,7 +245,8 @@ bool ExecutionContext::deleteProperty(String *name)
bool CallContext::needsOwnArguments() const
{
- return d()->function->needsActivation() || argc() < static_cast<int>(d()->function->formalParameterCount());
+ QV4::Function *f = d()->v4Function;
+ return (f && f->needsActivation()) || (argc() < (f ? static_cast<int>(f->nFormals) : 0));
}
void ExecutionContext::markObjects(Heap::Base *m, ExecutionEngine *engine)
@@ -277,10 +278,11 @@ void ExecutionContext::markObjects(Heap::Base *m, ExecutionEngine *engine)
break;
case Heap::ExecutionContext::Type_CallContext: {
QV4::Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx);
+ Q_ASSERT(c->v4Function && c->function);
ctx->callData->thisObject.mark(engine);
- for (int arg = 0; arg < qMax(ctx->callData->argc, (int)c->function->formalParameterCount()); ++arg)
+ for (int arg = 0; arg < qMax(ctx->callData->argc, (int)c->v4Function->nFormals); ++arg)
ctx->callData->args[arg].mark(engine);
- for (unsigned local = 0, lastLocal = c->function->varCount(); local < lastLocal; ++local)
+ for (unsigned local = 0, lastLocal = c->v4Function->compiledFunction->nLocals; local < lastLocal; ++local)
c->locals[local].mark(engine);
if (c->activation)
c->activation->mark(engine);
@@ -327,13 +329,13 @@ void ExecutionContext::setProperty(String *name, const Value &value)
case Heap::ExecutionContext::Type_CallContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
- if (c->function->function) {
- uint index = c->function->function->internalClass->find(name);
+ if (c->v4Function) {
+ uint index = c->v4Function->internalClass->find(name);
if (index < UINT_MAX) {
- if (index < c->function->formalParameterCount()) {
- c->callData->args[c->function->formalParameterCount() - index - 1] = value;
+ if (index < c->v4Function->nFormals) {
+ c->callData->args[c->v4Function->nFormals - index - 1] = value;
} else {
- index -= c->function->formalParameterCount();
+ index -= c->v4Function->nFormals;
c->locals[index] = value;
}
return;
@@ -408,13 +410,12 @@ ReturnedValue ExecutionContext::getProperty(String *name)
case Heap::ExecutionContext::Type_CallContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
- ScopedFunctionObject f(scope, c->function);
- if (f->function() && (f->needsActivation() || hasWith || hasCatchScope)) {
- uint index = f->function()->internalClass->find(name);
+ if (c->v4Function && (c->v4Function->needsActivation() || hasWith || hasCatchScope)) {
+ uint index = c->v4Function->internalClass->find(name);
if (index < UINT_MAX) {
- if (index < c->function->formalParameterCount())
- return c->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue();
- return c->locals[index - c->function->formalParameterCount()].asReturnedValue();
+ if (index < c->v4Function->nFormals)
+ return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
+ return c->locals[index - c->v4Function->nFormals].asReturnedValue();
}
}
ScopedObject activation(scope, c->activation);
@@ -424,9 +425,9 @@ ReturnedValue ExecutionContext::getProperty(String *name)
if (hasProperty)
return v->asReturnedValue();
}
- if (f->function() && f->function()->isNamedExpression()
- && name->equals(ScopedString(scope, f->function()->name())))
- return f.asReturnedValue();
+ if (c->v4Function && c->v4Function->isNamedExpression()
+ && name->equals(ScopedString(scope, c->v4Function->name())))
+ return c->function->asReturnedValue();
break;
}
case Heap::ExecutionContext::Type_QmlContext: {
@@ -487,13 +488,12 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
case Heap::ExecutionContext::Type_CallContext:
case Heap::ExecutionContext::Type_SimpleCallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
- ScopedFunctionObject f(scope, c->function);
- if (f->function() && (f->needsActivation() || hasWith || hasCatchScope)) {
- uint index = f->function()->internalClass->find(name);
+ if (c->v4Function && (c->v4Function->needsActivation() || hasWith || hasCatchScope)) {
+ uint index = c->v4Function->internalClass->find(name);
if (index < UINT_MAX) {
- if (index < c->function->formalParameterCount())
- return c->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue();
- return c->locals[index - c->function->formalParameterCount()].asReturnedValue();
+ if (index < c->v4Function->nFormals)
+ return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
+ return c->locals[index - c->v4Function->nFormals].asReturnedValue();
}
}
ScopedObject activation(scope, c->activation);
@@ -503,9 +503,9 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
if (hasProperty)
return v->asReturnedValue();
}
- if (f->function() && f->function()->isNamedExpression()
- && name->equals(ScopedString(scope, f->function()->name())))
- return f.asReturnedValue();
+ if (c->v4Function && c->v4Function->isNamedExpression()
+ && name->equals(ScopedString(scope, c->v4Function->name())))
+ return c->function->asReturnedValue();
break;
}
case Heap::ExecutionContext::Type_QmlContext: {
diff --git a/src/qml/jsruntime/qv4context_p.h b/src/qml/jsruntime/qv4context_p.h
index 487917df7d..e5fd67d410 100644
--- a/src/qml/jsruntime/qv4context_p.h
+++ b/src/qml/jsruntime/qv4context_p.h
@@ -65,6 +65,7 @@ struct CompilationUnit;
struct Function;
}
+struct Function;
struct Identifier;
struct CallContext;
struct CatchContext;
@@ -140,11 +141,15 @@ struct CallContext : ExecutionContext {
{
ExecutionContext::init(engine, t);
function = 0;
+ v4Function = 0;
locals = 0;
activation = 0;
}
+ inline unsigned int formalParameterCount() const;
+
Pointer<FunctionObject> function;
+ QV4::Function *v4Function;
Value *locals;
Pointer<Object> activation;
};
diff --git a/src/qml/jsruntime/qv4function_p.h b/src/qml/jsruntime/qv4function_p.h
index 12094a0943..beba5a1fd6 100644
--- a/src/qml/jsruntime/qv4function_p.h
+++ b/src/qml/jsruntime/qv4function_p.h
@@ -53,6 +53,7 @@
#include "qv4global_p.h"
#include <private/qqmlglobal_p.h>
#include <private/qv4compileddata_p.h>
+#include <private/qv4context_p.h>
QT_BEGIN_NAMESPACE
@@ -97,6 +98,13 @@ struct Q_QML_EXPORT Function {
};
+
+inline unsigned int Heap::CallContext::formalParameterCount() const
+{
+ return v4Function ? v4Function->nFormals : 0;
+}
+
+
}
QT_END_NAMESPACE
diff --git a/src/qml/jsruntime/qv4functionobject.cpp b/src/qml/jsruntime/qv4functionobject.cpp
index 8e84eaebe7..02ea763b30 100644
--- a/src/qml/jsruntime/qv4functionobject.cpp
+++ b/src/qml/jsruntime/qv4functionobject.cpp
@@ -539,6 +539,7 @@ void SimpleScriptFunction::construct(const Managed *that, Scope &scope, CallData
CallContext::Data ctx = CallContext::Data::createOnStack(v4);
ctx.function = f->d();
QV4::Function *ff = ctx.function->function;
+ ctx.v4Function = ff;
ctx.strictMode = ff->isStrict();
ctx.callData = callData;
ctx.compilationUnit = ff->compilationUnit;
@@ -580,6 +581,7 @@ void SimpleScriptFunction::call(const Managed *that, Scope &scope, CallData *cal
CallContext::Data ctx = CallContext::Data::createOnStack(v4);
ctx.function = f->d();
QV4::Function *ff = ctx.function->function;
+ ctx.v4Function = ff;
ctx.strictMode = ff->isStrict();
ctx.callData = callData;
ctx.compilationUnit = ff->compilationUnit;