From 0192f99e8ad75bab4041cca11d94d32503cc9666 Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Fri, 21 Jun 2013 21:31:25 +0200 Subject: More complete JSC ECMA datamodel --- CMakeLists.txt | 13 +- contrib/dom/scripts/CodeGeneratorArabicaJSC.pm | 37 ++- src/bindings/swig/php/uscxmlNativePHP.php | 2 +- src/uscxml/Factory.h | 2 +- .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 309 +++++++++++++++++++-- .../ecmascript/JavaScriptCore/JSCDataModel.h | 12 +- .../ecmascript/JavaScriptCore/dom/JSCAttr.cpp | 3 +- .../JavaScriptCore/dom/JSCCDATASection.cpp | 1 + .../JavaScriptCore/dom/JSCCharacterData.cpp | 1 + .../ecmascript/JavaScriptCore/dom/JSCComment.cpp | 1 + .../JavaScriptCore/dom/JSCDOMImplementation.cpp | 1 + .../ecmascript/JavaScriptCore/dom/JSCDocument.cpp | 1 + .../JavaScriptCore/dom/JSCDocumentCustom.cpp | 43 +++ .../JavaScriptCore/dom/JSCDocumentFragment.cpp | 1 + .../JavaScriptCore/dom/JSCDocumentType.cpp | 1 + .../ecmascript/JavaScriptCore/dom/JSCElement.cpp | 1 + .../ecmascript/JavaScriptCore/dom/JSCEntity.cpp | 1 + .../JavaScriptCore/dom/JSCEntityReference.cpp | 1 + .../JavaScriptCore/dom/JSCNamedNodeMap.cpp | 1 + .../ecmascript/JavaScriptCore/dom/JSCNode.cpp | 49 ++++ .../JavaScriptCore/dom/JSCNodeCustom.cpp | 34 +++ .../ecmascript/JavaScriptCore/dom/JSCNodeList.cpp | 1 + .../JavaScriptCore/dom/JSCNodeListCustom.cpp | 53 ++++ .../ecmascript/JavaScriptCore/dom/JSCNodeSet.cpp | 3 +- .../JavaScriptCore/dom/JSCNodeSetCustom.cpp | 54 ++++ .../ecmascript/JavaScriptCore/dom/JSCNotation.cpp | 1 + .../dom/JSCProcessingInstruction.cpp | 1 + .../JavaScriptCore/dom/JSCSCXMLEvent.cpp | 13 + .../JavaScriptCore/dom/JSCSCXMLEventCustom.cpp | 40 +++ .../ecmascript/JavaScriptCore/dom/JSCText.cpp | 1 + .../JavaScriptCore/dom/JSCXPathResult.cpp | 3 +- .../JavaScriptCore/dom/JSCXPathResultCustom.cpp | 29 ++ .../datamodel/ecmascript/v8/V8DataModel.cpp | 2 +- .../datamodel/ecmascript/v8/dom/V8Document.h.old | 104 ------- 34 files changed, 678 insertions(+), 142 deletions(-) create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp delete mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old diff --git a/CMakeLists.txt b/CMakeLists.txt index 70d8a88..938e8ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -278,7 +278,7 @@ set(CMAKE_COMPILER_STRING "${CMAKE_CXX_COMPILER_ID} ${CMAKE_CXX_COMPILER_VERSION # see http://www.mail-archive.com/cmake@cmake.org/msg23240.html if (APPLE) # add_definitions("-D_DARWIN_UNLIMITED_SELECT") - set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") +# set(CMAKE_OSX_ARCHITECTURES "x86_64;i386") # support leopard and above set(CMAKE_OSX_DEPLOYMENT_TARGET 10.6) foreach(FLAGS CMAKE_C_FLAGS CMAKE_CXX_FLAGS CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS) @@ -454,13 +454,14 @@ if (APPLE OR IOS) list (APPEND USCXML_CORE_LIBS ${JSC_LIBRARY}) endif() set(JSC_FOUND ON) +else() + find_package(V8) + if (V8_FOUND) + include_directories(${V8_INCLUDE_DIR}) + list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY}) + endif() endif() -find_package(V8) -if (V8_FOUND) - include_directories(${V8_INCLUDE_DIR}) - list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY}) -endif() set(CMAKE_FIND_LIBRARY_SUFFIXES ${CMAKE_FIND_LIBRARY_SUFFIXES_SHARED}) find_package(SWI) diff --git a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm index 390bee0..2de92a9 100644 --- a/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm +++ b/contrib/dom/scripts/CodeGeneratorArabicaJSC.pm @@ -208,12 +208,12 @@ END push(@headerContent, "\n static JSValueRef ${getter}(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception);"); } - # if ($extensions->{'CustomIndexedGetter'}) { - # push(@headerContent, "\n static JSValueRef indexedPropertyCustomGetter(uint32_t, const JSC::AccessorInfo&);"); - # } - # if ($extensions->{'CustomIndexedSetter'}) { - # push(@headerContent, "\n static JSValueRef indexedPropertyCustomSetter(uint32_t, JSC::Local, const JSC::AccessorInfo&);"); - # } + if ($extensions->{'CustomIndexedGetter'}) { + push(@headerContent, "\n static JSValueRef indexedPropertyCustomGetter(uint32_t, const JSC::AccessorInfo&);"); + } + if ($extensions->{'CustomIndexedSetter'}) { + push(@headerContent, "\n static JSValueRef indexedPropertyCustomSetter(uint32_t, JSC::Local, const JSC::AccessorInfo&);"); + } push(@headerContent, "\n"); push(@headerContent, <nativeObj->${wrapperGetter});\n"); } elsif($JSCType eq "Boolean") { - push(@implContent, "\n return JSValueMakeNumber(ctx, privData->nativeObj->${wrapperGetter});\n"); + push(@implContent, "\n return JSValueMakeBoolean(ctx, privData->nativeObj->${wrapperGetter});\n"); } } push(@implContent, " }\n\n"); @@ -378,6 +378,28 @@ END } } } + foreach my $constant (@{$interface->constants}) { + my $name = $constant->name; + my $value = $constant->value; + my $getter = "${name}ConstGetter"; + push(@implContent, " JSValueRef JSC${interfaceName}::${getter}(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) {"); + my $JSCType = IdlToJSCType($constant->type); + if ($JSCType eq "String") { + push(@implContent, + "\n JSStringRef jscString = JSStringCreateWithUTF8CString(" . $constant->value . ");". + "\n return JSValueMakeString(ctx, jscString);\n"); + } elsif($JSCType eq "Number") { + push(@implContent, "\n return JSValueMakeNumber(ctx, " . $constant->value . ");\n"); + } elsif($JSCType eq "Boolean") { + push(@implContent, "\n return JSValueMakeBoolean(ctx, " . $constant->value . ");\n"); + } + push(@implContent, < @@ -23,27 +24,46 @@ bool connect(pluma::Host& host) { JSCDataModel::JSCDataModel() { } +// functions need to be objects to hold private data in JSC +JSClassDefinition JSCDataModel::jsInClassDef = { 0, 0, "In", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsIn, 0, 0, 0 }; +JSClassDefinition JSCDataModel::jsPrintClassDef = { 0, 0, "print", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, jsPrint, 0, 0, 0 }; + boost::shared_ptr JSCDataModel::create(InterpreterImpl* interpreter) { boost::shared_ptr dm = boost::shared_ptr(new JSCDataModel()); dm->_ctx = JSGlobalContextCreate(NULL); dm->_interpreter = interpreter; - Arabica::DOM::JSCDOM* dom = new Arabica::DOM::JSCDOM(); - // dom->interpreter = interpreter; - dom->xpath = new Arabica::XPath::XPath(); - dom->xpath->setNamespaceContext(interpreter->getNSContext()); + dm->_dom = new Arabica::DOM::JSCDOM(); + dm->_dom->xpath = new Arabica::XPath::XPath(); + dm->_dom->xpath->setNamespaceContext(interpreter->getNSContext()); + + // introduce global functions as objects for private data + JSClassRef jsInClassRef = JSClassCreate(&jsInClassDef); + JSObjectRef jsIn = JSObjectMake(dm->_ctx, jsInClassRef, dm.get()); + JSStringRef inName = JSStringCreateWithUTF8CString("In"); + JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), inName, jsIn, kJSPropertyAttributeNone, NULL); + JSStringRelease(inName); + + JSClassRef jsPrintClassRef = JSClassCreate(&jsPrintClassDef); + JSObjectRef jsPrint = JSObjectMake(dm->_ctx, jsPrintClassRef, dm.get()); + JSStringRef printName = JSStringCreateWithUTF8CString("print"); + JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), printName, jsPrint, kJSPropertyAttributeNone, NULL); + JSStringRelease(inName); dm->eval("_ioprocessors = {};"); Arabica::DOM::JSCDocument::JSCDocumentPrivate* privData = new Arabica::DOM::JSCDocument::JSCDocumentPrivate(); privData->nativeObj = new Arabica::DOM::Document(interpreter->getDocument()); - privData->dom = dom; + privData->dom = dm->_dom; JSObjectRef documentObject = JSObjectMake(dm->_ctx, Arabica::DOM::JSCDocument::getTmpl(), privData); JSObjectRef globalObject = JSContextGetGlobalObject(dm->_ctx); JSObjectSetProperty(dm->_ctx, globalObject, JSStringCreateWithUTF8CString("document"), documentObject, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL); + dm->eval("_invokers = {};"); + dm->eval("_x = {};"); + return dm; } @@ -58,7 +78,76 @@ void JSCDataModel::popContext() { } void JSCDataModel::setEvent(const Event& event) { - LOG(ERROR) << "setEvent not implemented in JSC"; + Arabica::DOM::JSCSCXMLEvent::JSCSCXMLEventPrivate* privData = new Arabica::DOM::JSCSCXMLEvent::JSCSCXMLEventPrivate(); + privData->nativeObj = new Event(event); + privData->dom = _dom; + + JSObjectRef eventObj = JSObjectMake(_ctx, Arabica::DOM::JSCSCXMLEvent::getTmpl(), privData); + JSObjectRef globalObject = JSContextGetGlobalObject(_ctx); + + JSValueRef exception = NULL; + + if (event.dom) { + JSStringRef propName = JSStringCreateWithUTF8CString("data"); + JSObjectSetProperty(_ctx, eventObj, propName, getDocumentAsValue(event.dom), 0, &exception); + JSStringRelease(propName); + if (exception) + handleException(exception); + + } else if (event.content.length() > 0) { + // _event.data is a string or JSON + Data json = Data::fromJSON(event.content); + if (json) { + JSStringRef propName = JSStringCreateWithUTF8CString("data"); + JSObjectSetProperty(_ctx, eventObj, propName, getDataAsValue(json), 0, &exception); + JSStringRelease(propName); + if (exception) + handleException(exception); + } else { + JSStringRef propName = JSStringCreateWithUTF8CString("data"); + JSStringRef contentStr = JSStringCreateWithUTF8CString(Interpreter::spaceNormalize(event.content).c_str()); + JSObjectSetProperty(_ctx, eventObj, propName, JSValueMakeString(_ctx, contentStr), 0, &exception); + JSStringRelease(propName); + JSStringRelease(contentStr); + + if (exception) + handleException(exception); + } + } else { + // _event.data is KVP + Event eventCopy(event); + if (!eventCopy.params.empty()) { + Event::params_t::iterator paramIter = eventCopy.params.begin(); + while(paramIter != eventCopy.params.end()) { + eventCopy.data.compound[paramIter->first] = Data(paramIter->second, Data::VERBATIM); + paramIter++; + } + } + if (!eventCopy.namelist.empty()) { + Event::namelist_t::iterator nameListIter = eventCopy.namelist.begin(); + while(nameListIter != eventCopy.namelist.end()) { + eventCopy.data.compound[nameListIter->first] = Data(nameListIter->second, Data::VERBATIM); + nameListIter++; + } + } + if (eventCopy.data > 0) { + JSStringRef propName = JSStringCreateWithUTF8CString("data"); + JSObjectSetProperty(_ctx, eventObj, propName, getDataAsValue(eventCopy.data), 0, &exception); + JSStringRelease(propName); + if (exception) + handleException(exception); + } else { + // test 343 / test 488 + JSStringRef propName = JSStringCreateWithUTF8CString("data"); + JSObjectSetProperty(_ctx, eventObj, propName, JSValueMakeUndefined(_ctx), 0, &exception); + JSStringRelease(propName); + if (exception) + handleException(exception); + } + } + + JSObjectSetProperty(_ctx, globalObject, JSStringCreateWithUTF8CString("_event"), eventObj, kJSPropertyAttributeDontDelete, NULL); + } Data JSCDataModel::getStringAsData(const std::string& content) { @@ -67,6 +156,45 @@ Data JSCDataModel::getStringAsData(const std::string& content) { return data; } +JSValueRef JSCDataModel::getDataAsValue(const Data& data) { + JSValueRef exception = NULL; + + if (data.compound.size() > 0) { + JSObjectRef value = JSObjectMake(_ctx, 0, 0); + std::map::const_iterator compoundIter = data.compound.begin(); + while(compoundIter != data.compound.end()) { + JSStringRef key = JSStringCreateWithUTF8CString(compoundIter->first.c_str()); + JSObjectSetProperty(_ctx, value, key, getDataAsValue(compoundIter->second), 0, &exception); + JSStringRelease(key); + if (exception) + handleException(exception); + compoundIter++; + } + return value; + } + if (data.array.size() > 0) { + JSValueRef elements[data.array.size()]; + std::list::const_iterator arrayIter = data.array.begin(); + uint32_t index = 0; + while(arrayIter != data.array.end()) { + elements[index++] = getDataAsValue(*arrayIter); + arrayIter++; + } + JSObjectRef value = JSObjectMakeArray(_ctx, data.array.size(), elements, &exception); + if (exception) + handleException(exception); + return value; + } + if (data.type == Data::VERBATIM) { + JSStringRef stringRef = JSStringCreateWithUTF8CString(data.atom.c_str()); + JSValueRef value = JSValueMakeString(_ctx, stringRef); + JSStringRelease(stringRef); + return value; + } else { + return evalAsValue(data.atom); + } +} + Data JSCDataModel::getValueAsData(const JSValueRef value) { Data data; JSValueRef exception = NULL; @@ -92,7 +220,7 @@ Data JSCDataModel::getValueAsData(const JSValueRef value) { char* buf = (char*)malloc(JSStringGetMaximumUTF8CStringSize(stringValue)); JSStringGetUTF8CString(stringValue, buf, sizeof(buf)); - data.atom = std::string(buf, sizeof(buf)); + data.atom = std::string(buf); free(buf); break; } @@ -108,7 +236,7 @@ Data JSCDataModel::getValueAsData(const JSValueRef value) { JSStringRef stringValue = JSPropertyNameArrayGetNameAtIndex(properties, i); char* buf = (char*)malloc(JSStringGetMaximumUTF8CStringSize(stringValue)); JSStringGetUTF8CString(stringValue, buf, sizeof(buf)); - std::string property(buf, sizeof(buf)); + std::string property(buf); if (!isNumeric(property.c_str(), 10)) isArray = false; propertySet.insert(property); @@ -143,8 +271,8 @@ bool JSCDataModel::validate(const std::string& location, const std::string& sche } uint32_t JSCDataModel::getLength(const std::string& expr) { - LOG(ERROR) << "I am not sure whether getLength() works :("; - JSValueRef result = evalAsValue(expr); +// LOG(ERROR) << "I am not sure whether getLength() works :("; + JSValueRef result = evalAsValue("(" + expr + ").length"); JSValueRef exception = NULL; double length = JSValueToNumber(_ctx, result, &exception); if (exception) @@ -153,6 +281,29 @@ uint32_t JSCDataModel::getLength(const std::string& expr) { return (uint32_t)length; } +void JSCDataModel::setForeach(const std::string& item, + const std::string& array, + const std::string& index, + uint32_t iteration) { + if (!isDeclared(item)) { + assign(item, Data()); + } + // assign array element to item + std::stringstream ss; + ss << array << "[" << iteration << "]"; + assign(item, ss.str()); + if (index.length() > 0) { + // assign iteration element to index + std::stringstream ss; + ss << iteration; + assign(index, ss.str()); + } +} + +bool JSCDataModel::isDeclared(const std::string& expr) { + return true; +} + void JSCDataModel::eval(const std::string& expr) { evalAsValue(expr); } @@ -165,48 +316,170 @@ bool JSCDataModel::evalAsBool(const std::string& expr) { std::string JSCDataModel::evalAsString(const std::string& expr) { JSValueRef result = evalAsValue(expr); JSValueRef exception = NULL; + JSStringRef stringValue = JSValueToStringCopy( _ctx, result, &exception); if (exception) handleException(exception); - char* data = (char*)malloc(JSStringGetMaximumUTF8CStringSize(stringValue)); - JSStringGetUTF8CString(stringValue, data, sizeof(data)); - std::string retString(data, sizeof(data)); + size_t maxSize = JSStringGetMaximumUTF8CStringSize(stringValue); + char data[maxSize]; + JSStringGetUTF8CString(stringValue, data, maxSize); + std::string retString(data); JSStringRelease(stringValue); - free(data); + return retString; } -JSValueRef JSCDataModel::evalAsValue(const std::string& expr) { +JSValueRef JSCDataModel::evalAsValue(const std::string& expr, bool dontThrow) { JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); JSValueRef exception = NULL; JSValueRef result = JSEvaluateScript(_ctx, scriptJS, NULL, NULL, 0, &exception); - if (exception) + JSStringRelease(scriptJS); + + if (exception && !dontThrow) handleException(exception); - JSStringRelease(scriptJS); return result; } void JSCDataModel::assign(const Arabica::DOM::Element& assignElem, const Arabica::DOM::Document& doc, const std::string& content) { + std::string key; + JSValueRef exception = NULL; + if (HAS_ATTR(assignElem, "id")) { + key = ATTR(assignElem, "id"); + } else if (HAS_ATTR(assignElem, "location")) { + key = ATTR(assignElem, "location"); + } + if (key.length() == 0) + throw Event("error.execution", Event::PLATFORM); + + if (HAS_ATTR(assignElem, "expr")) { + evalAsValue(key + " = " + ATTR(assignElem, "expr")); + } else if (doc) { + JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(key.c_str()), getDocumentAsValue(doc), 0, &exception); + if (exception) + handleException(exception); + } else if (content.size() > 0) { + try { + evalAsValue(key + " = " + content); + } catch (...) { + evalAsValue(key + " = " + "\"" + Interpreter::spaceNormalize(content) + "\""); + } + } else { + JSObjectSetProperty(_ctx, JSContextGetGlobalObject(_ctx), JSStringCreateWithUTF8CString(key.c_str()), JSValueMakeUndefined(_ctx), 0, &exception); + if (exception) + handleException(exception); + } +} + +JSValueRef JSCDataModel::getDocumentAsValue(const Arabica::DOM::Document& doc) { + + struct Arabica::DOM::JSCDocument::JSCDocumentPrivate* retPrivData = new Arabica::DOM::JSCDocument::JSCDocumentPrivate(); + retPrivData->dom = _dom; + retPrivData->nativeObj = new Arabica::DOM::Document(doc); + + JSObjectRef retObj = JSObjectMake(_ctx, Arabica::DOM::JSCDocument::getTmpl(), retPrivData); + + return retObj; } void JSCDataModel::assign(const std::string& location, const Data& data) { + std::stringstream ssJSON; + ssJSON << data; + evalAsValue(location + " = " + ssJSON.str()); } void JSCDataModel::init(const Arabica::DOM::Element& dataElem, const Arabica::DOM::Document& doc, const std::string& content) { + try { + assign(dataElem, doc, content); + } catch (Event e) { + // test 277 + std::string key; + if (HAS_ATTR(dataElem, "id")) { + key = ATTR(dataElem, "id"); + } else if (HAS_ATTR(dataElem, "location")) { + key = ATTR(dataElem, "location"); + } + evalAsValue(key + " = undefined", true); + throw e; + } } void JSCDataModel::init(const std::string& location, const Data& data) { + try { + assign(location, data); + } catch (Event e) { + // test 277 + evalAsValue(location + " = undefined", true); + throw e; + } } void JSCDataModel::handleException(JSValueRef exception) { - assert(false); + JSStringRef exceptionStringRef = JSValueToStringCopy(_ctx, exception, NULL); + size_t maxSize = JSStringGetMaximumUTF8CStringSize(exceptionStringRef); + char buffer[maxSize]; + JSStringGetUTF8CString(exceptionStringRef, buffer, maxSize); + JSStringRelease(exceptionStringRef); + std::string exceptionMsg(buffer); + + Event exceptionEvent; + exceptionEvent.data.compound["exception"] = Data(exceptionMsg, Data::VERBATIM); + exceptionEvent.name = "error.execution"; + exceptionEvent.type = Event::PLATFORM; + + throw(exceptionEvent); + +} + +JSValueRef JSCDataModel::jsPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(function); + + for (unsigned int i = 0; i < argumentCount; i++) { + if (JSValueIsString(ctx, arguments[i])) { + JSStringRef stringRef = JSValueToStringCopy(ctx, arguments[i], exception); + if (*exception) + INSTANCE->handleException(*exception); + + size_t maxSize = JSStringGetMaximumUTF8CStringSize(stringRef); + char* buffer = new char[maxSize]; + + JSStringGetUTF8CString(stringRef, buffer, maxSize); + std::string msg(buffer); + + std::cout << msg; + } + } + return JSValueMakeUndefined(ctx); +} + +JSValueRef JSCDataModel::jsIn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + JSCDataModel* INSTANCE = (JSCDataModel*)JSObjectGetPrivate(function); + + for (unsigned int i = 0; i < argumentCount; i++) { + if (JSValueIsString(ctx, arguments[i])) { + JSStringRef stringRef = JSValueToStringCopy(ctx, arguments[i], exception); + if (*exception) + INSTANCE->handleException(*exception); + + size_t maxSize = JSStringGetMaximumUTF8CStringSize(stringRef); + char* buffer = new char[maxSize]; + + JSStringGetUTF8CString(stringRef, buffer, maxSize); + std::string stateName(buffer); + if (Interpreter::isMember(INSTANCE->_interpreter->getState(stateName), INSTANCE->_interpreter->getConfiguration())) { + continue; + } + } + return JSValueMakeBoolean(ctx, false); + } + return JSValueMakeBoolean(ctx, true); + } } \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index f99551b..28a313e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -4,6 +4,7 @@ #include "uscxml/Interpreter.h" #include #include +#include "dom/JSCDOM.h" #ifdef BUILD_AS_PLUGINS #include "uscxml/plugins/Plugins.h" @@ -58,8 +59,17 @@ public: virtual void init(const std::string& location, const Data& data); protected: + Arabica::DOM::JSCDOM* _dom; + + static JSClassDefinition jsInClassDef; + static JSValueRef jsIn(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); + static JSClassDefinition jsPrintClassDef; + static JSValueRef jsPrint(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); + + JSValueRef getDocumentAsValue(const Arabica::DOM::Document& doc); + JSValueRef getDataAsValue(const Data& data); Data getValueAsData(const JSValueRef value); - JSValueRef evalAsValue(const std::string& expr); + JSValueRef evalAsValue(const std::string& expr, bool dontThrow = false); void handleException(JSValueRef exception); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp index 62b6e9d..4de0efa 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp @@ -5,6 +5,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCAttr::Tmpl; JSStaticValue JSCAttr::staticValues[] = { { "name", nameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, @@ -29,7 +30,7 @@ JSValueRef JSCAttr::nameAttrGetter(JSContextRef ctx, JSObjectRef object, JSStrin JSValueRef JSCAttr::specifiedAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCAttrPrivate* privData = (struct JSCAttrPrivate*)JSObjectGetPrivate(object); - return JSValueMakeNumber(ctx, privData->nativeObj->getSpecified()); + return JSValueMakeBoolean(ctx, privData->nativeObj->getSpecified()); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.cpp index c735084..4a6fd86 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCCDATASection::Tmpl; JSStaticValue JSCCDATASection::staticValues[] = { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp index 4d55722..46dbdae 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCCharacterData::Tmpl; JSStaticValue JSCCharacterData::staticValues[] = { { "data", dataAttrGetter, dataAttrSetter, kJSPropertyAttributeDontDelete }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.cpp index b9aa25c..344e795 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCComment::Tmpl; JSStaticValue JSCComment::staticValues[] = { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp index e54d260..66c9666 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp @@ -5,6 +5,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCDOMImplementation::Tmpl; JSStaticValue JSCDOMImplementation::staticValues[] = { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp index a3c394e..ed12bb0 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp @@ -15,6 +15,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCDocument::Tmpl; JSStaticValue JSCDocument::staticValues[] = { { "doctype", doctypeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp new file mode 100644 index 0000000..23cc0f9 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp @@ -0,0 +1,43 @@ +#include "JSCDocument.h" +#include "JSCXPathResult.h" + +namespace Arabica { +namespace DOM { + + +JSValueRef JSCDocument::evaluateCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { +#if 0 + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in evaluate"); +// if (!((V8Node::hasInstance(args[1])) && (V8XPathResult::hasInstance(args[3])))) +// throw V8Exception("Parameter mismatch while calling evaluate"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + v8::String::AsciiValue localExpression(args[0]); + + XPath::XPathValue* retVal; + if (args.Length() > 1) { + Arabica::DOM::Node* localContextNode = V8DOM::toClassPtr >(args[1]->ToObject()->GetInternalField(0)); + retVal = new XPath::XPathValue(privData->dom->xpath->evaluate(*localExpression, *localContextNode)); + } else { + retVal = new XPath::XPathValue(privData->dom->xpath->evaluate(*localExpression, *privData->nativeObj)); + } + + v8::Handle retCtor = V8XPathResult::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + V8XPathResult::V8XPathResultPrivate* retPrivData = new V8XPathResult::V8XPathResultPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8XPathResult::jsDestructor); + return retObj; +#endif +} + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.cpp index 77203a7..4bcbb21 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCDocumentFragment::Tmpl; JSStaticValue JSCDocumentFragment::staticValues[] = { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp index 0d9d059..07bfbc1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp @@ -5,6 +5,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCDocumentType::Tmpl; JSStaticValue JSCDocumentType::staticValues[] = { { "name", nameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp index 4b885f0..aa4b242 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp @@ -6,6 +6,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCElement::Tmpl; JSStaticValue JSCElement::staticValues[] = { { "tagName", tagNameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp index 717b5dd..9466f27 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCEntity::Tmpl; JSStaticValue JSCEntity::staticValues[] = { { "publicId", publicIdAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.cpp index a8aac23..ea6c41e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCEntityReference::Tmpl; JSStaticValue JSCEntityReference::staticValues[] = { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp index 9b344d2..aeb0913 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCNamedNodeMap::Tmpl; JSStaticValue JSCNamedNodeMap::staticValues[] = { { "length", lengthAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp index 54e7139..fc7513b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp @@ -5,6 +5,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCNode::Tmpl; JSStaticValue JSCNode::staticValues[] = { { "nodeName", nodeNameAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, @@ -238,6 +239,54 @@ JSValueRef JSCNode::localNameAttrGetter(JSContextRef ctx, JSObjectRef object, JS return JSValueMakeString(ctx, stringRef); } +JSValueRef JSCNode::ELEMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 1); +} + +JSValueRef JSCNode::ATTRIBUTE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 2); +} + +JSValueRef JSCNode::TEXT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 3); +} + +JSValueRef JSCNode::CDATA_SECTION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 4); +} + +JSValueRef JSCNode::ENTITY_REFERENCE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 5); +} + +JSValueRef JSCNode::ENTITY_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 6); +} + +JSValueRef JSCNode::PROCESSING_INSTRUCTION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 7); +} + +JSValueRef JSCNode::COMMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 8); +} + +JSValueRef JSCNode::DOCUMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 9); +} + +JSValueRef JSCNode::DOCUMENT_TYPE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 10); +} + +JSValueRef JSCNode::DOCUMENT_FRAGMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 11); +} + +JSValueRef JSCNode::NOTATION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 12); +} + JSValueRef JSCNode::insertBeforeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { if (argumentCount < 2) { std::string errorMsg = "Wrong number of arguments in insertBefore"; diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp new file mode 100644 index 0000000..82965ad --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeCustom.cpp @@ -0,0 +1,34 @@ +#include "JSCNode.h" +#include "JSCNamedNodeMap.h" + +namespace Arabica { +namespace DOM { + +JSValueRef JSCNode::attributesCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { +#if 0 + v8::Local self = info.Holder(); + struct V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + if (!privData->nativeObj->hasAttributes()) { + return v8::Undefined(); + } + + Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->nativeObj->getAttributes()); + + v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + struct V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); + return arbaicaRetObj; + +#endif +} + + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp index 60c47e8..b6e5723 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCNodeList::Tmpl; JSStaticValue JSCNodeList::staticValues[] = { { "length", lengthAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp new file mode 100644 index 0000000..788c8ec --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp @@ -0,0 +1,53 @@ +#include "JSCNodeList.h" +#include "JSCElement.h" +#include "JSCNode.h" + +namespace Arabica { +namespace DOM { + +#if 0 +v8::Handle V8NodeList::indexedPropertyCustomGetter(uint32_t index, const v8::AccessorInfo &info) { + v8::Local self = info.Holder(); + V8NodeListPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + if (privData->nativeObj->getLength() >= index) { + switch(privData->nativeObj->item(index).getNodeType()) { + case Node_base::ELEMENT_NODE: { + Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->nativeObj->item(index)); + + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::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; + } + default: { + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->item(index)); + + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + } + } + + return v8::Undefined(); + +} +#endif +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.cpp index c2b56c1..3aad9a4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.cpp @@ -3,6 +3,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCNodeSet::Tmpl; JSStaticValue JSCNodeSet::staticValues[] = { { "size", sizeAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, @@ -26,7 +27,7 @@ JSValueRef JSCNodeSet::sizeAttrGetter(JSContextRef ctx, JSObjectRef object, JSSt JSValueRef JSCNodeSet::emptyAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCNodeSetPrivate* privData = (struct JSCNodeSetPrivate*)JSObjectGetPrivate(object); - return JSValueMakeNumber(ctx, privData->nativeObj->empty()); + return JSValueMakeBoolean(ctx, privData->nativeObj->empty()); } JSValueRef JSCNodeSet::toDocumentOrderCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp new file mode 100644 index 0000000..1591310 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp @@ -0,0 +1,54 @@ +#include "JSCNodeSet.h" +#include "JSCElement.h" +#include "JSCNode.h" + +namespace Arabica { +namespace DOM { + +#if 0 +v8::Handle V8NodeSet::indexedPropertyCustomGetter(uint32_t index, const v8::AccessorInfo &info) { + v8::Local self = info.Holder(); + V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + if (privData->nativeObj->size() >= index) { + switch((*privData->nativeObj)[index].getNodeType()) { + case Node_base::ELEMENT_NODE: { + Arabica::DOM::Element* retVal = new Arabica::DOM::Element((*privData->nativeObj)[index]); + + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::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; + } + default: { + Arabica::DOM::Node* retVal = new Arabica::DOM::Node((*privData->nativeObj)[index]); + + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + } + } + + return v8::Undefined(); + +} +#endif + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp index ba6d506..35cdc61 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCNotation::Tmpl; JSStaticValue JSCNotation::staticValues[] = { { "publicId", publicIdAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp index 864f455..037af1b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCProcessingInstruction::Tmpl; JSStaticValue JSCProcessingInstruction::staticValues[] = { { "target", targetAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp index 2e43005..ba95603 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCSCXMLEvent::Tmpl; JSStaticValue JSCSCXMLEvent::staticValues[] = { { "type", typeCustomAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, @@ -88,6 +89,18 @@ JSValueRef JSCSCXMLEvent::invokeidAttrGetter(JSContextRef ctx, JSObjectRef objec return JSValueMakeString(ctx, stringRef); } +JSValueRef JSCSCXMLEvent::INTERNALConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 1); +} + +JSValueRef JSCSCXMLEvent::EXTERNALConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 2); +} + +JSValueRef JSCSCXMLEvent::PLATFORMConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef *exception) { + return JSValueMakeNumber(ctx, 3); +} + } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp new file mode 100644 index 0000000..f36e544 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEventCustom.cpp @@ -0,0 +1,40 @@ +#include "JSCSCXMLEvent.h" + +namespace Arabica { +namespace DOM { + +JSValueRef JSCSCXMLEvent::typeCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { +#if 0 + v8::Local self = info.Holder(); + V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + switch (privData->nativeObj->type) { + case uscxml::Event::INTERNAL: + return v8::String::New("internal"); + break; + case uscxml::Event::EXTERNAL: + return v8::String::New("external"); + break; + case uscxml::Event::PLATFORM: + return v8::String::New("platform"); + break; + default: + break; + } + return v8::String::New("unknown"); +#endif +} + +JSValueRef JSCSCXMLEvent::sendidCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { +#if 0 + v8::Local self = info.Holder(); + V8SCXMLEventPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + if (privData->nativeObj->sendid.length() == 0 || privData->nativeObj->hideSendId) + return v8::Undefined(); + return v8::String::New(privData->nativeObj->sendid.c_str()); +#endif +} + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp index 231823b..ba0b992 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCText::Tmpl; JSStaticValue JSCText::staticValues[] = { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp index d8dcbed..4ac7d17 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp @@ -4,6 +4,7 @@ namespace Arabica { namespace DOM { +JSClassRef JSCXPathResult::Tmpl; JSStaticValue JSCXPathResult::staticValues[] = { { "numberValue", numberValueAttrGetter, 0, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, @@ -39,7 +40,7 @@ JSValueRef JSCXPathResult::stringValueAttrGetter(JSContextRef ctx, JSObjectRef o JSValueRef JSCXPathResult::booleanValueAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCXPathResultPrivate* privData = (struct JSCXPathResultPrivate*)JSObjectGetPrivate(object); - return JSValueMakeNumber(ctx, privData->nativeObj->asBool()); + return JSValueMakeBoolean(ctx, privData->nativeObj->asBool()); } JSValueRef JSCXPathResult::asNodeSetCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp new file mode 100644 index 0000000..90abfa3 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResultCustom.cpp @@ -0,0 +1,29 @@ +#include "JSCXPathResult.h" +#include "JSCNode.h" + +namespace Arabica { +namespace DOM { + +JSValueRef JSCXPathResult::singleNodeValueCustomAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { +#if 0 + v8::Local self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->nativeObj->asNodeSet()[0]); + + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; +#endif +} + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 34dd524..420f1bb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -171,7 +171,7 @@ void V8DataModel::setEvent(const Event& event) { nameListIter++; } } - if (eventCopy.data.compound.size() > 0) { + if (eventCopy.data > 0) { eventObj->Set(v8::String::New("data"), getDataAsValue(eventCopy.data)); // set data part of _event } else { // test 343 / test 488 diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old deleted file mode 100644 index 680c433..0000000 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old +++ /dev/null @@ -1,104 +0,0 @@ -#ifndef V8DOCUMENT_H_COKK9O3L -#define V8DOCUMENT_H_COKK9O3L - -#include "V8DOM.h" -#include "V8Node.h" - -namespace uscxml { - - class V8Document { - public: - static v8::Handle doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - - static v8::Handle createElementCallback(const v8::Arguments& args); - static v8::Handle createDocumentFragmentCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createTextNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createCommentCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createCDATASectionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createProcessingInstructionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createEntityReferenceCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementsByTagNameCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle importNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createElementNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementByIdCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - - static v8::Handle createEventCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - - static v8::Handle createExpressionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createNSResolverCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle evaluateCallback(const v8::Arguments& args); - - V8_DESTRUCTOR(Arabica::DOM::Document); - - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Document")); - tmpl->ReadOnlyPrototype(); - - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - instance->SetInternalFieldCount(2); - - instance->SetAccessor(v8::String::NewSymbol("doctype"), V8Document::doctypeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("createElement"), - v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocumentFragment"), - v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createTextNode"), - v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createComment"), - v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createCDATASection"), - v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), - v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttribute"), - v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createEntityReference"), - v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagName"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("importNode"), - v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createElementNS"), - v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttributeNS"), - v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementById"), - v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createEvent"), - v8::FunctionTemplate::New(V8Document::createEventCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createExpression"), - v8::FunctionTemplate::New(V8Document::createExpressionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createNSResolver"), - v8::FunctionTemplate::New(V8Document::createNSResolverCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("evaluate"), - v8::FunctionTemplate::New(V8Document::evaluateCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } - - }; - -} - - -#endif /* end of include guard: V8DOCUMENT_H_COKK9O3L */ -- cgit v0.12