aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4context.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2017-08-13 22:34:05 +0200
committerErik Verbruggen <erik.verbruggen@qt.io>2017-08-18 10:05:51 +0000
commitaf5adb9e32713edb7196f761bcabd19f35722c57 (patch)
treef5c1f9d4e70c6bc9f9c7bb77d2d7be60797b668a /src/qml/jsruntime/qv4context.cpp
parent456632225f3173d401c68e301fb6d38f6c42e493 (diff)
Cleanup argument handling in contexts
Fix the compiler to already deal with duplicated argument names. Doing this at runtime was not ideal. Remove the callData member from the context. Instead use the fact that the arguments already followed the locals in the context. Don't copy the thisObject over into the CallContext anymore, it's never used from there anyway. Fix the ordering of names in the internalclass, so that arguments don't require special handling anymore when looking them up by name. Adjust all places that used callData, and related methods. Change-Id: I0bc45e1be3f1fcd38dc3b4f04e91edaf7b9ed103 Reviewed-by: Erik Verbruggen <erik.verbruggen@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4context.cpp')
-rw-r--r--src/qml/jsruntime/qv4context.cpp57
1 files changed, 14 insertions, 43 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index fbcfcc3460..eaf54282e7 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -58,7 +58,7 @@ DEFINE_MANAGED_VTABLE(CatchContext);
Heap::CallContext *ExecutionContext::newCallContext(Heap::ExecutionContext *outer, Function *function, CallData *callData, const FunctionObject *f)
{
uint nFormals = qMax(static_cast<uint>(callData->argc), function->nFormals);
- uint localsAndFormals = function->compiledFunction->nLocals + sizeof(CallData)/sizeof(Value) - 1 + nFormals;
+ uint localsAndFormals = function->compiledFunction->nLocals + nFormals;
size_t requiredMemory = sizeof(CallContext::Data) - sizeof(Value) + sizeof(Value) * (localsAndFormals);
ExecutionEngine *v4 = outer->internalClass->engine;
@@ -83,8 +83,8 @@ Heap::CallContext *ExecutionContext::newCallContext(Heap::ExecutionContext *oute
std::fill(c->locals.values, c->locals.values + nLocals, Primitive::undefinedValue());
#endif
- c->callData = reinterpret_cast<CallData *>(c->locals.values + nLocals);
- ::memcpy(c->callData, callData, sizeof(CallData) - sizeof(Value) + nFormals * sizeof(Value));
+ ::memcpy(c->locals.values + nLocals, &callData->args[0], nFormals * sizeof(Value));
+ c->nArgs = callData->argc;
return c;
}
@@ -161,28 +161,6 @@ void Heap::CatchContext::init(ExecutionContext *outerContext, String *exceptionV
this->exceptionValue.set(internalClass->engine, exceptionValue);
}
-Identifier * const *CallContext::formals() const
-{
- return d()->v4Function ? d()->internalClass->nameMap.constData() : 0;
-}
-
-unsigned int CallContext::formalCount() const
-{
- return d()->v4Function ? d()->v4Function->nFormals : 0;
-}
-
-Identifier * const *CallContext::variables() const
-{
- return d()->v4Function ? d()->internalClass->nameMap.constData() + d()->v4Function->nFormals : 0;
-}
-
-unsigned int CallContext::variableCount() const
-{
- return d()->v4Function ? d()->v4Function->compiledFunction->nLocals : 0;
-}
-
-
-
bool ExecutionContext::deleteProperty(String *name)
{
name->makeIdentifier();
@@ -257,13 +235,7 @@ ExecutionContext::Error ExecutionContext::setProperty(String *name, const Value
if (c->v4Function) {
uint index = c->internalClass->find(id);
if (index < UINT_MAX) {
- if (index < c->v4Function->nFormals) {
- c->callData->args[c->v4Function->nFormals - index - 1] = value;
- } else {
- Q_ASSERT(c->type == Heap::ExecutionContext::Type_CallContext);
- index -= c->v4Function->nFormals;
- static_cast<Heap::CallContext *>(c)->locals.set(v4, index, value);
- }
+ static_cast<Heap::CallContext *>(c)->locals.set(v4, index, value);
return NoError;
}
}
@@ -314,12 +286,8 @@ ReturnedValue ExecutionContext::getProperty(String *name)
Identifier *id = name->identifier();
uint index = c->internalClass->find(id);
- if (index < UINT_MAX) {
- if (index < c->v4Function->nFormals)
- return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
- Q_ASSERT(c->type == Heap::ExecutionContext::Type_CallContext);
- return c->locals[index - c->v4Function->nFormals].asReturnedValue();
- }
+ if (index < UINT_MAX)
+ return c->locals[index].asReturnedValue();
if (c->v4Function->isNamedExpression()) {
Scope scope(this);
if (c->function && name->equals(ScopedString(scope, c->v4Function->name())))
@@ -365,11 +333,8 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
Identifier *id = name->identifier();
uint index = c->internalClass->find(id);
- if (index < UINT_MAX) {
- if (index < c->v4Function->nFormals)
- return c->callData->args[c->v4Function->nFormals - index - 1].asReturnedValue();
- return c->locals[index - c->v4Function->nFormals].asReturnedValue();
- }
+ if (index < UINT_MAX)
+ return c->locals[index].asReturnedValue();
if (c->v4Function->isNamedExpression()) {
Scope scope(this);
if (c->function && name->equals(ScopedString(scope, c->v4Function->name())))
@@ -421,3 +386,9 @@ Function *ExecutionContext::getFunction() const
return 0;
}
+
+
+void Heap::CallContext::setArg(uint index, Value v)
+{
+ locals.set(internalClass->engine, locals.size + index, v);
+}