diff options
Diffstat (limited to 'src/uscxml/plugins')
7 files changed, 27 insertions, 5 deletions
diff --git a/src/uscxml/plugins/DataModel.h b/src/uscxml/plugins/DataModel.h index b1eafb9..be68ea2 100644 --- a/src/uscxml/plugins/DataModel.h +++ b/src/uscxml/plugins/DataModel.h @@ -42,6 +42,9 @@ public: virtual bool validate(const std::string& location, const std::string& schema) = 0; virtual bool isLocation(const std::string& expr) = 0; + virtual bool isValidSyntax(const std::string& expr) { + return true; // overwrite when datamodel supports it + } virtual void setEvent(const Event& event) = 0; virtual Data getStringAsData(const std::string& content) = 0; @@ -125,6 +128,9 @@ public: virtual bool isLocation(const std::string& expr) { return _impl->isLocation(expr); } + virtual bool isValidSyntax(const std::string& expr) { + return _impl->isValidSyntax(expr); + } virtual void setEvent(const Event& event) { return _impl->setEvent(event); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 3a9cb27..b8ec2cc 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -485,18 +485,21 @@ void JSCDataModel::setForeach(const std::string& item, bool JSCDataModel::isLocation(const std::string& expr) { // location needs to be RHS and ++ is only valid for RHS - JSStringRef scriptJS = JSStringCreateWithUTF8CString((expr + "++").c_str()); + return isValidSyntax(expr + "++"); +} + +bool JSCDataModel::isValidSyntax(const std::string& expr) { + JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; bool valid = JSCheckScriptSyntax(_ctx, scriptJS, NULL, 0, &exception); JSStringRelease(scriptJS); - + if (exception || !valid) { return false; } return true; } - - + bool JSCDataModel::isDeclared(const std::string& expr) { JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index 6792130..10d5999 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -50,6 +50,8 @@ public: virtual bool validate(const std::string& location, const std::string& schema); virtual bool isLocation(const std::string& expr); + virtual bool isValidSyntax(const std::string& expr); + virtual void setEvent(const Event& event); virtual Data getStringAsData(const std::string& content); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 2a27d47..7b0b8e9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -458,12 +458,17 @@ bool V8DataModel::validate(const std::string& location, const std::string& schem } bool V8DataModel::isLocation(const std::string& expr) { + // location needs to be RHS and ++ is only valid for RHS + return isValidSyntax(expr + "++"); +} + +bool V8DataModel::isValidSyntax(const std::string& expr) { v8::Locker locker; v8::HandleScope handleScope; v8::TryCatch tryCatch; v8::Context::Scope contextScope(_contexts.back()); - v8::Handle<v8::String> source = v8::String::New((expr + "++").c_str()); + v8::Handle<v8::String> source = v8::String::New(expr.c_str()); v8::Handle<v8::Script> script = v8::Script::Compile(source); if (script.IsEmpty() || tryCatch.HasCaught()) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index a9717a2..e67a5ab 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -54,6 +54,7 @@ public: virtual bool validate(const std::string& location, const std::string& schema); virtual bool isLocation(const std::string& expr); + virtual bool isValidSyntax(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp index dd3a0b4..02b97c3 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.cpp @@ -336,6 +336,10 @@ bool LuaDataModel::isLocation(const std::string& expr) { return true; } +bool LuaDataModel::isValidSyntax(const std::string& expr) { + return true; +} + uint32_t LuaDataModel::getLength(const std::string& expr) { // we need the result of the expression on the lua stack -> has to "return"! std::string trimmedExpr = boost::trim_copy(expr); diff --git a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h index 69b8d57..39990c6 100644 --- a/src/uscxml/plugins/datamodel/lua/LuaDataModel.h +++ b/src/uscxml/plugins/datamodel/lua/LuaDataModel.h @@ -57,6 +57,7 @@ public: virtual bool validate(const std::string& location, const std::string& schema); virtual bool isLocation(const std::string& expr); + virtual bool isValidSyntax(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, |