diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript')
4 files changed, 33 insertions, 2 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 6dc8c26..73a3744 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -482,6 +482,19 @@ void JSCDataModel::setForeach(const std::string& item, } } +bool JSCDataModel::isLocation(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 82882f0..fea2234 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -49,6 +49,7 @@ public: } virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(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 8b222f7..a995ec2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -457,6 +457,22 @@ bool V8DataModel::validate(const std::string& location, const std::string& schem return true; } +bool V8DataModel::isLocation(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::Script> script = v8::Script::Compile(source); + + if (script.IsEmpty() || tryCatch.HasCaught()) { + return false; + } + + return true; +} + uint32_t V8DataModel::getLength(const std::string& expr) { v8::Locker locker; v8::HandleScope handleScope; @@ -468,7 +484,7 @@ uint32_t V8DataModel::getLength(const std::string& expr) { Event exceptionEvent; exceptionEvent.name = "error.execution"; - exceptionEvent.data.compound["exception"] = Data("'" + expr + "' does not evaluate to an array.", Data::VERBATIM); + exceptionEvent.data.compound["cause"] = Data("'" + expr + "' does not evaluate to an array.", Data::VERBATIM); throw(exceptionEvent); } @@ -720,7 +736,7 @@ void V8DataModel::throwExceptionEvent(const v8::TryCatch& tryCatch) { exceptionEvent.eventType = Event::PLATFORM; std::string exceptionString(*v8::String::AsciiValue(tryCatch.Exception())); - exceptionEvent.data.compound["exception"] = Data(exceptionString, Data::VERBATIM);; + exceptionEvent.data.compound["cause"] = Data(exceptionString, Data::VERBATIM);; v8::Handle<v8::Message> message = tryCatch.Message(); if (!message.IsEmpty()) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index 5bfca93..6df1951 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -53,6 +53,7 @@ public: virtual void setEvent(const Event& event); virtual bool validate(const std::string& location, const std::string& schema); + virtual bool isLocation(const std::string& expr); virtual uint32_t getLength(const std::string& expr); virtual void setForeach(const std::string& item, |