aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/qml/qml/v4/qv4runtime_p.h2
-rw-r--r--src/qml/qml/v4/qv4script.cpp38
-rw-r--r--src/qml/qml/v4/qv4script_p.h2
-rw-r--r--tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp36
-rw-r--r--tools/v4/main.cpp9
5 files changed, 55 insertions, 32 deletions
diff --git a/src/qml/qml/v4/qv4runtime_p.h b/src/qml/qml/v4/qv4runtime_p.h
index 48908598ae..b4a8b9c310 100644
--- a/src/qml/qml/v4/qv4runtime_p.h
+++ b/src/qml/qml/v4/qv4runtime_p.h
@@ -195,7 +195,7 @@ QV4::Value __qmljs_to_object(QV4::ExecutionContext *ctx, const QV4::Value &value
QV4::Object *__qmljs_convert_to_object(QV4::ExecutionContext *ctx, const QV4::Value &value);
QV4::Bool __qmljs_equal(const QV4::Value &x, const QV4::Value &y);
-QV4::Bool __qmljs_strict_equal(const QV4::Value &x, const QV4::Value &y);
+Q_QML_EXPORT QV4::Bool __qmljs_strict_equal(const QV4::Value &x, const QV4::Value &y);
// unary operators
typedef void (*UnaryOpName)(QV4::Value *, const QV4::Value &);
diff --git a/src/qml/qml/v4/qv4script.cpp b/src/qml/qml/v4/qv4script.cpp
index d689bc231d..83a4c7cec9 100644
--- a/src/qml/qml/v4/qv4script.cpp
+++ b/src/qml/qml/v4/qv4script.cpp
@@ -155,17 +155,41 @@ Value Script::run()
if (engine->debugger)
engine->debugger->aboutToCall(0, scope);
- quintptr stackSpace[stackContextSize/sizeof(quintptr)];
- ExecutionContext *ctx = qml ? engine->newQmlContext(f, qml) : engine->newCallContext(stackSpace, f, Value::undefinedValue(), 0, 0);
+ if (!qml) {
+ QV4::Function *function = this->function();
+ TemporaryAssignment<Function*> savedGlobalCode(engine->globalCode, function);
+
+ bool strict = scope->strictMode;
+ Lookup *lookups = scope->lookups;
+
+ scope->strictMode = function->isStrict;
+ scope->lookups = function->lookups;
+
+ if (engine->debugger)
+ engine->debugger->aboutToCall(0, scope);
+
+ QV4::Value result;
+ try {
+ result = function->code(scope, function->codeData);
+ } catch (Exception &e) {
+ scope->strictMode = strict;
+ scope->lookups = lookups;
+ throw;
+ }
- Value result = f->function->code(ctx, f->function->codeData);
+ if (engine->debugger)
+ engine->debugger->justLeft(scope);
+ return result;
- engine->popContext();
+ } else {
+ ExecutionContext *ctx = engine->newQmlContext(f, qml);
- if (engine->debugger)
- engine->debugger->justLeft(scope);
+ Value result = f->function->code(ctx, f->function->codeData);
- return result;
+ engine->popContext();
+
+ return result;
+ }
}
Function *Script::function()
diff --git a/src/qml/qml/v4/qv4script_p.h b/src/qml/qml/v4/qv4script_p.h
index e624767dc7..17b98c213d 100644
--- a/src/qml/qml/v4/qv4script_p.h
+++ b/src/qml/qml/v4/qv4script_p.h
@@ -50,7 +50,7 @@ namespace QV4 {
struct ExecutionContext;
-struct Script {
+struct Q_QML_EXPORT Script {
Script(ExecutionContext *scope, const QString &sourceCode, const QString &source = QString(), int line = 0, int column = 0)
: sourceFile(source), line(line), column(column), sourceCode(sourceCode)
, scope(scope), strictMode(false), inheritContext(false), qml(0) {}
diff --git a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
index 9de75329dd..0aec42a811 100644
--- a/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
+++ b/tests/auto/qml/qqmlecmascript/tst_qqmlecmascript.cpp
@@ -53,6 +53,7 @@
#include "testtypes.h"
#include "testhttpserver.h"
#include "../../shared/util.h"
+#include <private/qv4functionobject_p.h>
/*
This test covers evaluation of ECMAScript expressions and bindings from within
@@ -2171,16 +2172,16 @@ static inline bool evaluate_error(QV8Engine *engine, v8::Handle<v8::Object> o, c
QString functionSource = QLatin1String("(function(object) { return ") +
QLatin1String(source) + QLatin1String(" })");
- v8::Handle<v8::Script> program = v8::Script::Compile(engine->toString(functionSource));
+ QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource);
QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current;
try {
- v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run());
- if (!function->v4Value().asFunctionObject())
+ QV4::FunctionObject *function = program.run().asFunctionObject();
+ if (!function)
return false;
- v8::Handle<v8::Value> args[] = { o };
- function->Call(engine->global(), 1, args);
+ QV4::Value args[] = { o->v4Value() };
+ function->call(engine->global(), args, 1);
} catch (QV4::Exception &e) {
e.accept(ctx);
return false;
@@ -2194,16 +2195,16 @@ static inline bool evaluate_value(QV8Engine *engine, v8::Handle<v8::Object> o,
QString functionSource = QLatin1String("(function(object) { return ") +
QLatin1String(source) + QLatin1String(" })");
+ QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource);
+
QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current;
- v8::Handle<v8::Script> program = v8::Script::Compile(engine->toString(functionSource));
try {
- v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run());
- if (!function->v4Value().asFunctionObject())
+ QV4::FunctionObject *function = program.run().asFunctionObject();
+ if (!function)
return false;
- v8::Handle<v8::Value> args[] = { o };
-
- v8::Handle<v8::Value> value = function->Call(engine->global(), 1, args);
- return value->StrictEquals(result);
+ QV4::Value args[] = { o->v4Value() };
+ QV4::Value value = function->call(engine->global(), args, 1);
+ return __qmljs_strict_equal(value, result->v4Value());
} catch (QV4::Exception &e) {
e.accept(ctx);
}
@@ -2217,14 +2218,13 @@ static inline v8::Handle<v8::Value> evaluate(QV8Engine *engine, v8::Handle<v8::O
QLatin1String(source) + QLatin1String(" })");
QV4::ExecutionContext *ctx = QV8Engine::getV4(engine)->current;
- v8::Handle<v8::Script> program = v8::Script::Compile(engine->toString(functionSource));
+ QV4::Script program(QV8Engine::getV4(engine)->rootContext, functionSource);
try {
- v8::Handle<v8::Function> function = v8::Handle<v8::Function>::Cast(program->Run());
- if (!function->v4Value().asFunctionObject())
+ QV4::FunctionObject *function = program.run().asFunctionObject();
+ if (!function)
return v8::Handle<v8::Value>();
- v8::Handle<v8::Value> args[] = { o };
-
- v8::Handle<v8::Value> value = function->Call(engine->global(), 1, args);
+ QV4::Value args[] = { o->v4Value() };
+ QV4::Value value = function->call(engine->global(), args, 1);
return value;
} catch (QV4::Exception &e) {
e.accept(ctx);
diff --git a/tools/v4/main.cpp b/tools/v4/main.cpp
index 5529930a99..56ec2da7af 100644
--- a/tools/v4/main.cpp
+++ b/tools/v4/main.cpp
@@ -57,6 +57,7 @@
#include "private/qv4isel_p.h"
#include "private/qv4mm_p.h"
#include "private/qv4context_p.h"
+#include "private/qv4script_p.h"
#ifdef V4_ENABLE_JIT
# include "private/qv4isel_masm_p.h"
@@ -380,11 +381,9 @@ int main(int argc, char *argv[])
file.close();
try {
- QV4::Function *f = QV4::EvalFunction::parseSource(ctx, fn, code, QQmlJS::Codegen::GlobalCode,
- /*strictMode =*/ false, /*inheritContext =*/ false);
- if (!f)
- continue;
- QV4::Value result = vm.run(f);
+ QV4::Script script(ctx, code, fn);
+ script.parse();
+ QV4::Value result = script.run();
if (!result.isUndefined()) {
if (! qgetenv("SHOW_EXIT_VALUE").isEmpty())
std::cout << "exit value: " << qPrintable(result.toString(ctx)->toQString()) << std::endl;