diff options
author | Stefan Radomski <github@mintwerk.de> | 2017-01-18 17:15:46 (GMT) |
---|---|---|
committer | Stefan Radomski <github@mintwerk.de> | 2017-01-18 17:15:46 (GMT) |
commit | fc78cfdc4d1f5bba8dbd6a412f23651e185cb191 (patch) | |
tree | dd32929c07e6c19250f2e8fde1e73712bab0c6fb /src/uscxml/plugins/datamodel/ecmascript/v8 | |
parent | 01ee860a88b5c8cf25fb7dcc145662d2c27f3ebe (diff) | |
download | uscxml-fc78cfdc4d1f5bba8dbd6a412f23651e185cb191.zip uscxml-fc78cfdc4d1f5bba8dbd6a412f23651e185cb191.tar.gz uscxml-fc78cfdc4d1f5bba8dbd6a412f23651e185cb191.tar.bz2 |
Worked on passing even more IRP tests
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/v8')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp | 46 | ||||
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h | 10 |
2 files changed, 25 insertions, 31 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 283372d..61eb815 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -408,7 +408,7 @@ void V8DataModel::setEvent(const Event& event) { } } if (!data.empty()) { -// std::cout << Data::toJSON(eventCopy.data); +// std::cout << Data::toJSON(data); eventObj->Set(v8::String::NewSymbol("data"), getDataAsValue(data)); // set data part of _event } else { // test 343 / test 488 @@ -436,7 +436,10 @@ Data V8DataModel::getAsData(const std::string& content) { (trimmed[0] == '\'' && trimmed[trimmed.length() - 1] == '\''))) { d = Data(trimmed.substr(1, trimmed.length() - 2), Data::VERBATIM); } else { - d = Data(trimmed, Data::INTERPRETED); + // test558, test562 + ERROR_EXECUTION(e, "Given content cannot be interpreted as data"); + e.data.compound["literal"] = Data(trimmed, Data::VERBATIM); + throw e; } } return d; @@ -631,12 +634,22 @@ void V8DataModel::jsIn(const v8::FunctionCallbackInfo<v8::Value>& info) { } bool V8DataModel::isValidSyntax(const std::string& expr) { + v8::Locker locker(_isolate); + v8::Isolate::Scope isoScope(_isolate); + v8::HandleScope scope(_isolate); + + v8::Local<v8::Context> ctx = v8::Local<v8::Context>::New(_isolate, _context); + v8::Context::Scope contextScope(ctx); // segfaults at newinstance without! + v8::TryCatch tryCatch; v8::Local<v8::String> source = v8::String::New(expr.c_str()); - v8::Local<v8::Script> script = v8::Script::Compile(source); + if (tryCatch.HasCaught() || source.IsEmpty()) { + return false; + } - if (script.IsEmpty() || tryCatch.HasCaught()) { + v8::Local<v8::Script> script = v8::Script::Compile(source); + if (tryCatch.HasCaught() || script.IsEmpty()) { return false; } @@ -726,7 +739,7 @@ bool V8DataModel::evalAsBool(const std::string& expr) { } -void V8DataModel::assign(const std::string& location, const Data& data) { +void V8DataModel::assign(const std::string& location, const Data& data, const std::map<std::string, std::string>& attr) { v8::Locker locker(_isolate); v8::Isolate::Scope isoScope(_isolate); @@ -754,8 +767,7 @@ void V8DataModel::assign(const std::string& location, const Data& data) { } } -void V8DataModel::init(const std::string& location, - const Data& data) { +void V8DataModel::init(const std::string& location, const Data& data, const std::map<std::string, std::string>& attr) { v8::Locker locker(_isolate); v8::Isolate::Scope isoScope(_isolate); v8::HandleScope scope(_isolate); @@ -774,26 +786,6 @@ void V8DataModel::init(const std::string& location, } } -std::string V8DataModel::andExpressions(std::list<std::string> expressions) { - if (expressions.size() == 0) - return ""; - - if (expressions.size() == 1) - return *(expressions.begin()); - - std::ostringstream exprSS; - exprSS << "("; - std::string conjunction = ""; - for (std::list<std::string>::const_iterator exprIter = expressions.begin(); - exprIter != expressions.end(); - exprIter++) { - exprSS << conjunction << "(" << *exprIter << ")"; - conjunction = " && "; - } - exprSS << ")"; - return exprSS.str(); -} - v8::Local<v8::Value> V8DataModel::evalAsValue(const std::string& expr, bool dontThrow) { // v8::Locker locker(_isolate); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index 3b4d776..a9dbca1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -73,10 +73,12 @@ public: virtual bool isDeclared(const std::string& expr); - virtual void assign(const std::string& location, const Data& data); - virtual void init(const std::string& location, const Data& data); - - virtual std::string andExpressions(std::list<std::string>); + virtual void assign(const std::string& location, + const Data& data, + const std::map<std::string, std::string>& attr = std::map<std::string, std::string>()); + virtual void init(const std::string& location, + const Data& data, + const std::map<std::string, std::string>& attr = std::map<std::string, std::string>()); protected: |