8 #include "executor_kjs_p.h"
10 #include <kjs/kjsarguments.h>
11 #include <kjs/kjsinterpreter.h>
12 #include <kjs/kjsobject.h>
13 #include <kjs/kjsprototype.h>
14 #include <kjs_version.h>
18 #include "../debug_p.h"
19 #include "../document_p.h"
21 #include "config-okular.h"
23 #include "kjs_app_p.h"
24 #include "kjs_console_p.h"
25 #include "kjs_data_p.h"
26 #include "kjs_display_p.h"
27 #include "kjs_document_p.h"
28 #include "kjs_event_p.h"
29 #include "kjs_field_p.h"
30 #include "kjs_fullscreen_p.h"
31 #include "kjs_ocg_p.h"
32 #include "kjs_spell_p.h"
33 #include "kjs_util_p.h"
37 class Okular::ExecutorKJSPrivate
40 explicit ExecutorKJSPrivate(DocumentPrivate *doc)
52 DocumentPrivate *m_doc;
57 void ExecutorKJSPrivate::initTypes()
59 m_docObject = JSDocument::wrapDocument(m_doc);
62 m_interpreter->setTimeoutTime(2000);
63 KJSContext *ctx = m_interpreter->globalContext();
66 JSFullscreen::initType(ctx);
67 JSConsole::initType(ctx);
68 JSData::initType(ctx);
69 JSDisplay::initType(ctx);
70 JSDocument::initType(ctx);
71 JSEvent::initType(ctx);
72 JSField::initType(ctx);
74 JSSpell::initType(ctx);
75 JSUtil::initType(ctx);
77 m_docObject.setProperty(ctx, QStringLiteral(
"app"), JSApp::object(ctx, m_doc));
78 m_docObject.setProperty(ctx, QStringLiteral(
"console"), JSConsole::object(ctx));
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));
82 m_docObject.setProperty(ctx, QStringLiteral(
"spell"), JSSpell::object(ctx));
83 m_docObject.setProperty(ctx, QStringLiteral(
"util"), JSUtil::object(ctx));
86 ExecutorKJS::ExecutorKJS(DocumentPrivate *doc)
87 : d(new ExecutorKJSPrivate(doc))
91 ExecutorKJS::~ExecutorKJS()
93 JSField::clearCachedFields();
94 JSApp::clearCachedFields();
95 JSOCG::clearCachedFields();
99 void ExecutorKJS::execute(
const QString &script, Event *event)
101 KJSContext *ctx = d->m_interpreter->globalContext();
103 d->m_docObject.setProperty(ctx, QStringLiteral(
"event"), event ? JSEvent::wrapEvent(ctx, event) :
KJSUndefined());
105 d->m_interpreter->startTimeoutCheck();
106 KJSResult result = d->m_interpreter->evaluate(QStringLiteral(
"okular.js"), 1, script, &d->m_docObject);
107 d->m_interpreter->stopTimeoutCheck();
110 qCDebug(OkularCoreDebug) <<
"JS exception" << result.
errorMessage();
112 qCDebug(OkularCoreDebug) <<
"result:" << result.value().toString(ctx);
115 qCDebug(OkularCoreDebug) <<
"Event Result:" <<
event->name() <<
event->type() <<
"value:" <<
event->value();