Changeset View
Changeset View
Standalone View
Standalone View
core/script/executor_kjs.cpp
Show All 18 Lines | |||||
19 | 19 | | |||
20 | #include "../debug_p.h" | 20 | #include "../debug_p.h" | ||
21 | #include "../document_p.h" | 21 | #include "../document_p.h" | ||
22 | 22 | | |||
23 | #include "event_p.h" | 23 | #include "event_p.h" | ||
24 | #include "kjs_app_p.h" | 24 | #include "kjs_app_p.h" | ||
25 | #include "kjs_console_p.h" | 25 | #include "kjs_console_p.h" | ||
26 | #include "kjs_data_p.h" | 26 | #include "kjs_data_p.h" | ||
27 | #include "kjs_display_p.h" | ||||
27 | #include "kjs_document_p.h" | 28 | #include "kjs_document_p.h" | ||
28 | #include "kjs_event_p.h" | 29 | #include "kjs_event_p.h" | ||
29 | #include "kjs_field_p.h" | 30 | #include "kjs_field_p.h" | ||
30 | #include "kjs_fullscreen_p.h" | 31 | #include "kjs_fullscreen_p.h" | ||
32 | #include "kjs_ocg_p.h" | ||||
31 | #include "kjs_spell_p.h" | 33 | #include "kjs_spell_p.h" | ||
32 | #include "kjs_util_p.h" | 34 | #include "kjs_util_p.h" | ||
33 | 35 | | |||
34 | using namespace Okular; | 36 | using namespace Okular; | ||
35 | 37 | | |||
36 | class Okular::ExecutorKJSPrivate | 38 | class Okular::ExecutorKJSPrivate | ||
37 | { | 39 | { | ||
38 | public: | 40 | public: | ||
Show All 20 Lines | 59 | { | |||
59 | m_interpreter = new KJSInterpreter( m_docObject ); | 61 | m_interpreter = new KJSInterpreter( m_docObject ); | ||
60 | 62 | | |||
61 | KJSContext *ctx = m_interpreter->globalContext(); | 63 | KJSContext *ctx = m_interpreter->globalContext(); | ||
62 | 64 | | |||
63 | JSApp::initType( ctx ); | 65 | JSApp::initType( ctx ); | ||
64 | JSFullscreen::initType( ctx ); | 66 | JSFullscreen::initType( ctx ); | ||
65 | JSConsole::initType( ctx ); | 67 | JSConsole::initType( ctx ); | ||
66 | JSData::initType( ctx ); | 68 | JSData::initType( ctx ); | ||
69 | JSDisplay::initType( ctx ); | ||||
67 | JSDocument::initType( ctx ); | 70 | JSDocument::initType( ctx ); | ||
68 | JSEvent::initType( ctx ); | 71 | JSEvent::initType( ctx ); | ||
69 | JSField::initType( ctx ); | 72 | JSField::initType( ctx ); | ||
73 | JSOCG::initType( ctx ); | ||||
70 | JSSpell::initType( ctx ); | 74 | JSSpell::initType( ctx ); | ||
71 | JSUtil::initType( ctx ); | 75 | JSUtil::initType( ctx ); | ||
72 | 76 | | |||
73 | m_docObject.setProperty( ctx, QStringLiteral("app"), JSApp::object( ctx, m_doc ) ); | 77 | m_docObject.setProperty( ctx, QStringLiteral("app"), JSApp::object( ctx, m_doc ) ); | ||
74 | m_docObject.setProperty( ctx, QStringLiteral("console"), JSConsole::object( ctx ) ); | 78 | m_docObject.setProperty( ctx, QStringLiteral("console"), JSConsole::object( ctx ) ); | ||
75 | m_docObject.setProperty( ctx, QStringLiteral("Doc"), m_docObject ); | 79 | m_docObject.setProperty( ctx, QStringLiteral("Doc"), m_docObject ); | ||
80 | m_docObject.setProperty( ctx, QStringLiteral("display"), JSDisplay::object( ctx ) ); | ||||
81 | m_docObject.setProperty( ctx, QStringLiteral("OCG"), JSOCG::object( ctx ) ); | ||||
76 | m_docObject.setProperty( ctx, QStringLiteral("spell"), JSSpell::object( ctx ) ); | 82 | m_docObject.setProperty( ctx, QStringLiteral("spell"), JSSpell::object( ctx ) ); | ||
77 | m_docObject.setProperty( ctx, QStringLiteral("util"), JSUtil::object( ctx ) ); | 83 | m_docObject.setProperty( ctx, QStringLiteral("util"), JSUtil::object( ctx ) ); | ||
78 | } | 84 | } | ||
79 | 85 | | |||
80 | ExecutorKJS::ExecutorKJS( DocumentPrivate *doc ) | 86 | ExecutorKJS::ExecutorKJS( DocumentPrivate *doc ) | ||
81 | : d( new ExecutorKJSPrivate( doc ) ) | 87 | : d( new ExecutorKJSPrivate( doc ) ) | ||
82 | { | 88 | { | ||
83 | } | 89 | } | ||
84 | 90 | | |||
85 | ExecutorKJS::~ExecutorKJS() | 91 | ExecutorKJS::~ExecutorKJS() | ||
86 | { | 92 | { | ||
93 | JSField::clearCachedFields(); | ||||
94 | JSApp::clearCachedFields(); | ||||
95 | JSOCG::clearCachedFields(); | ||||
87 | delete d; | 96 | delete d; | ||
88 | } | 97 | } | ||
89 | 98 | | |||
90 | void ExecutorKJS::execute( const QString &script, Event *event ) | 99 | void ExecutorKJS::execute( const QString &script, Event *event ) | ||
91 | { | 100 | { | ||
92 | #if 0 | 101 | #if 0 | ||
93 | QString script2; | 102 | QString script2; | ||
94 | QString errMsg; | 103 | QString errMsg; | ||
95 | int errLine; | 104 | int errLine; | ||
96 | if ( !KJSInterpreter::normalizeCode( script, &script2, &errLine, &errMsg ) ) | 105 | if ( !KJSInterpreter::normalizeCode( script, &script2, &errLine, &errMsg ) ) | ||
97 | { | 106 | { | ||
98 | qCWarning(OkularCoreDebug) << "Parse error during normalization!"; | 107 | qCWarning(OkularCoreDebug) << "Parse error during normalization!"; | ||
99 | script2 = script; | 108 | script2 = script; | ||
100 | } | 109 | } | ||
101 | #endif | 110 | #endif | ||
102 | 111 | | |||
103 | KJSContext* ctx = d->m_interpreter->globalContext(); | 112 | KJSContext* ctx = d->m_interpreter->globalContext(); | ||
104 | 113 | | |||
105 | d->m_docObject.setProperty( ctx, QStringLiteral("event"), event ? JSEvent::wrapEvent( ctx, event ) : KJSUndefined() ); | 114 | d->m_docObject.setProperty( ctx, QStringLiteral("event"), event ? JSEvent::wrapEvent( ctx, event ) : KJSUndefined() ); | ||
106 | 115 | | |||
107 | KJSResult result = d->m_interpreter->evaluate( QStringLiteral("okular.js"), 1, | 116 | KJSResult result = d->m_interpreter->evaluate( QStringLiteral("okular.js"), 1, | ||
108 | script, &d->m_docObject ); | 117 | script, &d->m_docObject ); | ||
118 | | ||||
109 | if ( result.isException() || ctx->hasException() ) | 119 | if ( result.isException() || ctx->hasException() ) | ||
110 | { | 120 | { | ||
111 | qCDebug(OkularCoreDebug) << "JS exception" << result.errorMessage(); | 121 | qCDebug(OkularCoreDebug) << "JS exception" << result.errorMessage(); | ||
112 | } | 122 | } | ||
113 | else | 123 | else | ||
114 | { | 124 | { | ||
115 | qCDebug(OkularCoreDebug) << "result:" << result.value().toString( ctx ); | 125 | qCDebug(OkularCoreDebug) << "result:" << result.value().toString( ctx ); | ||
116 | 126 | | |||
117 | if (event) | 127 | if (event) | ||
118 | { | 128 | { | ||
119 | qCDebug(OkularCoreDebug) << "Event Result:" << event->name() | 129 | qCDebug(OkularCoreDebug) << "Event Result:" << event->name() | ||
120 | << event->type() << "value:" << event->value(); | 130 | << event->type() << "value:" << event->value(); | ||
121 | } | 131 | } | ||
122 | } | 132 | } | ||
123 | JSField::clearCachedFields(); | | |||
124 | } | 133 | } |