diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp | 110 |
1 files changed, 64 insertions, 46 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index fd4da3c..86bafd3 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -625,11 +625,60 @@ JSValueRef JSCDataModel::evalAsValue(const std::string& expr, bool dontThrow) { return result; } +JSValueRef JSCDataModel::getNodeAsValue(const Node<std::string>& node) { + switch (node.getNodeType()) { + case Node_base::ELEMENT_NODE: { + TO_JSC_DOMVALUE(Element); + } + case Node_base::TEXT_NODE: { + TO_JSC_DOMVALUE(Text); + } + case Node_base::CDATA_SECTION_NODE: { + TO_JSC_DOMVALUE(CDATASection); + } + case Node_base::DOCUMENT_NODE: { + TO_JSC_DOMVALUE(Document); + } + default: { + TO_JSC_DOMVALUE(Node); + } + } +} + +void JSCDataModel::assign(const std::string& location, const Data& data) { + + // flags on attribute are ignored? + if (location.compare("_sessionid") == 0) // test 322 + ERROR_EXECUTION_THROW("Cannot assign to _sessionId"); + if (location.compare("_name") == 0) + ERROR_EXECUTION_THROW("Cannot assign to _name"); + if (location.compare("_ioprocessors") == 0) // test 326 + ERROR_EXECUTION_THROW("Cannot assign to _ioprocessors"); + if (location.compare("_invokers") == 0) + ERROR_EXECUTION_THROW("Cannot assign to _invokers"); + if (location.compare("_event") == 0) + ERROR_EXECUTION_THROW("Cannot assign to _event"); + + JSValueRef exception = NULL; + if (data.node) { + JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(location.c_str()), getNodeAsValue(data.node), 0, &exception); + } else { + evalAsValue(location + " = " + Data::toJSON(data)); + } + + /** + * test157: We need to evluate, as this will not throw for 'continue' = Var[5] in + */ +// JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(location.c_str()), getDataAsValue(data), 0, &exception); + + if (exception) + handleException(exception); +} + void JSCDataModel::assign(const Element<std::string>& assignElem, const Node<std::string>& node, const std::string& content) { std::string key; - JSValueRef exception = NULL; if (HAS_ATTR(assignElem, "id")) { key = ATTR(assignElem, "id"); } else if (HAS_ATTR(assignElem, "location")) { @@ -638,63 +687,30 @@ void JSCDataModel::assign(const Element<std::string>& assignElem, if (key.length() == 0) { ERROR_EXECUTION_THROW("Assign element has neither id nor location"); } - // flags on attribute are ignored? - if (key.compare("_sessionid") == 0) // test 322 - ERROR_EXECUTION_THROW("Cannot assign to _sessionId"); - if (key.compare("_name") == 0) - ERROR_EXECUTION_THROW("Cannot assign to _name"); - if (key.compare("_ioprocessors") == 0) // test 326 - ERROR_EXECUTION_THROW("Cannot assign to _ioprocessors"); - if (key.compare("_invokers") == 0) - ERROR_EXECUTION_THROW("Cannot assign to _invokers"); - if (key.compare("_event") == 0) - ERROR_EXECUTION_THROW("Cannot assign to _event"); if (HAS_ATTR(assignElem, "expr")) { - evalAsValue(key + " = " + ATTR(assignElem, "expr")); + assign(key, Data(ATTR(assignElem, "expr"), Data::INTERPRETED)); } else if (node) { - JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(key.c_str()), getNodeAsValue(node), 0, &exception); - if (exception) - handleException(exception); + Data d; + d.node = node; + assign(key, d); } else if (content.size() > 0) { try { - evalAsValue(key + " = " + content); - } catch (...) { - evalAsValue(key + " = " + "\"" + InterpreterImpl::spaceNormalize(content) + "\""); + Data d = Data::fromJSON(content); + if (d.empty()) + throw Event(); + assign(key, Data(d, Data::INTERPRETED)); + } catch (Event e) { + assign(key, Data("\"" + InterpreterImpl::spaceNormalize(content) + "\"", Data::INTERPRETED)); } } else { + JSValueRef exception = NULL; JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(key.c_str()), JSValueMakeUndefined(_ctx), 0, &exception); if (exception) handleException(exception); } } -JSValueRef JSCDataModel::getNodeAsValue(const Node<std::string>& node) { - switch (node.getNodeType()) { - case Node_base::ELEMENT_NODE: { - TO_JSC_DOMVALUE(Element); - } - case Node_base::TEXT_NODE: { - TO_JSC_DOMVALUE(Text); - } - case Node_base::CDATA_SECTION_NODE: { - TO_JSC_DOMVALUE(CDATASection); - } - case Node_base::DOCUMENT_NODE: { - TO_JSC_DOMVALUE(Document); - } - default: { - TO_JSC_DOMVALUE(Node); - } - } -} - -void JSCDataModel::assign(const std::string& location, const Data& data) { - std::stringstream ssJSON; - ssJSON << data; - evalAsValue(location + " = " + ssJSON.str()); -} - void JSCDataModel::init(const Element<std::string>& dataElem, const Node<std::string>& node, const std::string& content) { @@ -708,7 +724,9 @@ void JSCDataModel::init(const Element<std::string>& dataElem, } else if (HAS_ATTR(dataElem, "location")) { key = ATTR(dataElem, "location"); } - evalAsValue(key + " = undefined", true); + if (key.size() > 0) { + evalAsValue(key + " = undefined", true); + } throw e; } } |