summaryrefslogtreecommitdiffstats
path: root/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore
diff options
context:
space:
mode:
authorStefan Radomski <github@mintwerk.de>2017-05-10 20:48:14 (GMT)
committerStefan Radomski <github@mintwerk.de>2017-05-10 20:48:14 (GMT)
commita33a96fd7aee6d53f663102c56236e91d77f53a7 (patch)
tree3a27a07f8f4eeddd233b2bb8ed9a5c43c36077c6 /src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore
parent5083ea697c263a507341c98c5dadbb23953bd4fb (diff)
downloaduscxml-a33a96fd7aee6d53f663102c56236e91d77f53a7.zip
uscxml-a33a96fd7aee6d53f663102c56236e91d77f53a7.tar.gz
uscxml-a33a96fd7aee6d53f663102c56236e91d77f53a7.tar.bz2
Fixed issue 114
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore')
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp38
-rw-r--r--src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h1
2 files changed, 21 insertions, 18 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
index 1358f8b..124da6e 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp
@@ -246,9 +246,13 @@ JSValueRef JSCNodeListGetPropertyCallback(JSContextRef context, JSObjectRef obje
std::shared_ptr<DataModelImpl> JSCDataModel::create(DataModelCallbacks* callbacks) {
std::shared_ptr<JSCDataModel> dm(new JSCDataModel());
-
- dm->_ctx = JSGlobalContextCreate(NULL);
dm->_callbacks = callbacks;
+ dm->setup();
+ return dm;
+}
+
+void JSCDataModel::setup() {
+ _ctx = JSGlobalContextCreate(NULL);
#ifndef NO_XERCESC
JSObjectRef exports;
@@ -260,50 +264,48 @@ std::shared_ptr<DataModelImpl> JSCDataModel::create(DataModelCallbacks* callback
// not thread safe!
{
std::lock_guard<std::mutex> lock(_initMutex);
- JSCDOM_initialize(dm->_ctx, &exports);
+ JSCDOM_initialize(_ctx, &exports);
}
#endif
// introduce global functions as objects for private data
JSClassRef jsInClassRef = JSClassCreate(&jsInClassDef);
- JSObjectRef jsIn = JSObjectMake(dm->_ctx, jsInClassRef, dm.get());
+ JSObjectRef jsIn = JSObjectMake(_ctx, jsInClassRef, this);
JSStringRef inName = JSStringCreateWithUTF8CString("In");
- JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), inName, jsIn, kJSPropertyAttributeNone, NULL);
+ JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), inName, jsIn, kJSPropertyAttributeNone, NULL);
JSStringRelease(inName);
JSClassRef jsPrintClassRef = JSClassCreate(&jsPrintClassDef);
- JSObjectRef jsPrint = JSObjectMake(dm->_ctx, jsPrintClassRef, dm.get());
+ JSObjectRef jsPrint = JSObjectMake(_ctx, jsPrintClassRef, this);
JSStringRef printName = JSStringCreateWithUTF8CString("print");
- JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), printName, jsPrint, kJSPropertyAttributeNone, NULL);
+ JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), printName, jsPrint, kJSPropertyAttributeNone, NULL);
JSStringRelease(printName);
JSClassRef jsInvokerClassRef = JSClassCreate(&jsInvokersClassDef);
- JSObjectRef jsInvoker = JSObjectMake(dm->_ctx, jsInvokerClassRef, dm.get());
+ JSObjectRef jsInvoker = JSObjectMake(_ctx, jsInvokerClassRef, this);
JSStringRef invokerName = JSStringCreateWithUTF8CString("_invokers");
- JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), invokerName, jsInvoker, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
+ JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), invokerName, jsInvoker, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
JSStringRelease(invokerName);
JSClassRef jsIOProcClassRef = JSClassCreate(&jsIOProcessorsClassDef);
- JSObjectRef jsIOProc = JSObjectMake(dm->_ctx, jsIOProcClassRef, dm.get());
+ JSObjectRef jsIOProc = JSObjectMake(_ctx, jsIOProcClassRef, this);
JSStringRef ioProcName = JSStringCreateWithUTF8CString("_ioprocessors");
- JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), ioProcName, jsIOProc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
+ JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), ioProcName, jsIOProc, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
JSStringRelease(ioProcName);
JSStringRef nameName = JSStringCreateWithUTF8CString("_name");
- JSStringRef name = JSStringCreateWithUTF8CString(dm->_callbacks->getName().c_str());
- JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), nameName, JSValueMakeString(dm->_ctx, name), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
+ JSStringRef name = JSStringCreateWithUTF8CString(_callbacks->getName().c_str());
+ JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), nameName, JSValueMakeString(_ctx, name), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
JSStringRelease(nameName);
JSStringRelease(name);
JSStringRef sessionIdName = JSStringCreateWithUTF8CString("_sessionid");
- JSStringRef sessionId = JSStringCreateWithUTF8CString(dm->_callbacks->getSessionId().c_str());
- JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), sessionIdName, JSValueMakeString(dm->_ctx, sessionId), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
+ JSStringRef sessionId = JSStringCreateWithUTF8CString(_callbacks->getSessionId().c_str());
+ JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), sessionIdName, JSValueMakeString(_ctx, sessionId), kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);
JSStringRelease(sessionIdName);
JSStringRelease(sessionId);
- dm->evalAsValue("_x = {};");
-
- return dm;
+ evalAsValue("_x = {};");
}
void JSCDataModel::setEvent(const Event& event) {
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h
index 5a0e830..977385c 100644
--- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h
+++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h
@@ -89,6 +89,7 @@ public:
const std::map<std::string, std::string>& attr = std::map<std::string, std::string>());
protected:
+ virtual void setup();
static JSClassDefinition jsInClassDef;
static JSValueRef jsIn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception);