Fix a crash when a non direct call to eval caused a syntax error
authorLars Knoll <lars.knoll@digia.com>
Wed, 23 Jan 2013 19:24:12 +0000 (20:24 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Wed, 23 Jan 2013 20:31:30 +0000 (21:31 +0100)
Change-Id: I89d1eabd248fd844f7cd2caa29667e0c7850958d
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
main.cpp
qv4codegen.cpp
qv4codegen_p.h
qv4functionobject.cpp
qv4globalobject.cpp
qv4globalobject.h
tests/TestExpectations

index af14fb7..741171e 100644 (file)
--- 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;
 
index bc45257..4e5def9 100644 (file)
@@ -402,7 +402,7 @@ private:
     QStack<Environment *> _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)
 {
index 8a83908..9806198 100644 (file)
@@ -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 {
index e5501d8..7985491 100644 (file)
@@ -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<EvalInstructionSelection> isel(ctx->engine->iselFactory->create(ctx->engine, &module));
index df666df..f75d313 100644 (file)
@@ -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<EvalInstructionSelection> isel(ctx->engine->iselFactory->create(vm, &module));
             if (globalIRCode)
index 2072227..2292e38 100644 (file)
@@ -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);
index 6c39053..0aa424d 100644 (file)
@@ -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