diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-22 14:02:03 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2014-04-22 14:02:03 (GMT) |
commit | 1fb6bcf30f954e426f2d3002d14887574fb941dd (patch) | |
tree | 08cff7f2b879c50efe79e3c04d255075522af862 /src/uscxml/plugins/datamodel/ecmascript | |
parent | 71c334bf4e35559496feac3f3cf00b72ceb88812 (diff) | |
download | uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.zip uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.tar.gz uscxml-1fb6bcf30f954e426f2d3002d14887574fb941dd.tar.bz2 |
Major refactoring
- Moved tests
- Changes to promela datamodel
- Implemented Trie
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript')
12 files changed, 189 insertions, 164 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp index 2a84c24..40bd464 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.cpp @@ -23,6 +23,7 @@ namespace Arabica { namespace DOM { JSCDOM::JSCDOM() { + nsInfo = NULL; xpath = NULL; storage = NULL; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h index 5a6bfea..cb196ff 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h @@ -49,6 +49,7 @@ public: JSCDOM(); virtual ~JSCDOM(); uscxml::Storage* storage; + uscxml::NameSpaceInfo* nsInfo; Arabica::XPath::XPath<std::string>* xpath; }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index dece4f2..2e8e6d2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -125,8 +125,9 @@ boost::shared_ptr<DataModelImpl> JSCDataModel::create(InterpreterImpl* interpret dm->_dom = new JSCDOM(); dm->_dom->xpath = new XPath<std::string>(); - dm->_dom->xpath->setNamespaceContext(interpreter->getNSContext()); + dm->_dom->xpath->setNamespaceContext(*interpreter->getNameSpaceInfo().nsContext); dm->_dom->storage = new Storage(URL::getResourceDir() + PATH_SEPERATOR + interpreter->getName() + ".storage"); + dm->_dom->nsInfo = new NameSpaceInfo(interpreter->getNameSpaceInfo()); // introduce global functions as objects for private data JSClassRef jsInClassRef = JSClassCreate(&jsInClassDef); @@ -632,16 +633,16 @@ std::string JSCDataModel::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++) { + exprIter != expressions.end(); + exprIter++) { exprSS << conjunction << "(" << *exprIter << ")"; conjunction = " && "; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp index 1527884..795ad70 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp @@ -55,8 +55,8 @@ JSStaticFunction JSCDocument::staticFunctions[] = { { "createEntityReference", createEntityReferenceCallback, kJSPropertyAttributeDontDelete }, { "getElementsByTagName", getElementsByTagNameCallback, kJSPropertyAttributeDontDelete }, { "importNode", importNodeCallback, kJSPropertyAttributeDontDelete }, - { "createElementNS", createElementNSCallback, kJSPropertyAttributeDontDelete }, - { "createAttributeNS", createAttributeNSCallback, kJSPropertyAttributeDontDelete }, + { "createElementNS", createElementNSCustomCallback, kJSPropertyAttributeDontDelete }, + { "createAttributeNS", createAttributeNSCustomCallback, kJSPropertyAttributeDontDelete }, { "getElementsByTagNameNS", getElementsByTagNameNSCallback, kJSPropertyAttributeDontDelete }, { "getElementById", getElementByIdCallback, kJSPropertyAttributeDontDelete }, { "evaluate", evaluateCustomCallback, kJSPropertyAttributeDontDelete }, @@ -459,94 +459,6 @@ JSValueRef JSCDocument::importNodeCallback(JSContextRef ctx, JSObjectRef functio return JSValueMakeUndefined(ctx); } -JSValueRef JSCDocument::createElementNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - - struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - - if (false) { - } else if (argumentCount == 2 && - JSValueIsString(ctx, arguments[0]) && - JSValueIsString(ctx, arguments[1])) { - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); - - JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); - char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; - JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); - std::string localQualifiedName(localQualifiedNameBuffer); - JSStringRelease(stringReflocalQualifiedName); - free(localQualifiedNameBuffer); - - - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(localNamespaceURI, localQualifiedName)); - JSClassRef retClass = JSCElement::getTmpl(); - - struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - - return retObj; - - } - - JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createElementNS"); - *exception = JSValueMakeString(ctx, exceptionString); - JSStringRelease(exceptionString); - return JSValueMakeUndefined(ctx); -} - -JSValueRef JSCDocument::createAttributeNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - - struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - - if (false) { - } else if (argumentCount == 2 && - JSValueIsString(ctx, arguments[0]) && - JSValueIsString(ctx, arguments[1])) { - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); - - JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); - char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; - JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); - std::string localQualifiedName(localQualifiedNameBuffer); - JSStringRelease(stringReflocalQualifiedName); - free(localQualifiedNameBuffer); - - - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(localNamespaceURI, localQualifiedName)); - JSClassRef retClass = JSCAttr::getTmpl(); - - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - - return retObj; - - } - - JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createAttributeNS"); - *exception = JSValueMakeString(ctx, exceptionString); - JSStringRelease(exceptionString); - return JSValueMakeUndefined(ctx); -} - JSValueRef JSCDocument::getElementsByTagNameNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h index f6b167e..1b300fb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h @@ -48,8 +48,8 @@ public: static JSValueRef createEntityReferenceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef getElementsByTagNameCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef importNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); - static JSValueRef createElementNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); - static JSValueRef createAttributeNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSValueRef createElementNSCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSValueRef createAttributeNSCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef getElementsByTagNameNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef getElementByIdCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef evaluateCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp index 6f15c72..c6ee022 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp @@ -18,6 +18,8 @@ */ #include "JSCDocument.h" +#include "JSCElement.h" +#include "JSCAttr.h" #include "JSCStorage.h" #include "JSCXPathResult.h" #include "JSCNode.h" @@ -141,5 +143,99 @@ JSValueRef JSCDocument::evaluateCustomCallback(JSContextRef ctx, JSObjectRef fun #endif } +JSValueRef JSCDocument::createElementNSCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + + struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); + + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); + char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); + free(localQualifiedNameBuffer); + + + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(localNamespaceURI, localQualifiedName)); + if (privData->dom->nsInfo->nsToPrefix.find(localNamespaceURI) != privData->dom->nsInfo->nsToPrefix.end()) + retVal->setPrefix(privData->dom->nsInfo->nsToPrefix[localNamespaceURI]); + + JSClassRef retClass = JSCElement::getTmpl(); + + struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + + return retObj; + + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createElementNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} + +JSValueRef JSCDocument::createAttributeNSCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + + struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); + + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); + char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); + free(localQualifiedNameBuffer); + + + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(localNamespaceURI, localQualifiedName)); + if (privData->dom->nsInfo->nsToPrefix.find(localNamespaceURI) != privData->dom->nsInfo->nsToPrefix.end()) + retVal->setPrefix(privData->dom->nsInfo->nsToPrefix[localNamespaceURI]); + + JSClassRef retClass = JSCAttr::getTmpl(); + + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + + return retObj; + + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createAttributeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} + } }
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp index b09d670..87e7966 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp @@ -23,9 +23,14 @@ namespace Arabica { namespace DOM { V8DOM::V8DOM() { + nsInfo = NULL; + xpath = NULL; + storage = NULL; } V8DOM::~V8DOM() { + if (nsInfo) + delete(nsInfo); if (xpath) delete(xpath); if (storage) diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h index a10b980..dd0c18a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h @@ -70,6 +70,7 @@ public: // return v8::External::New(pointer); } + uscxml::NameSpaceInfo* nsInfo; Arabica::XPath::XPath<std::string>* xpath; uscxml::Storage* storage; }; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 1341d09..b18e039 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -94,9 +94,9 @@ boost::shared_ptr<DataModelImpl> V8DataModel::create(InterpreterImpl* interprete dm->_dom = new V8DOM(); // dom->interpreter = interpreter; dm->_dom->xpath = new XPath<std::string>(); - dm->_dom->xpath->setNamespaceContext(interpreter->getNSContext()); + dm->_dom->xpath->setNamespaceContext(*interpreter->getNameSpaceInfo().nsContext); dm->_dom->storage = new Storage(URL::getResourceDir() + PATH_SEPERATOR + interpreter->getName() + ".storage"); - + dm->_dom->nsInfo = new NameSpaceInfo(interpreter->getNameSpaceInfo()); // see http://stackoverflow.com/questions/3171418/v8-functiontemplate-class-instance // some free functions @@ -661,7 +661,7 @@ 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()); @@ -669,8 +669,8 @@ std::string V8DataModel::andExpressions(std::list<std::string> expressions) { exprSS << "("; std::string conjunction = ""; for (std::list<std::string>::const_iterator exprIter = expressions.begin(); - exprIter != expressions.end(); - exprIter++) { + exprIter != expressions.end(); + exprIter++) { exprSS << conjunction << "(" << *exprIter << ")"; conjunction = " && "; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp index 1e4a2dc..226cd26 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp @@ -368,64 +368,6 @@ v8::Handle<v8::Value> V8Document::importNodeCallback(const v8::Arguments& args) return v8::Undefined(); } -v8::Handle<v8::Value> V8Document::createElementNSCallback(const v8::Arguments& args) { - - v8::Local<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - if (false) { - } else if (args.Length() == 2 && - args[0]->IsString() && - args[1]->IsString()) { - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; - - } - throw V8Exception("Parameter mismatch while calling createElementNS"); - return v8::Undefined(); -} - -v8::Handle<v8::Value> V8Document::createAttributeNSCallback(const v8::Arguments& args) { - - v8::Local<v8::Object> self = args.Holder(); - struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - if (false) { - } else if (args.Length() == 2 && - args[0]->IsString() && - args[1]->IsString()) { - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; - - } - throw V8Exception("Parameter mismatch while calling createAttributeNS"); - return v8::Undefined(); -} - v8::Handle<v8::Value> V8Document::getElementsByTagNameNSCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h index cebc5d1..373d18a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h @@ -51,8 +51,8 @@ public: static v8::Handle<v8::Value> createEntityReferenceCallback(const v8::Arguments&); static v8::Handle<v8::Value> getElementsByTagNameCallback(const v8::Arguments&); static v8::Handle<v8::Value> importNodeCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createElementNSCallback(const v8::Arguments&); - static v8::Handle<v8::Value> createAttributeNSCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createElementNSCustomCallback(const v8::Arguments&); + static v8::Handle<v8::Value> createAttributeNSCustomCallback(const v8::Arguments&); static v8::Handle<v8::Value> getElementsByTagNameNSCallback(const v8::Arguments&); static v8::Handle<v8::Value> getElementByIdCallback(const v8::Arguments&); static v8::Handle<v8::Value> evaluateCustomCallback(const v8::Arguments&); @@ -105,9 +105,9 @@ public: prototype->Set(v8::String::NewSymbol("importNode"), v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("createElementNS"), - v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + v8::FunctionTemplate::New(V8Document::createElementNSCustomCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("createAttributeNS"), - v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + v8::FunctionTemplate::New(V8Document::createAttributeNSCustomCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("getElementById"), diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp index 2e4d7c4..8659ccd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp @@ -20,6 +20,8 @@ #include "V8Document.h" #include "V8XPathResult.h" #include "V8Storage.h" +#include "V8Attr.h" +#include "V8Element.h" namespace Arabica { namespace DOM { @@ -81,5 +83,69 @@ v8::Handle<v8::Value> V8Document::evaluateCustomCallback(const v8::Arguments& ar } +v8::Handle<v8::Value> V8Document::createElementNSCustomCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); + if (privData->dom->nsInfo->nsToPrefix.find(*localNamespaceURI) != privData->dom->nsInfo->nsToPrefix.end()) + retVal->setPrefix(privData->dom->nsInfo->nsToPrefix[*localNamespaceURI]); + + v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + + } + throw V8Exception("Parameter mismatch while calling createElementNS"); + return v8::Undefined(); +} + +v8::Handle<v8::Value> V8Document::createAttributeNSCustomCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); + if (privData->dom->nsInfo->nsToPrefix.find(*localNamespaceURI) != privData->dom->nsInfo->nsToPrefix.end()) + retVal->setPrefix(privData->dom->nsInfo->nsToPrefix[*localNamespaceURI]); + + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + throw V8Exception("Parameter mismatch while calling createAttributeNS"); + return v8::Undefined(); +} + } }
\ No newline at end of file |