Skip to content

Commit

Permalink
Merge pull request tklab-tud#165 from tklab-tud/sradomski
Browse files Browse the repository at this point in the history
Reenabled V8, Debugger tests and smaller fixes
  • Loading branch information
sradomski authored Aug 2, 2017
2 parents 998e624 + 045bde7 commit 97e72c5
Show file tree
Hide file tree
Showing 47 changed files with 2,924 additions and 1,734 deletions.
12 changes: 6 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -410,13 +410,13 @@ OPTION(WITH_DM_ECMA_V8 "Do search for the V8 ECMAScript implementation" ON)
if (WITH_DM_ECMA_V8)
find_package(V8)
if (V8_FOUND)
# set(ECMA_FOUND ON)
# include_directories(${V8_INCLUDE_DIR})
# list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY})
set(ECMA_FOUND ON)
include_directories(${V8_INCLUDE_DIR})
list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY})

message(WARNING "We no longer support the V8 ECMAScript engine - contributions are welcome")
set(V8_FOUND OFF)
set(WITH_DM_ECMA_V8 OFF)
# message(WARNING "We no longer support the V8 ECMAScript engine - contributions are welcome")
# set(V8_FOUND OFF)
# set(WITH_DM_ECMA_V8 OFF)
else()
set(WITH_DM_ECMA_V8 OFF)
endif()
Expand Down
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@ For more detailled information, refer to the [documentation](http://tklab-tud.gi

## Changes

* **[9db80409b3ca048c4b404a43d2c224f374c0090a](https://github.com/tklab-tud/uscxml/pull/163/commits/9db80409b3ca048c4b404a43d2c224f374c0090a):**
* **08/01/2017:**

We selectively re-enabled support for Google's V8 ECMAScript engine, but only in version 3.23.17 and 3.14.05 and API compatible versions. These two versions are noteworthy as the first one used to be distributed via MacPorts and the second one is still found in many Linux distributions (e.g. Debian and Ubuntu). It is bordering on impossible to build them from source today as they are rather old. If you need an ECMAScript datamodel and do not have binary images of these, just go for `libjavascriptcoregtk-4.0-dev`. Make sure it's version **4.0** as the previous version had a bug with `JSCheckScriptSyntax`.

* **07/19/2017:**

We **dropped support for Google's V8 ECMAScript engine**. The API is changing too fast and there is no reliable way to get / build / identify older versions. The latest branch will not work with the wrappers generated from even SWIG 4.0 and I have no time to keep up with them. Use JavaScriptCore, its API is unchanged since we started to support it in 2012. If you feel capable to maintain the [](V8DataModel.cpp) send a push request. Everything will be left in place but we will ignore `libv8` at configure time. I may have another look when a number of Linux distribution settled on a more recent version, most are still shipping v8 in version 3.14.

* **[bfefa5fd44b9ed1491612f26b099db8ad624247b](https://github.com/tklab-tud/uscxml/pull/155/commits/bfefa5fd44b9ed1491612f26b099db8ad624247b):**
* **07/05/2017:**

We **broke the InterpreterMonitor** API by substituting the Interpreter instance in the first formal parameter by its sessionId throughout all callbacks. Retrieving the actual Interpreter involved locking a weak_ptr into a shared_ptr which proved to be a performance bottleneck. You can retrieve the Interpreter from its sessionId via the new static method `Interpreter::fromSessionId` if you actually need.

1 change: 1 addition & 0 deletions TODO.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Arraybuffers
Run tests on build slaves
2 changes: 2 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
#cmakedefine USCXML_VERSION_PATCH "@USCXML_VERSION_PATCH@"
#cmakedefine USCXML_VERSION "@USCXML_VERSION@"

#cmakedefine V8_VERSION @V8_VERSION@

// #cmakedefine XERCESC_NS @XERCESC_NS@

/** build type */
Expand Down
29 changes: 23 additions & 6 deletions contrib/cmake/FindV8.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,30 @@ if (V8_LIBRARY AND V8_INCLUDE_DIR)
set(CMAKE_REQUIRED_LIBRARIES ${V8_LIBRARY})
check_cxx_source_compiles("
#include <v8.h>
int main(){ v8::Local<v8::Value> foo = v8::Array::New(v8::Isolate::GetCurrent()); }
" V8_VER_GREATER_032317)
int main(){
v8::Locker locker;
v8::HandleScope scope;
v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New();
v8::Persistent<v8::Context> context = v8::Context::New(0, global);
v8::Context::Scope contextScope(context);
}" V8_VER_COMPILES_AS_031405)

if (NOT V8_VER_GREATER_032317)
message(STATUS "Your V8 installation is too old - we need >= 3.23.17")
unset(V8_LIBRARY)
unset(V8_INCLUDE_DIR)
if (NOT V8_VER_COMPILES_AS_031405)
check_cxx_source_compiles("
#include <v8.h>
int main(){
v8::Local<v8::Value> foo = v8::Array::New(v8::Isolate::GetCurrent());
}" V8_VER_COMPILES_AS_032317)

if (NOT V8_VER_COMPILES_AS_032317)
message(STATUS "Your V8 installation is unsupported - we support 3.14.5 and 3.23.17")
unset(V8_LIBRARY)
unset(V8_INCLUDE_DIR)
else()
set(V8_VERSION "032317")
endif()
else()
set(V8_VERSION "031405")
endif()
endif()

Expand Down
5 changes: 4 additions & 1 deletion src/uscxml/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#define ELPP_STACKTRACE_ON_CRASH 1
#endif

#if __cplusplus >= 201402L
#if defined(SWIGIMPORTED) || defined(SWIG)
#define DEPRECATED
#elif __cplusplus >= 201402L
#define DEPRECATED [[deprecated]]
#elif defined(__GNUC__)
#define DEPRECATED __attribute__((deprecated))
Expand All @@ -37,6 +39,7 @@
#define DEPRECATED(alternative)
#endif


#if defined(_WIN32) && !defined(USCXML_STATIC)
# ifdef USCXML_EXPORT
# define USCXML_API __declspec(dllexport)
Expand Down
34 changes: 33 additions & 1 deletion src/uscxml/debug/DebugSession.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "uscxml/debug/DebugSession.h"
#include "uscxml/debug/Debugger.h"
#include "uscxml/util/Predicates.h"
#include "uscxml/util/DOM.h"

#include "uscxml/interpreter/Logging.h"

Expand Down Expand Up @@ -440,7 +441,7 @@ Data DebugSession::debugEval(const Data& data) {
replyData.compound["reason"] = Data("No datamodel available", Data::VERBATIM);
} else {
try {
replyData.compound["eval"] = _interpreter.getImpl()->getAsData(expr);
replyData.compound["eval"] = _interpreter.getImpl()->evalAsData(expr);
} catch (Event e) {
replyData.compound["eval"] = e.data;
replyData.compound["eval"].compound["error"] = Data(e.name, Data::VERBATIM);
Expand All @@ -450,6 +451,37 @@ Data DebugSession::debugEval(const Data& data) {
return replyData;
}

Data DebugSession::debugEvent(const Data& data) {
Data replyData;

if (!_interpreter) {
replyData.compound["status"] = Data("failure", Data::VERBATIM);
replyData.compound["reason"] = Data("No interpreter running", Data::VERBATIM);
} else if (!data.hasKey("name")) {
replyData.compound["status"] = Data("failure", Data::VERBATIM);
replyData.compound["reason"] = Data("No event name given", Data::VERBATIM);
return replyData;
}
try {
Event event(data.at("name").atom);
if (data.hasKey("data")) {
event.data = data.at("data");
}
// TODO: this should not be necessary - initialize lazily
if (_interpreter.getState() == USCXML_INSTANTIATED) {
_interpreter.step();
}
_interpreter.receive(event);

} catch (Event e) {
replyData.compound["eval"] = e.data;
replyData.compound["eval"].compound["error"] = Data(e.name, Data::VERBATIM);
}
replyData.compound["status"] = Data("success", Data::VERBATIM);

return replyData;
}

std::shared_ptr<LoggerImpl> DebugSession::create() {
return shared_from_this();
}
Expand Down
1 change: 1 addition & 0 deletions src/uscxml/debug/DebugSession.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class USCXML_API DebugSession : public LoggerImpl ,public std::enable_shared_fro
Data disableAllBreakPoints();
Data getIssues();
Data debugEval(const Data& data);
Data debugEvent(const Data& data);

void setDebugger(Debugger* debugger) {
_debugger = debugger;
Expand Down
10 changes: 6 additions & 4 deletions src/uscxml/debug/DebuggerServlet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ bool DebuggerServlet::requestFromHTTP(const HTTPServer::Request& request) {
} else if (boost::istarts_with(request.data.at("path").atom, "/debug/connect")) {
processConnect(request);
return true;
} else if (boost::starts_with(request.data.at("path").atom, "/debug/sessions")) {
processListSessions(request);
} else if (boost::starts_with(request.data.at("path").atom, "/debug/instances")) {
processListInstances(request);
return true;
}

Expand Down Expand Up @@ -168,6 +168,8 @@ bool DebuggerServlet::requestFromHTTP(const HTTPServer::Request& request) {
replyData = session->debugResume(request.data["content"]);
} else if (boost::starts_with(request.data.at("path").atom, "/debug/eval")) {
replyData = session->debugEval(request.data["content"]);
} else if (boost::starts_with(request.data.at("path").atom, "/debug/event")) {
replyData = session->debugEvent(request.data["content"]);
}

if (!replyData.empty()) {
Expand Down Expand Up @@ -220,7 +222,7 @@ void DebuggerServlet::processDisconnect(const HTTPServer::Request& request) {
returnData(request, replyData);
}

void DebuggerServlet::processListSessions(const HTTPServer::Request& request) {
void DebuggerServlet::processListInstances(const HTTPServer::Request& request) {
Data replyData;

std::map<std::string, std::weak_ptr<InterpreterImpl> > instances = InterpreterImpl::getInstances();
Expand All @@ -234,7 +236,7 @@ void DebuggerServlet::processListSessions(const HTTPServer::Request& request) {
sessionData.compound["source"] = Data(instance->getBaseURL(), Data::VERBATIM);
sessionData.compound["xml"].node = instance->getDocument();

replyData.compound["sessions"].array.push_back(sessionData);
replyData.compound["instances"].array.push_back(sessionData);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/uscxml/debug/DebuggerServlet.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class USCXML_API DebuggerServlet : public Debugger, public HTTPServlet {

void processDisconnect(const HTTPServer::Request& request);
void processConnect(const HTTPServer::Request& request);
void processListSessions(const HTTPServer::Request& request);
void processListInstances(const HTTPServer::Request& request);

void processIssues(const HTTPServer::Request& request);

Expand Down
4 changes: 3 additions & 1 deletion src/uscxml/debug/InterpreterIssue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ std::list<InterpreterIssue> InterpreterIssue::forInterpreter(InterpreterImpl* in

for (auto iter = scripts.begin(); iter != scripts.end(); iter++) {
DOMElement* script = *iter;
if (HAS_ATTR(script, kXMLCharSource) && script->getChildNodes()->getLength() > 0) {
if (HAS_ATTR(script, kXMLCharSource) &&
script->getChildNodes()->getLength() > 0 &&
script->getUserData(X("downladed")) == NULL) {
issues.push_back(InterpreterIssue("Script element cannot have src attribute and children", script, InterpreterIssue::USCXML_ISSUE_WARNING));
}
}
Expand Down
22 changes: 13 additions & 9 deletions src/uscxml/interpreter/BasicContentExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void BasicContentExecutor::processAssign(XERCESC_NS::DOMElement* content) {
additionalAttr[X(attr->getNodeName()).str()] = X(attr->getNodeValue()).str();
}

_callbacks->assign(location, elementAsData(content, true), additionalAttr);
_callbacks->assign(location, elementAsData(content), additionalAttr);
}

void BasicContentExecutor::processForeach(XERCESC_NS::DOMElement* content) {
Expand Down Expand Up @@ -545,7 +545,12 @@ void BasicContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC
// content
std::list<DOMElement*> contents = DOMUtils::filterChildElements(XML_PREFIX(doneData).str() + "content", doneData);
if (contents.size() > 0) {
doneEvent.data = elementAsData(contents.front());
if (HAS_ATTR(contents.front(), kXMLCharExpr) &&
!_callbacks->isLegalDataValue(ATTR(contents.front(), kXMLCharExpr))) {
ERROR_EXECUTION_THROW2("Expression '" + ATTR(contents.front(), kXMLCharExpr) + "' is not a legal data value", contents.front());
} else {
doneEvent.data = elementAsData(contents.front());
}
}
} catch (ErrorEvent e) {
ERROR_EXECUTION_RETHROW(e, "Syntax error in donedata element content", doneData);
Expand Down Expand Up @@ -594,15 +599,14 @@ void BasicContentExecutor::processParams(std::multimap<std::string, Data>& param
}
}

Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element, bool asExpression) {
Data BasicContentExecutor::elementAsData(XERCESC_NS::DOMElement* element) {
// element with expr
if (HAS_ATTR(element, kXMLCharExpr)) {
std::string expr = ATTR(element, kXMLCharExpr);
if (_callbacks->isLegalDataValue(expr)) {
return Data(expr, Data::INTERPRETED);
} else {
ERROR_EXECUTION_THROW2("Expression '" + expr + "' is not a legal data value", element);
}
// we cannot throw here:
// - with init, we need to check in the datamodel
// - with content, we need to invoke isLegalDataValue later
// test 277, 528
return Data(ATTR(element, kXMLCharExpr), Data::INTERPRETED);
}

// element with external src - this ought to behave just as with child nodes below
Expand Down
2 changes: 1 addition & 1 deletion src/uscxml/interpreter/BasicContentExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class USCXML_API BasicContentExecutor : public ContentExecutorImpl {
virtual void uninvoke(XERCESC_NS::DOMElement* invoke);
virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData);

virtual Data elementAsData(XERCESC_NS::DOMElement* element, bool asExpression = false);
virtual Data elementAsData(XERCESC_NS::DOMElement* element);

protected:
void processNameLists(std::map<std::string, Data>& nameMap, XERCESC_NS::DOMElement* element);
Expand Down
4 changes: 2 additions & 2 deletions src/uscxml/interpreter/ContentExecutor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ void ContentExecutor::uninvoke(XERCESC_NS::DOMElement* invoke) {
_impl->uninvoke(invoke);
}

Data ContentExecutor::elementAsData(XERCESC_NS::DOMElement* element, bool asExpression) {
return _impl->elementAsData(element, asExpression);
Data ContentExecutor::elementAsData(XERCESC_NS::DOMElement* element) {
return _impl->elementAsData(element);
}

void ContentExecutor::raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) {
Expand Down
2 changes: 1 addition & 1 deletion src/uscxml/interpreter/ContentExecutor.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class USCXML_API ContentExecutor {
virtual void process(XERCESC_NS::DOMElement* block);
virtual void invoke(XERCESC_NS::DOMElement* invoke);
virtual void uninvoke(XERCESC_NS::DOMElement* invoke);
virtual Data elementAsData(XERCESC_NS::DOMElement* element, bool asExpression = false);
virtual Data elementAsData(XERCESC_NS::DOMElement* element);
virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData);
virtual std::shared_ptr<ContentExecutorImpl> getImpl() const;

Expand Down
2 changes: 1 addition & 1 deletion src/uscxml/interpreter/ContentExecutorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class USCXML_API ContentExecutorImpl {
virtual void uninvoke(XERCESC_NS::DOMElement* invoke) = 0;

virtual void raiseDoneEvent(XERCESC_NS::DOMElement* state, XERCESC_NS::DOMElement* doneData) = 0;
virtual Data elementAsData(XERCESC_NS::DOMElement* element, bool asExpression = false) = 0;
virtual Data elementAsData(XERCESC_NS::DOMElement* element) = 0;

protected:
ContentExecutorCallbacks* _callbacks;
Expand Down
19 changes: 10 additions & 9 deletions src/uscxml/interpreter/InterpreterImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ void InterpreterImpl::reset() {
if (_microStepper)
_microStepper.reset();

// _isInitialized = false;
_isInitialized = false;
_state = USCXML_INSTANTIATED;
// _dataModel.reset();
if (_delayQueue)
Expand Down Expand Up @@ -320,7 +320,12 @@ void InterpreterImpl::setupDOM() {
XERCESC_NS::DOMText* scriptText = _document->createTextNode(X(contents));
XERCESC_NS::DOMNode* newNode = _document->importNode(scriptText, true);
script->appendChild(newNode);
script->removeAttribute(kXMLCharSource); // remove attribute for validation: see issue 141
/**
* We nees to download all scripts (issue134) but also fail validation when there
* are child nodes with the src attribute present (issue141). Make a note that we
* already downloaded the content.
*/
script->setUserData(X("downloaded"), newNode, NULL);
}
}

Expand Down Expand Up @@ -378,7 +383,6 @@ void InterpreterImpl::init() {

// do not override if already set
if (_ioProcs.find(ioProcIter->first) != _ioProcs.end()) {
ioProcIter++;
continue;
}

Expand Down Expand Up @@ -438,15 +442,12 @@ void InterpreterImpl::initData(XERCESC_NS::DOMElement* root) {
} else if (_invokeReq.namelist.find(id) != _invokeReq.namelist.end()) {
_dataModel.init(id, _invokeReq.namelist[id], additionalAttr);
} else {
try {
_dataModel.init(id, _execContent.elementAsData(root), additionalAttr);
} catch (ErrorEvent e) {
// test 453
_dataModel.init(id, _execContent.elementAsData(root, true), additionalAttr);
}
_dataModel.init(id, _execContent.elementAsData(root), additionalAttr);
}
} catch(ErrorEvent e) {
// test 277
e.data.compound["xpath"] = uscxml::Data(DOMUtils::xPathForNode(root), uscxml::Data::VERBATIM);
\
enqueueInternal(e);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/uscxml/plugins/DataModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,13 @@ class USCXML_API DataModel {
const std::map<std::string, std::string>& attr = std::map<std::string, std::string>());

/// @copydoc DataModelImpl::isDeclared()
virtual bool isDeclared(const std::string& expr);
DEPRECATED virtual bool isDeclared(const std::string& expr);

/// @copydoc DataModelImpl::replaceExpressions()
size_t replaceExpressions(std::string& content);
DEPRECATED size_t replaceExpressions(std::string& content);

/// @copydoc DataModelImpl::addExtension()
virtual void addExtension(DataModelExtension* ext);
DEPRECATED virtual void addExtension(DataModelExtension* ext);

protected:
std::shared_ptr<DataModelImpl> _impl;
Expand Down
Loading

0 comments on commit 97e72c5

Please sign in to comment.