summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/ecmascript/v8
diff options
context:
space:
mode:
authorStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-04-01 22:28:07 (GMT)
committerStefan Radomski <radomski@tk.informatik.tu-darmstadt.de>2013-04-01 22:28:07 (GMT)
commitf19be97dea6fd8da994392d6fa7de5b3f0d9bf3e (patch)
tree4583fe7d5fa44f128ce92284429b6ee9f2c631bf /src/uscxml/plugins/datamodel/ecmascript/v8
parentc912952fb5e8072770262c64932c1d8cf2027cf0 (diff)
downloaduscxml-f19be97dea6fd8da994392d6fa7de5b3f0d9bf3e.zip
uscxml-f19be97dea6fd8da994392d6fa7de5b3f0d9bf3e.tar.gz
uscxml-f19be97dea6fd8da994392d6fa7de5b3f0d9bf3e.tar.bz2
Still more bugfixes and added w3c tests
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/v8')
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp46
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h4
2 files changed, 29 insertions, 21 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp
index 0663db4..affd641 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp
@@ -57,14 +57,13 @@ boost::shared_ptr<DataModelImpl> V8DataModel::create(Interpreter* interpreter) {
docObj->SetInternalField(0, Arabica::DOM::V8DOM::toExternal(privData));
context->Global()->Set(v8::String::New("document"), docObj);
+ context->Global()->Set(v8::String::New("_sessionid"), v8::String::New(interpreter->getSessionId().c_str()), v8::ReadOnly);
+ context->Global()->Set(v8::String::New("_name"), v8::String::New(interpreter->getName().c_str()), v8::ReadOnly);
+ context->Global()->Set(v8::String::New("_ioprocessors"), v8::Object::New(), v8::ReadOnly);
dm->_contexts.push_back(context);
// instantiate objects - we have to have a context for that!
-
- dm->setName(interpreter->getName());
- dm->setSessionId(interpreter->getSessionId());
- dm->eval("_ioprocessors = {};");
dm->eval("_invokers = {};");
dm->eval("_x = {};");
@@ -72,17 +71,12 @@ boost::shared_ptr<DataModelImpl> V8DataModel::create(Interpreter* interpreter) {
}
void V8DataModel::registerIOProcessor(const std::string& name, const IOProcessor& ioprocessor) {
- assign("_ioprocessors['" + name + "']", ioprocessor.getDataModelVariables());
-}
-
-void V8DataModel::setSessionId(const std::string& sessionId) {
- _sessionId = sessionId;
- assign("_sessionId", "'" + sessionId + "'");
-}
-
-void V8DataModel::setName(const std::string& name) {
- _name = name;
- assign("_name", "'" + name + "'");
+ v8::Locker locker;
+ v8::HandleScope handleScope;
+ v8::Context::Scope contextScope(_contexts.front());
+ v8::Handle<v8::Object> global = _contexts.front()->Global();
+ v8::Handle<v8::Object> ioProcessors = global->Get(v8::String::New("_ioprocessors"))->ToObject();
+ ioProcessors->Set(v8::String::New(name.c_str()),getDataAsValue(ioprocessor.getDataModelVariables()));
}
V8DataModel::~V8DataModel() {
@@ -285,12 +279,28 @@ void V8DataModel::eval(const std::string& expr) {
evalAsValue(expr);
}
-bool V8DataModel::isDefined(const std::string& expr) {
+bool V8DataModel::isDeclared(const std::string& expr) {
+ /**
+ * Undeclared variables can be checked by trying to access them and catching
+ * a reference error.
+ */
+
v8::Locker locker;
v8::HandleScope handleScope;
v8::Context::Scope contextScope(_contexts.back());
- v8::Handle<v8::Value> result = evalAsValue(expr);
- return !result->IsUndefined();
+
+ v8::TryCatch tryCatch;
+ v8::Handle<v8::String> source = v8::String::New(expr.c_str());
+ v8::Handle<v8::Script> script = v8::Script::Compile(source);
+
+ v8::Handle<v8::Value> result;
+ if (!script.IsEmpty())
+ result = script->Run();
+
+ if (result.IsEmpty())
+ return false;
+
+ return true;
}
bool V8DataModel::evalAsBool(const std::string& expr) {
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h
index a9db5ca..441297d 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h
+++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h
@@ -31,8 +31,6 @@ public:
}
virtual void initialize();
- virtual void setSessionId(const std::string& sessionId);
- virtual void setName(const std::string& name);
virtual void setEvent(const Event& event);
virtual void registerIOProcessor(const std::string& name, const IOProcessor& ioprocessor);
@@ -49,7 +47,7 @@ public:
virtual Data getStringAsData(const std::string& content);
virtual Data getValueAsData(const v8::Handle<v8::Value>& value);
- virtual bool isDefined(const std::string& expr);
+ virtual bool isDeclared(const std::string& expr);
virtual std::string evalAsString(const std::string& expr);
virtual bool evalAsBool(const std::string& expr);