diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp | 31 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h | 1 |
2 files changed, 31 insertions, 1 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 551b590..9a71ab0 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -19,6 +19,7 @@ #include "uscxml/Common.h" #include "uscxml/config.h" + #include "JSCDataModel.h" #include "JSCDOM.h" #include "dom/JSCDocument.h" @@ -43,6 +44,12 @@ #include "uscxml/DOMUtils.h" #include <glog/logging.h> +#ifdef BUILD_PROFILING +#define TIME_BLOCK Measurement msm(&timer); +#else +#define TIME_BLOCK (0); +#endif + #ifdef BUILD_AS_PLUGINS #include <Pluma/Connector.hpp> #endif @@ -86,6 +93,7 @@ JSCDataModel::~JSCDataModel() { } void JSCDataModel::addExtension(DataModelExtension* ext) { + TIME_BLOCK if (_extensions.find(ext) != _extensions.end()) return; @@ -191,7 +199,8 @@ JSClassDefinition JSCDataModel::jsInvokersClassDef = { 0, 0, "invokers", 0, 0, 0 boost::shared_ptr<DataModelImpl> JSCDataModel::create(InterpreterInfo* interpreter) { boost::shared_ptr<JSCDataModel> dm = boost::shared_ptr<JSCDataModel>(new JSCDataModel()); - + TIME_BLOCK + dm->_ctx = JSGlobalContextCreate(NULL); dm->_interpreter = interpreter; @@ -275,6 +284,7 @@ void JSCDataModel::popContext() { } void JSCDataModel::setEvent(const Event& event) { + TIME_BLOCK JSCSCXMLEvent::JSCSCXMLEventPrivate* privData = new JSCSCXMLEvent::JSCSCXMLEventPrivate(); privData->nativeObj = new Event(event); privData->dom = _dom; @@ -357,12 +367,14 @@ void JSCDataModel::setEvent(const Event& event) { } Data JSCDataModel::getStringAsData(const std::string& content) { + TIME_BLOCK JSValueRef result = evalAsValue(content); Data data = getValueAsData(result); return data; } JSValueRef JSCDataModel::getDataAsValue(const Data& data) { + TIME_BLOCK JSValueRef exception = NULL; if (data.node) { @@ -428,6 +440,7 @@ JSValueRef JSCDataModel::getDataAsValue(const Data& data) { } Data JSCDataModel::getValueAsData(const JSValueRef value) { + TIME_BLOCK Data data; JSValueRef exception = NULL; switch(JSValueGetType(_ctx, value)) { @@ -516,10 +529,12 @@ Data JSCDataModel::getValueAsData(const JSValueRef value) { } bool JSCDataModel::validate(const std::string& location, const std::string& schema) { + TIME_BLOCK return true; } uint32_t JSCDataModel::getLength(const std::string& expr) { + TIME_BLOCK JSValueRef result; result = evalAsValue("(" + expr + ").length"); @@ -540,6 +555,7 @@ void JSCDataModel::setForeach(const std::string& item, const std::string& array, const std::string& index, uint32_t iteration) { + TIME_BLOCK if (!isDeclared(item)) { assign(item, Data()); } @@ -556,11 +572,13 @@ void JSCDataModel::setForeach(const std::string& item, } bool JSCDataModel::isLocation(const std::string& expr) { + TIME_BLOCK // location needs to be LHS and ++ is only valid for LHS return isValidSyntax(expr + "++"); } bool JSCDataModel::isValidSyntax(const std::string& expr) { + TIME_BLOCK JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; bool valid = JSCheckScriptSyntax(_ctx, scriptJS, NULL, 0, &exception); @@ -573,6 +591,7 @@ bool JSCDataModel::isValidSyntax(const std::string& expr) { } bool JSCDataModel::isDeclared(const std::string& expr) { + TIME_BLOCK JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; JSValueRef result = JSEvaluateScript(_ctx, scriptJS, NULL, NULL, 0, &exception); @@ -586,15 +605,18 @@ bool JSCDataModel::isDeclared(const std::string& expr) { void JSCDataModel::eval(const Element<std::string>& scriptElem, const std::string& expr) { + TIME_BLOCK evalAsValue(expr); } bool JSCDataModel::evalAsBool(const Arabica::DOM::Element<std::string>& node, const std::string& expr) { + TIME_BLOCK JSValueRef result = evalAsValue(expr); return JSValueToBoolean(_ctx, result); } std::string JSCDataModel::evalAsString(const std::string& expr) { + TIME_BLOCK JSValueRef result = evalAsValue(expr); JSValueRef exception = NULL; @@ -613,6 +635,7 @@ std::string JSCDataModel::evalAsString(const std::string& expr) { } JSValueRef JSCDataModel::evalAsValue(const std::string& expr, bool dontThrow) { + TIME_BLOCK JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; JSValueRef result = JSEvaluateScript(_ctx, scriptJS, NULL, NULL, 0, &exception); @@ -627,6 +650,7 @@ JSValueRef JSCDataModel::evalAsValue(const std::string& expr, bool dontThrow) { void JSCDataModel::assign(const Element<std::string>& assignElem, const Node<std::string>& node, const std::string& content) { + TIME_BLOCK std::string key; JSValueRef exception = NULL; if (HAS_ATTR(assignElem, "id")) { @@ -669,6 +693,7 @@ void JSCDataModel::assign(const Element<std::string>& assignElem, } JSValueRef JSCDataModel::getNodeAsValue(const Node<std::string>& node) { + TIME_BLOCK switch (node.getNodeType()) { case Node_base::ELEMENT_NODE: { TO_JSC_DOMVALUE(Element); @@ -689,6 +714,7 @@ JSValueRef JSCDataModel::getNodeAsValue(const Node<std::string>& node) { } void JSCDataModel::assign(const std::string& location, const Data& data) { + TIME_BLOCK std::stringstream ssJSON; ssJSON << data; evalAsValue(location + " = " + ssJSON.str()); @@ -697,6 +723,7 @@ void JSCDataModel::assign(const std::string& location, const Data& data) { void JSCDataModel::init(const Element<std::string>& dataElem, const Node<std::string>& node, const std::string& content) { + TIME_BLOCK try { assign(dataElem, node, content); } catch (Event e) { @@ -713,6 +740,7 @@ void JSCDataModel::init(const Element<std::string>& dataElem, } void JSCDataModel::init(const std::string& location, const Data& data) { + TIME_BLOCK try { assign(location, data); } catch (Event e) { @@ -723,6 +751,7 @@ void JSCDataModel::init(const std::string& location, const Data& data) { } std::string JSCDataModel::andExpressions(std::list<std::string> expressions) { + TIME_BLOCK if (expressions.size() == 0) return ""; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 944d185..9bc39d6 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -120,6 +120,7 @@ protected: Event _event; JSGlobalContextRef _ctx; + }; #ifdef BUILD_AS_PLUGINS |