diff options
author | Simon Hausmann <[email protected]> | 2016-10-22 05:24:20 +0200 |
---|---|---|
committer | Simon Hausmann <[email protected]> | 2016-11-26 09:17:36 +0000 |
commit | 8bf579d8d4feb13ca8651e98dd762b28483abe9e (patch) | |
tree | 7d779292848d742b427bc35a1723b1049e60ee99 /tools/qmljs/qmljs.cpp | |
parent | 9fdab4a3619f457f66716c74ea73355453557e52 (diff) |
Cleanup of builtin JS helpers for qmljs
Replace the hand-written gc and print functions with the print and gc
functions also used in Qml and QJSEngine. And while we're at it, this
also adds the console object.
Change-Id: Ia3a0ff24936b7ed5149cb689838b987f9178131e
Reviewed-by: Erik Verbruggen <[email protected]>
Reviewed-by: Mitch Curtis <[email protected]>
Diffstat (limited to 'tools/qmljs/qmljs.cpp')
-rw-r--r-- | tools/qmljs/qmljs.cpp | 57 |
1 files changed, 2 insertions, 55 deletions
diff --git a/tools/qmljs/qmljs.cpp b/tools/qmljs/qmljs.cpp index b0079dcf49..dd1898a88a 100644 --- a/tools/qmljs/qmljs.cpp +++ b/tools/qmljs/qmljs.cpp @@ -42,6 +42,7 @@ #include "private/qv4context_p.h" #include "private/qv4script_p.h" #include "private/qv4string_p.h" +#include "private/qqmlbuiltinfunctions_p.h" #ifdef V4_ENABLE_JIT # include "private/qv4isel_masm_p.h" @@ -60,57 +61,6 @@ QT_REQUIRE_CONFIG(qml_interpreter); #include <iostream> -namespace builtins { - -using namespace QV4; - -struct Print: FunctionObject -{ - struct Data : Heap::FunctionObject { - void init(ExecutionContext *scope) - { - Heap::FunctionObject::init(scope, QStringLiteral("print")); - } - }; - V4_OBJECT(FunctionObject) - - static void call(const Managed *, Scope &scope, CallData *callData) - { - for (int i = 0; i < callData->argc; ++i) { - QString s = callData->args[i].toQStringNoThrow(); - if (i) - std::cout << ' '; - std::cout << qPrintable(s); - } - std::cout << std::endl; - scope.result = Encode::undefined(); - } -}; - -DEFINE_OBJECT_VTABLE(Print); - -struct GC: public FunctionObject -{ - struct Data : Heap::FunctionObject { - void init(ExecutionContext *scope) - { - Heap::FunctionObject::init(scope, QStringLiteral("gc")); - } - - }; - V4_OBJECT(FunctionObject) - - static void call(const Managed *m, Scope &scope, CallData *) - { - static_cast<const GC *>(m)->engine()->memoryManager->runGC(); - scope.result = Encode::undefined(); - } -}; - -DEFINE_OBJECT_VTABLE(GC); - -} // builtins - static void showException(QV4::ExecutionContext *ctx, const QV4::Value &exception, const QV4::StackTrace &trace) { QV4::Scope scope(ctx); @@ -200,10 +150,7 @@ int main(int argc, char *argv[]) QV4::Scope scope(&vm); QV4::ScopedContext ctx(scope, vm.rootContext()); - QV4::ScopedObject print(scope, vm.memoryManager->allocObject<builtins::Print>(vm.rootContext())); - vm.globalObject->put(QV4::ScopedString(scope, vm.newIdentifier(QStringLiteral("print"))).getPointer(), print); - QV4::ScopedObject gc(scope, vm.memoryManager->allocObject<builtins::GC>(ctx)); - vm.globalObject->put(QV4::ScopedString(scope, vm.newIdentifier(QStringLiteral("gc"))).getPointer(), gc); + QV4::GlobalExtensions::init(vm.globalObject, QJSEngine::ConsoleExtension | QJSEngine::GarbageCollectionExtension); for (const QString &fn : qAsConst(args)) { QFile file(fn); |