thisObject = thisObject.toObject(this);
}
+ locals = function->varCount ? reinterpret_cast<Value *>(this + 1) : 0;
+ if (locals)
+ std::fill(locals, locals + function->varCount, Value::undefinedValue());
+
arguments = args;
argumentCount = argc;
if (function->needsActivation || argc < function->formalParameterCount){
argumentCount = qMax(argc, function->formalParameterCount);
- arguments = new Value[argumentCount];
+ arguments = reinterpret_cast<Value *>(this + 1) + function->varCount;
if (argc)
std::copy(args, args + argc, arguments);
if (argc < function->formalParameterCount)
std::fill(arguments + argc, arguments + function->formalParameterCount, Value::undefinedValue());
}
- locals = function->varCount ? new Value[function->varCount] : 0;
- if (locals)
- std::fill(locals, locals + function->varCount, Value::undefinedValue());
activation = 0;
withObject = 0;
void ExecutionContext::leaveCallContext()
{
- if (!function->needsActivation) {
- delete[] locals;
+ if (!function->needsActivation)
locals = 0;
- }
engine->current = parent;
parent = 0;
}
void mark();
+
};
+/* Function *f, int argc */
+#define requiredMemoryForExecutionContect(f, argc) \
+ sizeof(ExecutionContext) + sizeof(Value) * (f->varCount + qMax((uint)argc, f->formalParameterCount))
} // namespace VM
if (proto.isObject())
obj->prototype = proto.objectValue();
- ExecutionContext k;
- ExecutionContext *ctx = needsActivation ? context->engine->newContext() : &k;
+ uint size = requiredMemoryForExecutionContect(this, argc);
+ ExecutionContext *ctx = static_cast<ExecutionContext *>(needsActivation ? malloc(size) : alloca(size));
ctx->initCallContext(context, Value::fromObject(obj), this, args, argc);
Value result = construct(ctx);
Value FunctionObject::call(ExecutionContext *context, Value thisObject, Value *args, int argc)
{
- ExecutionContext k;
- ExecutionContext *ctx = needsActivation ? context->engine->newContext() : &k;
+ uint size = requiredMemoryForExecutionContect(this, argc);
+ ExecutionContext *ctx = static_cast<ExecutionContext *>(needsActivation ? malloc(size) : alloca(size));
+
ctx->initCallContext(context, thisObject, this, args, argc);
if (isBuiltinFunction) {
#include <QtCore/QDebug>
#include <QtCore/QString>
#include <iostream>
+#include <alloca.h>
using namespace QQmlJS::VM;
bool strict = f->isStrict || (directCall && context->strictMode);
- ExecutionContext k;
+ uint size = requiredMemoryForExecutionContect(this, argc);
+ ExecutionContext *k = static_cast<ExecutionContext *>(alloca(size));
if (strict) {
- ctx = &k;
+ ctx = k;
ctx->initCallContext(context, context->thisObject, this, args, argc);
}
return n > 1 ? n * fact(n - 1) : 1
}
-for (var i = 0; i < 1000000; i = i + 1)
+for (var i = 0; i < 10000; i = i + 1)
fact(12)