From: Lars Knoll Date: Wed, 23 Jan 2013 19:24:12 +0000 (+0100) Subject: Fix a crash when a non direct call to eval caused a syntax error X-Git-Tag: upstream/5.2.1~669^2~659^2~405 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d9a15cb8ec77eb370e806f391214f2e3ded272b5;p=platform%2Fupstream%2Fqtdeclarative.git Fix a crash when a non direct call to eval caused a syntax error Change-Id: I89d1eabd248fd844f7cd2caa29667e0c7850958d Reviewed-by: Simon Hausmann --- diff --git a/main.cpp b/main.cpp index af14fb7..741171e 100644 --- a/main.cpp +++ b/main.cpp @@ -395,7 +395,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - QQmlJS::VM::Function *f = QQmlJS::VM::EvalFunction::parseSource(ctx, fn, code, QQmlJS::Codegen::GlobalCode, /*inheritContext =*/ false); + QQmlJS::VM::Function *f = QQmlJS::VM::EvalFunction::parseSource(ctx, fn, code, QQmlJS::Codegen::GlobalCode, + /*strictMode =*/ false, /*inheritContext =*/ false); if (!f) continue; diff --git a/qv4codegen.cpp b/qv4codegen.cpp index bc45257..4e5def9 100644 --- a/qv4codegen.cpp +++ b/qv4codegen.cpp @@ -402,7 +402,7 @@ private: QStack _envStack; }; -Codegen::Codegen(VM::ExecutionContext *context) +Codegen::Codegen(VM::ExecutionContext *context, bool strict) : _module(0) , _function(0) , _block(0) @@ -415,7 +415,7 @@ Codegen::Codegen(VM::ExecutionContext *context) , _labelledStatement(0) , _tryCleanup(0) , _context(context) - , _strictMode(context->strictMode) + , _strictMode(strict) , _debugger(context->engine->debugger) , _errorHandler(0) { diff --git a/qv4codegen_p.h b/qv4codegen_p.h index 8a83908..9806198 100644 --- a/qv4codegen_p.h +++ b/qv4codegen_p.h @@ -70,7 +70,7 @@ public: class Codegen: protected AST::Visitor { public: - Codegen(VM::ExecutionContext *ctx); + Codegen(VM::ExecutionContext *ctx, bool strict); Codegen(ErrorHandler *errorHandler, bool strictMode); enum Mode { diff --git a/qv4functionobject.cpp b/qv4functionobject.cpp index e5501d8..7985491 100644 --- a/qv4functionobject.cpp +++ b/qv4functionobject.cpp @@ -182,7 +182,7 @@ Value FunctionCtor::construct(ExecutionContext *ctx) IR::Module module; - Codegen cg(ctx); + Codegen cg(ctx, ctx->strictMode); IR::Function *irf = cg(QString(), fe, &module); QScopedPointer isel(ctx->engine->iselFactory->create(ctx->engine, &module)); diff --git a/qv4globalobject.cpp b/qv4globalobject.cpp index df666df..f75d313 100644 --- a/qv4globalobject.cpp +++ b/qv4globalobject.cpp @@ -332,13 +332,9 @@ Value EvalFunction::evalCall(ExecutionContext *context, Value /*thisObject*/, Va const QString code = args[0].stringValue()->toQString(); bool inheritContext = !ctx->strictMode; - bool cstrict = ctx->strictMode; - if (!directCall) - ctx->strictMode = false; - QQmlJS::VM::Function *f = parseSource(ctx, QStringLiteral("eval code"), + QQmlJS::VM::Function *f = parseSource(context, QStringLiteral("eval code"), code, QQmlJS::Codegen::EvalCode, - inheritContext); - ctx->strictMode = cstrict; + (directCall && context->strictMode), inheritContext); if (!f) return Value::undefinedValue(); @@ -353,7 +349,7 @@ Value EvalFunction::evalCall(ExecutionContext *context, Value /*thisObject*/, Va } // set the correct strict mode flag on the context - cstrict = ctx->strictMode; + bool cstrict = ctx->strictMode; ctx->strictMode = strict; Value result = f->code(ctx, f->codeData); @@ -376,7 +372,7 @@ Value EvalFunction::call(ExecutionContext *context, Value thisObject, Value *arg QQmlJS::VM::Function *EvalFunction::parseSource(QQmlJS::VM::ExecutionContext *ctx, const QString &fileName, const QString &source, QQmlJS::Codegen::Mode mode, - bool inheritContext) + bool strictMode, bool inheritContext) { using namespace QQmlJS; @@ -428,7 +424,7 @@ QQmlJS::VM::Function *EvalFunction::parseSource(QQmlJS::VM::ExecutionContext *ct for (String **i = ctx->variables(), **ei = i + ctx->variableCount(); i < ei; ++i) inheritedLocals.append(*i ? (*i)->toQString() : QString()); - Codegen cg(ctx); + Codegen cg(ctx, strictMode); IR::Function *globalIRCode = cg(fileName, program, &module, mode, inheritedLocals); QScopedPointer isel(ctx->engine->iselFactory->create(vm, &module)); if (globalIRCode) diff --git a/qv4globalobject.h b/qv4globalobject.h index 2072227..2292e38 100644 --- a/qv4globalobject.h +++ b/qv4globalobject.h @@ -54,7 +54,7 @@ struct EvalFunction : FunctionObject static QQmlJS::VM::Function *parseSource(QQmlJS::VM::ExecutionContext *ctx, const QString &fileName, const QString &source, - QQmlJS::Codegen::Mode mode, + QQmlJS::Codegen::Mode mode, bool strictMode, bool inheritContext); virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc); diff --git a/tests/TestExpectations b/tests/TestExpectations index 6c39053..0aa424d 100644 --- a/tests/TestExpectations +++ b/tests/TestExpectations @@ -166,7 +166,6 @@ S12.10_A1.4_T4 failing S12.10_A1.4_T5 failing S12.10_A1.5_T4 failing S12.10_A1.5_T5 failing -12.2.1-22-s failing S13_A15_T4 failing S13_A3_T1 failing 13.1-11-s failing