From e6180ecdc2144786c58d2f9d615f698ca3442382 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 6 Sep 2013 13:48:33 +0200 Subject: Properly unwind the js stack for generated code Surround all calls into generated code with a try {} catch {} statement that resets the jstack to the correct position. Like this we properly unwind the js stack in all cases, and can also use stricter assertions in our ScopedCallData, etc. classes to check that the stack is healthy. Change-Id: I7ca03e06ea55007be683305d9c2a6898cf5fc689 Reviewed-by: Simon Hausmann --- src/qml/jsruntime/qv4function_p.h | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'src/qml/jsruntime/qv4function_p.h') diff --git a/src/qml/jsruntime/qv4function_p.h b/src/qml/jsruntime/qv4function_p.h index 595955a8ec..e9640fd925 100644 --- a/src/qml/jsruntime/qv4function_p.h +++ b/src/qml/jsruntime/qv4function_p.h @@ -50,6 +50,7 @@ #include #include "qv4value_def_p.h" #include +#include QT_BEGIN_NAMESPACE @@ -85,7 +86,17 @@ struct Function { const CompiledData::Function *compiledFunction; CompiledData::CompilationUnit *compilationUnit; - Value (*code)(ExecutionContext *, const uchar *); + inline Value code(ExecutionContext *ctx, const uchar *data) { + Value *stack = ctx->engine->jsStackTop; + try { + return codePtr(ctx, data); + } catch (...) { + ctx->engine->jsStackTop = stack; + throw; + } + } + + Value (*codePtr)(ExecutionContext *, const uchar *); const uchar *codeData; quint32 codeSize; -- cgit v1.2.3