diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/v8')
28 files changed, 248 insertions, 41 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp new file mode 100644 index 0000000..be20bee --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.cpp @@ -0,0 +1,17 @@ +#include "V8DOM.h" + +namespace Arabica { +namespace DOM { + +V8DOM::V8DOM() { +} + +V8DOM::~V8DOM() { + if (xpath) + delete(xpath); + if (storage) + delete(storage); +} + +} +}
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h index 10528e8..43b98ce 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h @@ -4,6 +4,7 @@ #include "uscxml/Interpreter.h" #include <v8.h> #include <XPath/XPath.hpp> +#include "../Storage.h" #define V8_DESTRUCTOR(type) \ static void jsDestructor(v8::Persistent<v8::Value> object, void* data) { \ @@ -30,7 +31,7 @@ namespace DOM { class V8DOM { public: V8DOM(); - virtual ~V8DOM() { }; + virtual ~V8DOM(); template <typename T> static T* toClassPtr(v8::Local<v8::Value> data) { @@ -48,6 +49,7 @@ public: } Arabica::XPath::XPath<std::string>* xpath; + uscxml::Storage* storage; }; class V8Exception : public std::runtime_error { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index b394171..017b2eb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -1,6 +1,7 @@ #include "uscxml/Common.h" +#include "uscxml/config.h" #include "V8DataModel.h" -#include "dom/V8DOM.h" +#include "V8DOM.h" #include "dom/V8Document.h" #include "dom/V8Node.h" #include "dom/V8SCXMLEvent.h" @@ -29,6 +30,15 @@ V8DataModel::V8DataModel() { // _contexts.push_back(v8::Context::New()); } +V8DataModel::~V8DataModel() { + while(_contexts.size() > 0) { + _contexts.back().Dispose(); + _contexts.pop_back(); + } + if (_dom) + delete _dom; +} + boost::shared_ptr<DataModelImpl> V8DataModel::create(InterpreterImpl* interpreter) { boost::shared_ptr<V8DataModel> dm = boost::shared_ptr<V8DataModel>(new V8DataModel()); dm->_interpreter = interpreter; @@ -39,6 +49,7 @@ boost::shared_ptr<DataModelImpl> V8DataModel::create(InterpreterImpl* interprete // dom->interpreter = interpreter; dm->_dom->xpath = new XPath<std::string>(); dm->_dom->xpath->setNamespaceContext(interpreter->getNSContext()); + dm->_dom->storage = new Storage(URL::getResourceDir() + PATH_SEPERATOR + interpreter->getName() + ".storage"); // see http://stackoverflow.com/questions/3171418/v8-functiontemplate-class-instance @@ -111,13 +122,6 @@ v8::Handle<v8::Value> V8DataModel::getIOProcessors(v8::Local<v8::String> propert return dataModel->_ioProcessors; } -V8DataModel::~V8DataModel() { - while(_contexts.size() > 0) { - _contexts.back().Dispose(); - _contexts.pop_back(); - } -} - void V8DataModel::pushContext() { _contexts.push_back(_contexts.back().New(_contexts.back())); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h index da69c4f..9d17093 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.h @@ -4,7 +4,7 @@ #include "uscxml/Interpreter.h" #include <list> #include <v8.h> -#include "dom/V8DOM.h" +#include "V8DOM.h" #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h index 9829023..f216215 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h index 3b95b84..5f936d2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Text.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h index 6c51ca7..d5846e4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h index 074da74..a19462d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8CharacterData.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp deleted file mode 100644 index 4562fe3..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp +++ /dev/null @@ -1,11 +0,0 @@ -#include "V8DOM.h" - -namespace Arabica { -namespace DOM { - -V8DOM::V8DOM() { - -} - -} -}
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h index 5c58e22..58d6f9a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h @@ -24,7 +24,7 @@ #include <string> #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h index 2db4b54..a023ac9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { @@ -60,6 +60,7 @@ public: static v8::Handle<v8::Value> doctypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); static v8::Handle<v8::Value> implementationAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); static v8::Handle<v8::Value> documentElementAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> localStorageCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -80,6 +81,8 @@ public: v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("localStorage"), V8Document::localStorageCustomAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); prototype->Set(v8::String::NewSymbol("createElement"), v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp index 1e0b700..cd7f942 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp @@ -1,9 +1,28 @@ #include "V8Document.h" #include "V8XPathResult.h" +#include "V8Storage.h" namespace Arabica { namespace DOM { +v8::Handle<v8::Value> V8Document::localStorageCustomAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + + v8::Handle<v8::Function> retCtor = V8Storage::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + V8Storage::V8StoragePrivate* retPrivData = new V8Storage::V8StoragePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = privData->dom->storage; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8XPathResult::jsDestructor); + return retObj; + +} + v8::Handle<v8::Value> V8Document::evaluateCustomCallback(const v8::Arguments& args) { if (args.Length() < 1) diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h index c669b05..641aacd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h index 59c2607..d1551a3 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h index e5a52bf..7263ab1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h index 6e85585..88a284b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h index 86dd61b..cc25213 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h index be89037..d918186 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h @@ -24,7 +24,7 @@ #include <string> #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h index 2ea8ddc..b4fbad4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h @@ -24,7 +24,7 @@ #include <string> #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h index c454e65..341c63a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h @@ -24,7 +24,7 @@ #include <string> #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h index 97b5d4f..b95f4c1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h @@ -24,7 +24,7 @@ #include <string> #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h index 0745728..51f324b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h index 56b61eb..d31d5d9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8Node.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h index 8b71ed7..3c5e6ee 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.h @@ -24,7 +24,7 @@ #include <string> #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp new file mode 100644 index 0000000..d9ab828 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp @@ -0,0 +1,83 @@ +#include "V8Storage.h" + +namespace Arabica { +namespace DOM { + +v8::Persistent<v8::FunctionTemplate> V8Storage::Tmpl; + + +v8::Handle<v8::Value> V8Storage::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); + + return v8::Integer::New(privData->nativeObj->getLength()); +} +v8::Handle<v8::Value> V8Storage::keyCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in key"); + + v8::Local<v8::Object> self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + + std::string retVal = privData->nativeObj->key(localIndex); + + return v8::String::New(retVal.c_str()); +} + +v8::Handle<v8::Value> V8Storage::getItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getItem"); + + v8::Local<v8::Object> self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localKey(args[0]); + + std::string retVal = privData->nativeObj->getItem(*localKey); + + return v8::String::New(retVal.c_str()); +} + +v8::Handle<v8::Value> V8Storage::setItemCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in setItem"); + + v8::Local<v8::Object> self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localKey(args[0]); + v8::String::AsciiValue localValue(args[1]); + + privData->nativeObj->setItem(*localKey, *localValue); + + return v8::Undefined(); +} + +v8::Handle<v8::Value> V8Storage::removeItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeItem"); + + v8::Local<v8::Object> self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); + v8::String::AsciiValue localKey(args[0]); + + privData->nativeObj->removeItem(*localKey); + + return v8::Undefined(); +} + +v8::Handle<v8::Value> V8Storage::clearCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); + + privData->nativeObj->clear(); + + return v8::Undefined(); +} + +bool V8Storage::hasInstance(v8::Handle<v8::Value> value) { + return getTmpl()->HasInstance(value); +} + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.h new file mode 100644 index 0000000..4d6692d --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.h @@ -0,0 +1,90 @@ +/* + This file is part of the Wrapper open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Storage_h +#define V8Storage_h + +#include <string> +#include "DOM/Node.hpp" +#include "string" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" +#include <v8.h> + +namespace Arabica { +namespace DOM { + +class V8Storage { +public: + struct V8StoragePrivate { + V8DOM* dom; + uscxml::Storage* nativeObj; + }; + + V8_DESTRUCTOR_KEEP_WRAPPED(V8StoragePrivate); + static bool hasInstance(v8::Handle<v8::Value>); + + static v8::Handle<v8::Value> keyCallback(const v8::Arguments&); + static v8::Handle<v8::Value> getItemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> setItemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> removeItemCallback(const v8::Arguments&); + static v8::Handle<v8::Value> clearCallback(const v8::Arguments&); + + static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + + static v8::Persistent<v8::FunctionTemplate> Tmpl; + static v8::Handle<v8::FunctionTemplate> getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Storage")); + tmpl->ReadOnlyPrototype(); + + v8::Local<v8::ObjectTemplate> instance = tmpl->InstanceTemplate(); + v8::Local<v8::ObjectTemplate> prototype = tmpl->PrototypeTemplate(); + (void)prototype; // surpress unused warnings + + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("length"), V8Storage::lengthAttrGetter, 0, + v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + + prototype->Set(v8::String::NewSymbol("key"), + v8::FunctionTemplate::New(V8Storage::keyCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getItem"), + v8::FunctionTemplate::New(V8Storage::getItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setItem"), + v8::FunctionTemplate::New(V8Storage::setItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeItem"), + v8::FunctionTemplate::New(V8Storage::removeItemCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("clear"), + v8::FunctionTemplate::New(V8Storage::clearCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + + + Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8Storage_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h index 61b92fb..0604984 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h @@ -25,7 +25,7 @@ #include "DOM/Node.hpp" #include "V8CharacterData.h" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h index f6a2d10..b613b93 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h @@ -24,7 +24,7 @@ #include <string> #include "DOM/Node.hpp" #include "string" -#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> namespace Arabica { |