diff options
-rw-r--r-- | src/uscxml/interpreter/BasicContentExecutor.cpp | 2 | ||||
-rw-r--r-- | src/uscxml/interpreter/InterpreterImpl.cpp | 23 | ||||
-rw-r--r-- | test/issues/test-issue134.js | 1 | ||||
-rw-r--r-- | test/issues/test-issue134.scxml | 14 |
4 files changed, 39 insertions, 1 deletions
diff --git a/src/uscxml/interpreter/BasicContentExecutor.cpp b/src/uscxml/interpreter/BasicContentExecutor.cpp index 9796c4c..696b575 100644 --- a/src/uscxml/interpreter/BasicContentExecutor.cpp +++ b/src/uscxml/interpreter/BasicContentExecutor.cpp @@ -289,7 +289,7 @@ void BasicContentExecutor::processLog(XERCESC_NS::DOMElement* content) { } void BasicContentExecutor::processScript(XERCESC_NS::DOMElement* content) { - // download as necessary + // contents were already downloaded in setupDOM, see to SCXML rec 5.8 std::string scriptContent(X(content->getTextContent())); _callbacks->eval(scriptContent); diff --git a/src/uscxml/interpreter/InterpreterImpl.cpp b/src/uscxml/interpreter/InterpreterImpl.cpp index 60448f9..f7a46fc 100644 --- a/src/uscxml/interpreter/InterpreterImpl.cpp +++ b/src/uscxml/interpreter/InterpreterImpl.cpp @@ -295,6 +295,29 @@ SCXML_STOP_SEARCH: _name = _baseURL.pathComponents().back(); } + // download all script, see issue 134 + std::list<DOMElement*> scripts = DOMUtils::filterChildElements(_xmlPrefix + "script", _scxml, true); + for (auto script : scripts) { + if (HAS_ATTR(script, kXMLCharSource)) { + std::string src = ATTR(script, kXMLCharSource); + std::string contents; + if (src.size() > 0) { + URL url(src); + if (!url.isAbsolute()) { + url = URL::resolve(url, _baseURL); + } + contents = url.getInContent(); + } else { + ERROR_COMMUNICATION2(exc, "Empty source attribute", script); + throw exc; + } + + XERCESC_NS::DOMText* scriptText = _document->createTextNode(X(contents)); + XERCESC_NS::DOMNode* newNode = _document->importNode(scriptText, true); + script->appendChild(newNode); + } + } + _binding = (HAS_ATTR(_scxml, kXMLCharBinding) && iequals(ATTR(_scxml, kXMLCharBinding), "late") ? LATE : EARLY); } diff --git a/test/issues/test-issue134.js b/test/issues/test-issue134.js new file mode 100644 index 0000000..6b3e64f --- /dev/null +++ b/test/issues/test-issue134.js @@ -0,0 +1 @@ +Var1 = 1;
\ No newline at end of file diff --git a/test/issues/test-issue134.scxml b/test/issues/test-issue134.scxml new file mode 100644 index 0000000..973065d --- /dev/null +++ b/test/issues/test-issue134.scxml @@ -0,0 +1,14 @@ +<scxml datamodel="ecmascript"> + <datamodel> + <data id="Var1" expr="0" /> + </datamodel> + <state id="s0"> + <onentry> + <script src="test-issue134.js"/> + </onentry> + <transition cond="Var1 == 1" target="pass" /> + <transition cond="Var1 != 1" target="fail" /> + </state> + <final id="pass" /> + <final id="fail" /> +</scxml>
\ No newline at end of file |