aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4context.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@qt.io>2018-03-26 22:59:28 +0200
committerLars Knoll <lars.knoll@qt.io>2018-05-02 14:17:46 +0000
commit20d30b6b3a253eebedc927dbb91685bbec52cfee (patch)
tree0e91a6c519829bd279258f3fe807519e6c8a1e3d /src/qml/jsruntime/qv4context.cpp
parentd499a995292629d3522f5e77b7c958bacdf5d0ae (diff)
Add support for proper lexical scoping
This is still to some extend work in progress as lexically scoped for loops won't yet do the right thing. let and const variables are still accessible before they are declared, and the global scope doesn't yet have a proper context for lexically declared variables. Change-Id: Ie39f74a8fccdaead437fbf07f9fc228a444c26ed Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jsruntime/qv4context.cpp')
-rw-r--r--src/qml/jsruntime/qv4context.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4context.cpp b/src/qml/jsruntime/qv4context.cpp
index 020e519e74..39fdcf0227 100644
--- a/src/qml/jsruntime/qv4context.cpp
+++ b/src/qml/jsruntime/qv4context.cpp
@@ -55,6 +55,29 @@ DEFINE_MANAGED_VTABLE(ExecutionContext);
DEFINE_MANAGED_VTABLE(CallContext);
DEFINE_MANAGED_VTABLE(CatchContext);
+Heap::CallContext *ExecutionContext::newBlockContext(CppStackFrame *frame, int blockIndex)
+{
+ Function *function = frame->v4Function;
+ Heap::ExecutionContext *outer = static_cast<Heap::ExecutionContext *>(frame->context()->m());
+
+ Heap::InternalClass *ic = function->compilationUnit->runtimeBlocks.at(blockIndex);
+ int nLocals = ic->size;
+ size_t requiredMemory = sizeof(CallContext::Data) - sizeof(Value) + sizeof(Value) * nLocals;
+
+ ExecutionEngine *v4 = outer->internalClass->engine;
+ Heap::CallContext *c = v4->memoryManager->allocManaged<CallContext>(requiredMemory, ic);
+ c->init();
+ c->type = Heap::ExecutionContext::Type_BlockContext;
+
+ c->outer.set(v4, outer);
+ c->function.set(v4, static_cast<Heap::FunctionObject *>(frame->jsFrame->function.m()));
+
+ c->locals.size = nLocals;
+ c->locals.alloc = nLocals;
+
+ return c;
+}
+
Heap::CallContext *ExecutionContext::newCallContext(CppStackFrame *frame)
{
Function *function = frame->v4Function;
@@ -112,6 +135,7 @@ void ExecutionContext::createMutableBinding(String *name, bool deletable)
ScopedContext ctx(scope, this);
while (ctx) {
switch (ctx->d()->type) {
+ case Heap::ExecutionContext::Type_BlockContext:
case Heap::ExecutionContext::Type_CallContext:
if (!activation) {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx->d());
@@ -170,6 +194,7 @@ bool ExecutionContext::deleteProperty(String *name)
return false;
break;
}
+ case Heap::ExecutionContext::Type_BlockContext:
case Heap::ExecutionContext::Type_CallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx);
uint index = c->internalClass->find(id);
@@ -225,6 +250,7 @@ ExecutionContext::Error ExecutionContext::setProperty(String *name, const Value
}
break;
}
+ case Heap::ExecutionContext::Type_BlockContext:
case Heap::ExecutionContext::Type_CallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx);
uint index = c->internalClass->find(id);
@@ -273,6 +299,7 @@ ReturnedValue ExecutionContext::getProperty(String *name)
return c->exceptionValue.asReturnedValue();
break;
}
+ case Heap::ExecutionContext::Type_BlockContext:
case Heap::ExecutionContext::Type_CallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx);
Identifier *id = name->identifier();
@@ -314,6 +341,7 @@ ReturnedValue ExecutionContext::getPropertyAndBase(String *name, Value *base)
return c->exceptionValue.asReturnedValue();
break;
}
+ case Heap::ExecutionContext::Type_BlockContext:
case Heap::ExecutionContext::Type_CallContext: {
Heap::CallContext *c = static_cast<Heap::CallContext *>(ctx);
name->makeIdentifier();