diff options
author | Lars Knoll <lars.knoll@qt.io> | 2018-05-04 15:16:08 +0200 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2018-05-11 07:17:05 +0000 |
commit | 4cf7e80c5740912804383e4d866ba12b2520d0e6 (patch) | |
tree | 143d960492aa166a7f3d7111b64151c42234a81f /src/qml/jit | |
parent | 2fc50421c86134b5b42a4ba68aa7f6b87cfd7d74 (diff) |
Ensure we have a lexical scope for global code
This requires a bit more work than simply pushing a
new BlockContext for the lexically declared variables,
as eval() and the Function constructor operate on the
global scope (including the lexically declared names).
To fix this introduce Push/PopScriptContext instructions,
that create a BlockContext for the lexically declared
vars and pushes that one as a global script context that
eval and friends use.
Change-Id: I0fd0b0f682f82e250545e874fe93978449fe5e46
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'src/qml/jit')
-rw-r--r-- | src/qml/jit/qv4jit.cpp | 34 | ||||
-rw-r--r-- | src/qml/jit/qv4jit_p.h | 2 |
2 files changed, 36 insertions, 0 deletions
diff --git a/src/qml/jit/qv4jit.cpp b/src/qml/jit/qv4jit.cpp index 16b6b5fb94..f659ddfb00 100644 --- a/src/qml/jit/qv4jit.cpp +++ b/src/qml/jit/qv4jit.cpp @@ -659,6 +659,34 @@ void BaselineJIT::generate_PushBlockContext(int reg, int index) JIT_GENERATE_RUNTIME_CALL(pushBlockContextHelper, Assembler::IgnoreResult); } +static void pushScriptContextHelper(QV4::Value *stack, ExecutionEngine *engine, int index) +{ + stack[CallData::Context] = Runtime::method_createScriptContext(engine, index); +} + +void BaselineJIT::generate_PushScriptContext(int index) +{ + as->saveAccumulatorInFrame(); + as->prepareCallWithArgCount(3); + as->passInt32AsArg(index, 2); + as->passEngineAsArg(1); + as->passRegAsArg(0, 0); + JIT_GENERATE_RUNTIME_CALL(pushScriptContextHelper, Assembler::IgnoreResult); +} + +static void popScriptContextHelper(QV4::Value *stack, ExecutionEngine *engine) +{ + stack[CallData::Context] = Runtime::method_popScriptContext(engine); +} + +void BaselineJIT::generate_PopScriptContext() +{ + as->saveAccumulatorInFrame(); + as->prepareCallWithArgCount(2); + as->passEngineAsArg(1); + as->passRegAsArg(0, 0); + JIT_GENERATE_RUNTIME_CALL(popScriptContextHelper, Assembler::IgnoreResult); +} void BaselineJIT::generate_PopContext(int reg) { as->popContext(reg); } @@ -1208,6 +1236,12 @@ void BaselineJIT::collectLabelsInBytecode() MOTH_BEGIN_INSTR(PushBlockContext) MOTH_END_INSTR(PushBlockContext) + MOTH_BEGIN_INSTR(PushScriptContext) + MOTH_END_INSTR(PushScriptContext) + + MOTH_BEGIN_INSTR(PopScriptContext) + MOTH_END_INSTR(PopScriptContext) + MOTH_BEGIN_INSTR(PopContext) MOTH_END_INSTR(PopContext) diff --git a/src/qml/jit/qv4jit_p.h b/src/qml/jit/qv4jit_p.h index 157fbffeb1..97dd2ef2a5 100644 --- a/src/qml/jit/qv4jit_p.h +++ b/src/qml/jit/qv4jit_p.h @@ -181,6 +181,8 @@ public: void generate_PushCatchContext(int reg, int index, int name) override; void generate_PushWithContext(int reg) override; void generate_PushBlockContext(int reg, int index) override; + void generate_PushScriptContext(int index) override; + void generate_PopScriptContext() override; void generate_PopContext(int reg) override; void generate_GetIterator(int iterator) override; void generate_DeleteMember(int member, int base) override; |