if (fullyCreated)
return;
- uint numAccessors = qMin((int)context->function->formalParameterCount, context->realArgumentCount);
+ uint numAccessors = qMin((int)context->function->formalParameterCount(), context->realArgumentCount);
uint argCount = qMin(context->realArgumentCount, context->callData->argc);
ArrayData::realloc(this, ArrayData::Sparse, 0, argCount, true);
context->engine->requireArgumentsAccessors(numAccessors);
if (args->fullyCreated)
return Object::queryIndexed(m, index);
- uint numAccessors = qMin((int)args->context->function->formalParameterCount, args->context->realArgumentCount);
+ uint numAccessors = qMin((int)args->context->function->formalParameterCount(), args->context->realArgumentCount);
uint argCount = qMin(args->context->realArgumentCount, args->context->callData->argc);
if (index >= argCount)
return PropertyAttributes();
CallContext *ExecutionContext::newCallContext(FunctionObject *function, CallData *callData)
{
+ Q_ASSERT(function->function);
+
CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocManaged(requiredMemoryForExecutionContect(function, callData->argc)));
new (c) CallContext(engine, Type_CallContext);
c->activation = 0;
- if (function->function) {
- c->compilationUnit = function->function->compilationUnit;
- c->lookups = c->compilationUnit->runtimeLookups;
- }
-
+ c->compilationUnit = function->function->compilationUnit;
+ c->lookups = c->compilationUnit->runtimeLookups;
c->locals = (Value *)((quintptr(c + 1) + 7) & ~7);
- if (function->varCount)
- std::fill(c->locals, c->locals + function->varCount, Primitive::undefinedValue());
+ const CompiledData::Function *compiledFunction = function->function->compiledFunction;
+ int nLocals = compiledFunction->nLocals;
+ if (nLocals)
+ std::fill(c->locals, c->locals + nLocals, Primitive::undefinedValue());
- c->callData = reinterpret_cast<CallData *>(c->locals + function->varCount);
+ c->callData = reinterpret_cast<CallData *>(c->locals + nLocals);
::memcpy(c->callData, callData, sizeof(CallData) + (callData->argc - 1) * sizeof(Value));
- if (callData->argc < static_cast<int>(function->formalParameterCount))
- std::fill(c->callData->args + c->callData->argc, c->callData->args + function->formalParameterCount, Primitive::undefinedValue());
- c->callData->argc = qMax((uint)callData->argc, function->formalParameterCount);
+ if (callData->argc < static_cast<int>(compiledFunction->nFormals))
+ std::fill(c->callData->args + c->callData->argc, c->callData->args + compiledFunction->nFormals, Primitive::undefinedValue());
+ c->callData->argc = qMax((uint)callData->argc, compiledFunction->nFormals);
return c;
}
if (type < Type_SimpleCallContext)
return 0;
QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function;
- return f ? f->formalParameterCount : 0;
+ return f ? f->formalParameterCount() : 0;
}
String * const *ExecutionContext::variables() const
if (type < Type_SimpleCallContext)
return 0;
QV4::FunctionObject *f = static_cast<const CallContext *>(this)->function;
- return f ? f->varCount : 0;
+ return f ? f->varCount() : 0;
}
}
locals = (Value *)(this + 1);
- if (function->varCount)
- std::fill(locals, locals + function->varCount, Primitive::undefinedValue());
+ if (function->varCount())
+ std::fill(locals, locals + function->varCount(), Primitive::undefinedValue());
}
bool CallContext::needsOwnArguments() const
{
- return function->needsActivation || callData->argc < static_cast<int>(function->formalParameterCount);
+ return function->needsActivation || callData->argc < static_cast<int>(function->formalParameterCount());
}
void ExecutionContext::markObjects(Managed *m, ExecutionEngine *engine)
if (c->function->function) {
uint index = c->function->function->internalClass->find(name);
if (index < UINT_MAX) {
- if (index < c->function->formalParameterCount) {
- c->callData->args[c->function->formalParameterCount - index - 1] = *value;
+ if (index < c->function->formalParameterCount()) {
+ c->callData->args[c->function->formalParameterCount() - index - 1] = *value;
} else {
- index -= c->function->formalParameterCount;
+ index -= c->function->formalParameterCount();
c->locals[index] = *value;
}
return;
if (f->function && (f->needsActivation || hasWith || hasCatchScope)) {
uint index = f->function->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->function->formalParameterCount())
+ return c->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue();
+ return c->locals[index - c->function->formalParameterCount()].asReturnedValue();
}
}
if (c->activation) {
if (f->function && (f->needsActivation || hasWith || hasCatchScope)) {
uint index = f->function->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->function->formalParameterCount())
+ return c->callData->args[c->function->formalParameterCount() - index - 1].asReturnedValue();
+ return c->locals[index - c->function->formalParameterCount()].asReturnedValue();
}
}
if (c->activation) {
/* Function *f, int argc */
#define requiredMemoryForExecutionContect(f, argc) \
- ((sizeof(CallContext) + 7) & ~7) + sizeof(Value) * (f->varCount + qMax((uint)argc, f->formalParameterCount)) + sizeof(CallData)
+ ((sizeof(CallContext) + 7) & ~7) + sizeof(Value) * (f->varCount() + qMax((uint)argc, f->formalParameterCount())) + sizeof(CallData)
} // namespace QV4
FunctionObject::FunctionObject(ExecutionContext *scope, const StringRef name, bool createProto)
: Object(createProto ? scope->engine->functionWithProtoClass : scope->engine->functionClass)
, scope(scope)
- , formalParameterCount(0)
- , varCount(0)
, function(0)
, protoCacheClass(0)
, protoCacheIndex(UINT_MAX)
FunctionObject::FunctionObject(ExecutionContext *scope, const QString &name, bool createProto)
: Object(createProto ? scope->engine->functionWithProtoClass : scope->engine->functionClass)
, scope(scope)
- , formalParameterCount(0)
- , varCount(0)
, function(0)
, protoCacheClass(0)
, protoCacheIndex(UINT_MAX)
FunctionObject::FunctionObject(InternalClass *ic)
: Object(ic)
, scope(ic->engine->rootContext)
- , formalParameterCount(0)
- , varCount(0)
, function(0)
{
name = ic->engine->id_undefined;
FunctionObject *o = static_cast<FunctionObject *>(that);
if (o->name.managed())
o->name->mark(e);
- // these are marked in VM::Function:
-// for (uint i = 0; i < formalParameterCount; ++i)
-// formalParameterList[i]->mark();
-// for (uint i = 0; i < varCount; ++i)
-// varList[i]->mark();
o->scope->mark(e);
Object::markObjects(that, e);
needsActivation = function->needsActivation();
strictMode = function->isStrict();
- formalParameterCount = function->compiledFunction->nFormals;
- varCount = function->internalClass->size - function->compiledFunction->nFormals;
- defineReadonlyProperty(scope->engine->id_length, Primitive::fromInt32(formalParameterCount));
+ defineReadonlyProperty(scope->engine->id_length, Primitive::fromInt32(formalParameterCount()));
if (scope->strictMode) {
Property pd = Property::fromAccessor(v4->thrower, v4->thrower);
needsActivation = function->needsActivation();
strictMode = function->isStrict();
- formalParameterCount = function->compiledFunction->nFormals;
- varCount = function->internalClass->size - function->compiledFunction->nFormals;
- defineReadonlyProperty(scope->engine->id_length, Primitive::fromInt32(formalParameterCount));
+ defineReadonlyProperty(scope->engine->id_length, Primitive::fromInt32(formalParameterCount()));
if (scope->strictMode) {
Property pd = Property::fromAccessor(v4->thrower, v4->thrower);
ctx.compilationUnit = f->function->compilationUnit;
ctx.lookups = ctx.compilationUnit->runtimeLookups;
ctx.outer = f->scope;
- ctx.locals = v4->stackPush(f->varCount);
- while (callData->argc < (int)f->formalParameterCount) {
+ ctx.locals = v4->stackPush(f->varCount());
+ while (callData->argc < (int)f->formalParameterCount()) {
callData->args[callData->argc] = Encode::undefined();
++callData->argc;
}
ctx.compilationUnit = f->function->compilationUnit;
ctx.lookups = ctx.compilationUnit->runtimeLookups;
ctx.outer = f->scope;
- ctx.locals = v4->stackPush(f->varCount);
- while (callData->argc < (int)f->formalParameterCount) {
+ ctx.locals = v4->stackPush(f->varCount());
+ while (callData->argc < (int)f->formalParameterCount()) {
callData->args[callData->argc] = Encode::undefined();
++callData->argc;
}
#include "qv4string_p.h"
#include "qv4managed_p.h"
#include "qv4property_p.h"
+#include "qv4function_p.h"
#include "qv4objectiterator_p.h"
#include <QtCore/QString>
ExecutionContext *scope;
StringValue name;
- unsigned int formalParameterCount;
- unsigned int varCount;
+ unsigned int formalParameterCount() { return function ? function->compiledFunction->nFormals : 0; }
+ unsigned int varCount() { return function ? function->compiledFunction->nLocals : 0; }
Function *function;
InternalClass *protoCacheClass;
uint protoCacheIndex;
Q_ASSERT(This->function);
CallContext *ctx = This->qmlContext;
- std::fill(ctx->locals, ctx->locals + ctx->function->varCount, Primitive::undefinedValue());
+ std::fill(ctx->locals, ctx->locals + ctx->function->varCount(), Primitive::undefinedValue());
engine->pushContext(ctx);
ScopedValue result(scope, This->function->code(ctx, This->function->codeData));
engine->popContext();