Fix scoping for catch blocks
authorSimon Hausmann <simon.hausmann@digia.com>
Fri, 8 Feb 2013 12:33:50 +0000 (13:33 +0100)
committerLars Knoll <lars.knoll@digia.com>
Wed, 13 Feb 2013 09:00:20 +0000 (10:00 +0100)
commit8e55a1a9263c651d5db10184f7f44539832feb9b
treecf1cd4a8e25059c881d1982974db153c97060a1e
parent817a3edf1a8f61b2c3bd8c4c086b36e2da5091e3
Fix scoping for catch blocks

Based on Lars' idea, done together with Erik.

For proper scoping of the exception variable in catch blocks, it is necessary
to define the new scope (ExecutionContext for us) at run-time, it cannot be
determined at compile time.

This patch implements the necessary logic to create the new execution context
when entering a try block and re-uses the existing pop_scope infrastructure for
destroying it again. Within the catch scope it is necessary to do all lookups by
name, so the existing _function->insideWith variable was re-used and renamed
to _function->insideWithOrCatch. Additionally the new context also stores the
name and value of the separately scoped exception variable that shadows any
existing equally named variables in outter scopes.

CodeGen::unwindException also had a bug that it would generate the finally code
with the wrong _function->insideWithOrCatch level, resulting in name lookups
inside finally instead of local index lookups.

Change-Id: I5616af38c3558e553e971a6a894ce5239ccb8422
Reviewed-by: Lars Knoll <lars.knoll@digia.com>
16 files changed:
src/v4/moth/qv4instr_moth_p.h
src/v4/moth/qv4isel_moth.cpp
src/v4/moth/qv4isel_moth_p.h
src/v4/moth/qv4vme_moth.cpp
src/v4/qmljs_environment.cpp
src/v4/qmljs_environment.h
src/v4/qmljs_runtime.cpp
src/v4/qmljs_runtime.h
src/v4/qv4codegen.cpp
src/v4/qv4ir.cpp
src/v4/qv4ir_p.h
src/v4/qv4isel_masm.cpp
src/v4/qv4isel_masm_p.h
src/v4/qv4isel_p.cpp
src/v4/qv4isel_p.h
tests/TestExpectations