diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp | 111 |
1 files changed, 83 insertions, 28 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp index 04bfcbe..6b7c077 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp @@ -1,30 +1,85 @@ -#include "V8XPathResult.h" #include "V8NodeSet.h" +#include "V8XPathResult.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent<v8::FunctionTemplate> V8XPathResult::Tmpl; + + + v8::Handle<v8::Value> V8XPathResult::numberValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + + return v8::Number::New(privData->arabicaThis->asNumber()); + } + + v8::Handle<v8::Value> V8XPathResult::stringValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->asString().c_str()); + } + + v8::Handle<v8::Value> V8XPathResult::booleanValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { + v8::Local<v8::Object> self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + + return v8::Boolean::New(privData->arabicaThis->asBool()); + } + v8::Handle<v8::Value> V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + + Arabica::XPath::NodeSet<std::string>* retVal = new Arabica::XPath::NodeSet<std::string>(privData->arabicaThis->asNodeSet()); + v8::Handle<v8::Function> retCtor = V8NodeSet::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8NodeSet::V8NodeSetPrivate* retPrivData = new V8NodeSet::V8NodeSetPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8NodeSet::jsDestructor); + return retObj; + + } + + v8::Handle<v8::Value> V8XPathResult::asBoolCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + + bool retVal = privData->arabicaThis->asBool(); + + return v8::Boolean::New(retVal); + } + + v8::Handle<v8::Value> V8XPathResult::asStringCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + + std::string retVal = privData->arabicaThis->asString(); + + return v8::String::New(retVal.c_str()); + } + + v8::Handle<v8::Value> V8XPathResult::asNumberCallback(const v8::Arguments& args) { + + v8::Local<v8::Object> self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + + double retVal = privData->arabicaThis->asNumber(); + + return v8::Number::New(retVal); + } + + bool V8XPathResult::hasInstance(v8::Handle<v8::Value> value) { + return getTmpl()->HasInstance(value); + } -namespace uscxml { - -using namespace Arabica::DOM; -using namespace Arabica::XPath; - -v8::Persistent<v8::FunctionTemplate> V8XPathResult::Tmpl; - -v8::Handle<v8::Value> V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { - - v8::Local<v8::Object> self = args.Holder(); - XPathValue<std::string>* xpathValue = V8DOM::toClassPtr<XPathValue<std::string> >(self->GetInternalField(0)); - V8DOM* dom = V8DOM::toClassPtr<V8DOM>(self->GetInternalField(1)); (void)dom; - - v8::Handle<v8::Function> nodeSetCtor = V8NodeSet::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> nodeSetObj = v8::Persistent<v8::Object>::New(nodeSetCtor->NewInstance()); - - Arabica::XPath::NodeSet<std::string>* nodeSet = new Arabica::XPath::NodeSet<std::string>(xpathValue->asNodeSet()); - - nodeSetObj->SetInternalField(0, V8DOM::toExternal(nodeSet)); - nodeSetObj->SetInternalField(1, self->GetInternalField(1)); - - nodeSetObj.MakeWeak(0, V8NodeSet::jsDestructor); - return nodeSetObj; - -} - -}
\ No newline at end of file +} +} |