• Skip to content
  • Skip to link menu
  • KDE API Reference
  • kdelibs-4.14.38 API Reference
  • KDE Home
  • Contact Us
 

kjsembed

  • KJSEmbed
  • Engine
Public Types | Public Member Functions | Static Public Member Functions | List of all members
KJSEmbed::Engine Class Reference

#include <kjsembed.h>

Public Types

enum  ExitStatus { Success = 0 , Failure = 1 }
 

Public Member Functions

 Engine (bool enableBindings=true)
 
virtual ~Engine ()
 
KJS::JSObject * addObject (QObject *obj, const KJS::UString &name=KJS::UString()) const
 
KJS::JSObject * addObject (QObject *obj, KJS::JSObject *parent, const KJS::UString &name=KJS::UString()) const
 
KJS::JSValue * callMethod (const KJS::UString &methodName, const KJS::List &args=KJS::List())
 
KJS::JSValue * callMethod (KJS::JSObject *parent, const KJS::UString &methodName, const KJS::List &args=KJS::List())
 
KJS::Completion completion () const
 
KJS::JSObject * construct (const KJS::UString &className, const KJS::List &args=KJS::List()) const
 
ExitStatus execute (const KJS::UString &code)
 
KJS::Interpreter * interpreter () const
 
bool isBindingsEnabled () const
 
ExitStatus runFile (const KJS::UString &file)
 

Static Public Member Functions

static KJS::Completion runFile (KJS::Interpreter *interpreter, const KJS::UString &file)
 

Detailed Description

The main interface for running embedded Javascript.

KJSEmbed::Engine *engine = new KJSEmbed::Engine();
KJS::Interpreter *interpreter = engine->interpreter();
interpreter->setShouldPrintExceptions(true);
KJS::ExecState *exec = interpreter->globalExec();
KJS::UString code("print(\"Hello World\")");
KJSEmbed::Engine::ExitStatus exitstatus = engine->execute(code);
KJS::Completion completion = engine->completion();
if(exitstatus != KJSEmbed::Engine::Success) {
KJS::JSValue* value = completion.value();
qDebug() << value->toString(exec).qstring();
}
KJSEmbed::Engine
The main interface for running embedded Javascript.
Definition: kjsembed.h:59
KJSEmbed::Engine::interpreter
KJS::Interpreter * interpreter() const
Returns the current interpreter.
Definition: kjsembed.cpp:200
KJSEmbed::Engine::completion
KJS::Completion completion() const
Returns the Completion object for the last script executed.
Definition: kjsembed.cpp:195
KJSEmbed::Engine::execute
ExitStatus execute(const KJS::UString &code)
Execute a code string using the current interpreter.
Definition: kjsembed.cpp:245
KJSEmbed::Engine::ExitStatus
ExitStatus
Status codes for script execution.
Definition: kjsembed.h:65
KJSEmbed::Engine::Success
@ Success
Definition: kjsembed.h:65
value
QVariant value
Definition: settings.cpp:35

Definition at line 58 of file kjsembed.h.

Member Enumeration Documentation

◆ ExitStatus

enum KJSEmbed::Engine::ExitStatus

Status codes for script execution.

Note that you can access the completion object itself with completion() for more detail.

Enumerator
Success 
Failure 

Definition at line 65 of file kjsembed.h.

Constructor & Destructor Documentation

◆ Engine()

KJSEmbed::Engine::Engine ( bool  enableBindings = true)

Constructs an embedded JS engine.

Parameters
enableBindingsIf true then the bindings will be added to the interpreter created. Otherwise a plain interpreter with nothing beyond the JS built in functions and objects is created. This allows users who want to run untrusted scripts to choose exactly which bindings they offer.

Definition at line 162 of file kjsembed.cpp.

◆ ~Engine()

KJSEmbed::Engine::~Engine ( )
virtual

Clean up.

Definition at line 170 of file kjsembed.cpp.

Member Function Documentation

◆ addObject() [1/2]

KJS::JSObject * KJSEmbed::Engine::addObject ( QObject *  obj,
const KJS::UString &  name = KJS::UString() 
) const

publishes a QObject to the global context of the javascript interpereter.

Definition at line 190 of file kjsembed.cpp.

◆ addObject() [2/2]

KJS::JSObject * KJSEmbed::Engine::addObject ( QObject *  obj,
KJS::JSObject *  parent,
const KJS::UString &  name = KJS::UString() 
) const

publishes a QObject to a parent object.

Definition at line 180 of file kjsembed.cpp.

◆ callMethod() [1/2]

KJS::JSValue * KJSEmbed::Engine::callMethod ( const KJS::UString &  methodName,
const KJS::List &  args = KJS::List() 
)

Execute a method at the global scope of the javascript interperter.

Definition at line 263 of file kjsembed.cpp.

◆ callMethod() [2/2]

KJS::JSValue * KJSEmbed::Engine::callMethod ( KJS::JSObject *  parent,
const KJS::UString &  methodName,
const KJS::List &  args = KJS::List() 
)

Execute a method on an object.

Definition at line 285 of file kjsembed.cpp.

◆ completion()

KJS::Completion KJSEmbed::Engine::completion ( ) const

Returns the Completion object for the last script executed.

Definition at line 195 of file kjsembed.cpp.

◆ construct()

KJS::JSObject * KJSEmbed::Engine::construct ( const KJS::UString &  className,
const KJS::List &  args = KJS::List() 
) const

Create a new instance of an object that the Javascript engine knows about.

If the object doesn't exist a KJS::jsNull() is returned and an exception thrown.

Definition at line 256 of file kjsembed.cpp.

◆ execute()

Engine::ExitStatus KJSEmbed::Engine::execute ( const KJS::UString &  code)

Execute a code string using the current interpreter.

Parameters
codeThe script code to execute.

Definition at line 245 of file kjsembed.cpp.

◆ interpreter()

KJS::Interpreter * KJSEmbed::Engine::interpreter ( ) const

Returns the current interpreter.

Definition at line 200 of file kjsembed.cpp.

◆ isBindingsEnabled()

bool KJSEmbed::Engine::isBindingsEnabled ( ) const

Returns true if the Engine was created with the bindings enabled.

Definition at line 175 of file kjsembed.cpp.

◆ runFile() [1/2]

Engine::ExitStatus KJSEmbed::Engine::runFile ( const KJS::UString &  file)

Execute the file with the specified name using the current interpreter.

Parameters
fileFilename to execute.

Definition at line 233 of file kjsembed.cpp.

◆ runFile() [2/2]

KJS::Completion KJSEmbed::Engine::runFile ( KJS::Interpreter *  interpreter,
const KJS::UString &  file 
)
static

Execute the file with the specified name using the specified interpreter.

Parameters
interpreterInterpreter to use.
fileFilename to execute.

Definition at line 205 of file kjsembed.cpp.


The documentation for this class was generated from the following files:
  • kjsembed.h
  • kjsembed.cpp
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kjsembed

Skip menu "kjsembed"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdelibs-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal