From da01333817e3e91fd2e690e91220af1128460a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Netto?= Date: Fri, 19 Jul 2019 14:58:12 -0300 Subject: [PATCH] Fixed the KJSPrototype pointers and deleted unused arguments. --- core/script/kjs_app.cpp | 10 +++++----- core/script/kjs_display.cpp | 10 ++++++---- core/script/kjs_document.cpp | 2 +- core/script/kjs_field.cpp | 4 ++-- core/script/kjs_ocg.cpp | 10 ++++++---- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/core/script/kjs_app.cpp b/core/script/kjs_app.cpp index 638efce48..3534906ec 100644 --- a/core/script/kjs_app.cpp +++ b/core/script/kjs_app.cpp @@ -220,11 +220,11 @@ static KJSObject appSetInterval( KJSContext *ctx, void *object, } // app.clearInterval() -static KJSObject appClearInterval( KJSContext *ctx, void *object, +static KJSObject appClearInterval( KJSContext *ctx, void *, const KJSArguments &arguments ) { KJSObject timerObject = arguments.at( 0 ); - const int timerId = timerObject.property( ctx, QStringLiteral( "timerID" ).toLatin1().toBase64() ).toInt32( ctx ); + const int timerId = timerObject.property( ctx, QStringLiteral("okular_timerID") ).toInt32( ctx ); QTimer *timer = g_timerCache->value( timerId ); if( timer != nullptr ) { @@ -255,11 +255,11 @@ static KJSObject appSetTimeOut( KJSContext *ctx, void *object, } // app.clearTimeOut() -static KJSObject appClearTimeOut( KJSContext *ctx, void *object, +static KJSObject appClearTimeOut( KJSContext *ctx, void *, const KJSArguments &arguments ) { KJSObject timerObject = arguments.at( 0 ); - const int timerId = timerObject.property( ctx, QStringLiteral( "timerID" ).toLatin1().toBase64() ).toInt32( ctx ); + const int timerId = timerObject.property( ctx, QStringLiteral("okular_timerID") ).toInt32( ctx ); QTimer *timer = g_timerCache->value( timerId ); if( timer != nullptr ) @@ -311,7 +311,7 @@ KJSObject JSApp::object( KJSContext *ctx, DocumentPrivate *doc ) KJSObject JSApp::wrapTimer( KJSContext *ctx, QTimer *timer) { KJSObject timerObject = g_appProto->constructObject( ctx, timer ); - timerObject.setProperty( ctx, QStringLiteral("timerID").toLatin1().toBase64(), timer->timerId() ); + timerObject.setProperty( ctx, QStringLiteral("okular_timerID"), timer->timerId() ); g_timerCache->insert( timer->timerId(), timer ); diff --git a/core/script/kjs_display.cpp b/core/script/kjs_display.cpp index 41e09b6e6..d7ed212b6 100644 --- a/core/script/kjs_display.cpp +++ b/core/script/kjs_display.cpp @@ -19,7 +19,7 @@ using namespace Okular; -std::unique_ptr < KJSPrototype > g_displayProto; +static KJSPrototype *g_displayProto; // display.hidden static KJSObject displayGetHidden( KJSContext *, void * ) @@ -46,11 +46,13 @@ static KJSObject displayGetNoPrint( KJSContext *, void * ) } void JSDisplay::initType( KJSContext *ctx ) -{ - if ( g_displayProto ) +{ + static bool initialized = false; + if ( initialized ) return; + initialized = true; - g_displayProto.reset(new KJSPrototype); + g_displayProto = new KJSPrototype(); g_displayProto->defineProperty( ctx, QStringLiteral("hidden"), displayGetHidden ); g_displayProto->defineProperty( ctx, QStringLiteral("visible"), displayGetVisible ); diff --git a/core/script/kjs_document.cpp b/core/script/kjs_document.cpp index 7c17e62ce..deb95103b 100644 --- a/core/script/kjs_document.cpp +++ b/core/script/kjs_document.cpp @@ -290,7 +290,7 @@ static KJSObject docGetNthFieldName( KJSContext *ctx, void *object, } static KJSObject docGetOCGs( KJSContext *ctx, void *object, - const KJSArguments &arguments ) + const KJSArguments & ) { const DocumentPrivate *doc = reinterpret_cast< DocumentPrivate* >( object ); diff --git a/core/script/kjs_field.cpp b/core/script/kjs_field.cpp index b6fb521b2..8a5e5eef6 100644 --- a/core/script/kjs_field.cpp +++ b/core/script/kjs_field.cpp @@ -273,7 +273,7 @@ static KJSObject fieldButtonGetIcon( KJSContext *ctx, void *object, FormField *field = reinterpret_cast< FormField * >( object ); KJSObject fieldObject; - fieldObject.setProperty( ctx, QStringLiteral("name").toLatin1().toBase64(), field->name() ); + fieldObject.setProperty( ctx, QStringLiteral("okular_name"), field->name() ); g_buttonCache->insert( field->name(), field ); return fieldObject; @@ -287,7 +287,7 @@ static KJSObject fieldButtonSetIcon( KJSContext *ctx, void *object, { FormField *field = reinterpret_cast< FormField * >( object ); - const QString fieldName = arguments.at( 0 ).property( ctx, QStringLiteral("name").toLatin1().toBase64() ).toString( ctx ); + const QString fieldName = arguments.at( 0 ).property( ctx, QStringLiteral("okular_name") ).toString( ctx ); if( field->type() == Okular::FormField::FormButton ) { diff --git a/core/script/kjs_ocg.cpp b/core/script/kjs_ocg.cpp index 3471676f2..d7061f066 100644 --- a/core/script/kjs_ocg.cpp +++ b/core/script/kjs_ocg.cpp @@ -22,7 +22,7 @@ using namespace Okular; -std::unique_ptr < KJSPrototype > g_OCGProto; +static KJSPrototype *g_OCGProto; typedef QHash< QPair< int, int > *, QAbstractItemModel* > OCGCache; Q_GLOBAL_STATIC( OCGCache, g_OCGCache ) @@ -56,11 +56,13 @@ static void OCGSetState( KJSContext* ctx, void* object, void JSOCG::initType( KJSContext *ctx ) -{ - if ( g_OCGProto ) +{ + static bool initialized = false; + if ( initialized ) return; + initialized = true; - g_OCGProto.reset(new KJSPrototype); + g_OCGProto = new KJSPrototype(); g_OCGProto->defineProperty( ctx, QStringLiteral("state"), OCGGetState, OCGSetState ); } -- GitLab