aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4engine.cpp
diff options
context:
space:
mode:
authorLars Knoll <lars.knoll@digia.com>2013-09-18 09:30:45 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-22 01:06:20 +0200
commit055f71f87d5d58be2aafd6c0ef2b84d57ed48b63 (patch)
tree71f5f12e997bdcca340309cd5da81aacf0b3731f /src/qml/jsruntime/qv4engine.cpp
parent2d781c4ca42f50643fa37200073a2fb2644b3806 (diff)
Introduce a Referenced<T> class to pass Objects into methods
Added some convenience typedefs (StringRef, ObjectRef, ReturnedString, ScopedString, ...) Used StringRef in newBuiltinFunction() for testing. Cleaned up the duplicated code for thrower functions. Change-Id: I7b7676690cbe70d9eabb0a5afd0d922f0be3aefd Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index c9d3716469..70108aa00f 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -79,6 +79,12 @@ using namespace QV4;
static QBasicAtomicInt engineSerial = Q_BASIC_ATOMIC_INITIALIZER(1);
+static ReturnedValue throwTypeError(SimpleCallContext *ctx)
+{
+ ctx->throwTypeError();
+ return Value::undefinedValue().asReturnedValue();
+}
+
ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
: memoryManager(new QV4::MemoryManager)
, executableAllocator(new QV4::ExecutableAllocator)
@@ -287,6 +293,10 @@ ExecutionEngine::ExecutionEngine(QQmlJS::EvalISelFactory *factory)
globalObject->defineDefaultProperty(rootContext, QStringLiteral("encodeURIComponent"), GlobalFunctions::method_encodeURIComponent, 1);
globalObject->defineDefaultProperty(rootContext, QStringLiteral("escape"), GlobalFunctions::method_escape, 1);
globalObject->defineDefaultProperty(rootContext, QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1);
+
+ Scope scope(this);
+ Scoped<String> name(scope, newString(QStringLiteral("thrower")));
+ thrower = newBuiltinFunction(rootContext, name, throwTypeError)->getPointer();
}
ExecutionEngine::~ExecutionEngine()
@@ -344,9 +354,9 @@ ExecutionContext *ExecutionEngine::pushGlobalContext()
return current;
}
-Returned<FunctionObject> *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, String *name, ReturnedValue (*code)(SimpleCallContext *))
+Returned<FunctionObject> *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, StringRef name, ReturnedValue (*code)(SimpleCallContext *))
{
- BuiltinFunction *f = new (memoryManager) BuiltinFunction(scope, name, code);
+ BuiltinFunction *f = new (memoryManager) BuiltinFunction(scope, name.getPointer(), code);
return f->asReturned<FunctionObject>();
}
@@ -721,6 +731,8 @@ void ExecutionEngine::markObjects()
typeErrorCtor.mark();
uRIErrorCtor.mark();
+ thrower->mark();
+
if (m_qmlExtensions)
m_qmlExtensions->markObjects();