diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-08-13 10:07:32 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-08-13 10:07:32 (GMT) |
commit | 459f406eb2a36d393bd3a2b6aa3d63d86eb99c07 (patch) | |
tree | 35593bb978fee75bb7547f3d2c84a9039413fe1f /src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore | |
parent | beac3e74f703148085947d75da6fdaa9fd7472b4 (diff) | |
download | uscxml-459f406eb2a36d393bd3a2b6aa3d63d86eb99c07.zip uscxml-459f406eb2a36d393bd3a2b6aa3d63d86eb99c07.tar.gz uscxml-459f406eb2a36d393bd3a2b6aa3d63d86eb99c07.tar.bz2 |
Started Java datamodel and fixed memory leaks
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore')
28 files changed, 425 insertions, 164 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 33746a5..2c877b2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -370,6 +370,14 @@ void JSCDataModel::setForeach(const std::string& item, } bool JSCDataModel::isDeclared(const std::string& expr) { + JSStringRef scriptJS = JSStringCreateWithUTF8CString(expr.c_str()); + JSValueRef exception = NULL; + JSValueRef result = JSEvaluateScript(_ctx, scriptJS, NULL, NULL, 0, &exception); + JSStringRelease(scriptJS); + + if (exception || JSValueIsNull(_ctx, result)) { + return false; + } return true; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp index 6ceb642..3f967dd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp @@ -53,8 +53,9 @@ bool JSCAttr::valueAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, value, exception); size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); char* localValueBuffer = new char[localValueMaxSize]; - JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, sizeof(localValueBuffer)); - std::string localValue(localValueBuffer, localValueMaxSize); + JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); + std::string localValue(localValueBuffer); + JSStringRelease(stringReflocalValue); free(localValueBuffer); privData->nativeObj->setValue(localValue); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h index 5efc53a..01628a6 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.h @@ -57,6 +57,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h index a4d86f2..9fe225b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCDATASection.h @@ -52,6 +52,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCText::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp index c7ce20a..f64b4c9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp @@ -38,8 +38,9 @@ bool JSCCharacterData::dataAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSS JSStringRef stringReflocalData = JSValueToStringCopy(ctx, value, exception); size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, sizeof(localDataBuffer)); - std::string localData(localDataBuffer, localDataMaxSize); + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); free(localDataBuffer); privData->nativeObj->setData(localData); @@ -90,8 +91,9 @@ JSValueRef JSCCharacterData::appendDataCallback(JSContextRef ctx, JSObjectRef fu JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[0], exception); size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); char* localArgBuffer = new char[localArgMaxSize]; - JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, sizeof(localArgBuffer)); - std::string localArg(localArgBuffer, localArgMaxSize); + JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); + std::string localArg(localArgBuffer); + JSStringRelease(stringReflocalArg); free(localArgBuffer); @@ -117,8 +119,9 @@ JSValueRef JSCCharacterData::insertDataCallback(JSContextRef ctx, JSObjectRef fu JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[1], exception); size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); char* localArgBuffer = new char[localArgMaxSize]; - JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, sizeof(localArgBuffer)); - std::string localArg(localArgBuffer, localArgMaxSize); + JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); + std::string localArg(localArgBuffer); + JSStringRelease(stringReflocalArg); free(localArgBuffer); @@ -166,8 +169,9 @@ JSValueRef JSCCharacterData::replaceDataCallback(JSContextRef ctx, JSObjectRef f JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[2], exception); size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); char* localArgBuffer = new char[localArgMaxSize]; - JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, sizeof(localArgBuffer)); - std::string localArg(localArgBuffer, localArgMaxSize); + JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); + std::string localArg(localArgBuffer); + JSStringRelease(stringReflocalArg); free(localArgBuffer); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h index 2620468..0bdca74 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.h @@ -60,6 +60,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h index c1678ea..7c4e96f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCComment.h @@ -52,6 +52,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCCharacterData::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h index e2b8a4d..bffeab8 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h @@ -3,11 +3,21 @@ #include "uscxml/Interpreter.h" #include <JavaScriptCore/JavaScriptCore.h> +#include <XPath/XPath.hpp> #define JSC_DESTRUCTOR(type) \ static void jsDestructor(JSObjectRef object) { \ + type* thing = static_cast<type*>(JSObjectGetPrivate(object)); \ + if (thing) {\ + delete thing->nativeObj; \ + delete thing; \ + JSObjectSetPrivate(object, NULL);\ + }\ +} + +#define JSC_DESTRUCTOR_KEEP_WRAPPED(type) \ +static void jsDestructor(JSObjectRef object) { \ type* thing = static_cast<type*>(JSObjectGetPrivate(object)); \ -delete thing->nativeObj; \ delete thing; \ } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp index 66c9666..72d4beb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp @@ -33,15 +33,17 @@ JSValueRef JSCDOMImplementation::hasFeatureCallback(JSContextRef ctx, JSObjectRe JSStringRef stringReflocalFeature = JSValueToStringCopy(ctx, arguments[0], exception); size_t localFeatureMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalFeature); char* localFeatureBuffer = new char[localFeatureMaxSize]; - JSStringGetUTF8CString(stringReflocalFeature, localFeatureBuffer, sizeof(localFeatureBuffer)); - std::string localFeature(localFeatureBuffer, localFeatureMaxSize); + JSStringGetUTF8CString(stringReflocalFeature, localFeatureBuffer, localFeatureMaxSize); + std::string localFeature(localFeatureBuffer); + JSStringRelease(stringReflocalFeature); free(localFeatureBuffer); JSStringRef stringReflocalVersion = JSValueToStringCopy(ctx, arguments[1], exception); size_t localVersionMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalVersion); char* localVersionBuffer = new char[localVersionMaxSize]; - JSStringGetUTF8CString(stringReflocalVersion, localVersionBuffer, sizeof(localVersionBuffer)); - std::string localVersion(localVersionBuffer, localVersionMaxSize); + JSStringGetUTF8CString(stringReflocalVersion, localVersionBuffer, localVersionMaxSize); + std::string localVersion(localVersionBuffer); + JSStringRelease(stringReflocalVersion); free(localVersionBuffer); @@ -66,22 +68,25 @@ JSValueRef JSCDOMImplementation::createDocumentTypeCallback(JSContextRef ctx, JS JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; - JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, sizeof(localQualifiedNameBuffer)); - std::string localQualifiedName(localQualifiedNameBuffer, localQualifiedNameMaxSize); + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); free(localQualifiedNameBuffer); JSStringRef stringReflocalPublicId = JSValueToStringCopy(ctx, arguments[1], exception); size_t localPublicIdMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalPublicId); char* localPublicIdBuffer = new char[localPublicIdMaxSize]; - JSStringGetUTF8CString(stringReflocalPublicId, localPublicIdBuffer, sizeof(localPublicIdBuffer)); - std::string localPublicId(localPublicIdBuffer, localPublicIdMaxSize); + JSStringGetUTF8CString(stringReflocalPublicId, localPublicIdBuffer, localPublicIdMaxSize); + std::string localPublicId(localPublicIdBuffer); + JSStringRelease(stringReflocalPublicId); free(localPublicIdBuffer); JSStringRef stringReflocalSystemId = JSValueToStringCopy(ctx, arguments[2], exception); size_t localSystemIdMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalSystemId); char* localSystemIdBuffer = new char[localSystemIdMaxSize]; - JSStringGetUTF8CString(stringReflocalSystemId, localSystemIdBuffer, sizeof(localSystemIdBuffer)); - std::string localSystemId(localSystemIdBuffer, localSystemIdMaxSize); + JSStringGetUTF8CString(stringReflocalSystemId, localSystemIdBuffer, localSystemIdMaxSize); + std::string localSystemId(localSystemIdBuffer); + JSStringRelease(stringReflocalSystemId); free(localSystemIdBuffer); @@ -113,18 +118,20 @@ JSValueRef JSCDOMImplementation::createDocumentCallback(JSContextRef ctx, JSObje JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, 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, sizeof(localQualifiedNameBuffer)); - std::string localQualifiedName(localQualifiedNameBuffer, localQualifiedNameMaxSize); + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); free(localQualifiedNameBuffer); - Arabica::DOM::DocumentType<std::string>* localDoctype = ((struct JSCDocumentType::JSCDocumentTypePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::DocumentType<std::string>* localDoctype = ((struct JSCDocumentType::JSCDocumentTypePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[2], exception)))->nativeObj; Arabica::DOM::Document<std::string>* retVal = new Arabica::DOM::Document<std::string>(privData->nativeObj->createDocument(localNamespaceURI, localQualifiedName, *localDoctype)); JSClassRef retClass = JSCDocument::getTmpl(); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp index ed12bb0..4fae6c9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp @@ -109,8 +109,9 @@ JSValueRef JSCDocument::createElementCallback(JSContextRef ctx, JSObjectRef func JSStringRef stringReflocalTagName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localTagNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTagName); char* localTagNameBuffer = new char[localTagNameMaxSize]; - JSStringGetUTF8CString(stringReflocalTagName, localTagNameBuffer, sizeof(localTagNameBuffer)); - std::string localTagName(localTagNameBuffer, localTagNameMaxSize); + JSStringGetUTF8CString(stringReflocalTagName, localTagNameBuffer, localTagNameMaxSize); + std::string localTagName(localTagNameBuffer); + JSStringRelease(stringReflocalTagName); free(localTagNameBuffer); @@ -160,8 +161,9 @@ JSValueRef JSCDocument::createTextNodeCallback(JSContextRef ctx, JSObjectRef fun JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, sizeof(localDataBuffer)); - std::string localData(localDataBuffer, localDataMaxSize); + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); free(localDataBuffer); @@ -193,8 +195,9 @@ JSValueRef JSCDocument::createCommentCallback(JSContextRef ctx, JSObjectRef func JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, sizeof(localDataBuffer)); - std::string localData(localDataBuffer, localDataMaxSize); + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); free(localDataBuffer); @@ -226,8 +229,9 @@ JSValueRef JSCDocument::createCDATASectionCallback(JSContextRef ctx, JSObjectRef JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, sizeof(localDataBuffer)); - std::string localData(localDataBuffer, localDataMaxSize); + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); free(localDataBuffer); @@ -259,15 +263,17 @@ JSValueRef JSCDocument::createProcessingInstructionCallback(JSContextRef ctx, JS JSStringRef stringReflocalTarget = JSValueToStringCopy(ctx, arguments[0], exception); size_t localTargetMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTarget); char* localTargetBuffer = new char[localTargetMaxSize]; - JSStringGetUTF8CString(stringReflocalTarget, localTargetBuffer, sizeof(localTargetBuffer)); - std::string localTarget(localTargetBuffer, localTargetMaxSize); + JSStringGetUTF8CString(stringReflocalTarget, localTargetBuffer, localTargetMaxSize); + std::string localTarget(localTargetBuffer); + JSStringRelease(stringReflocalTarget); free(localTargetBuffer); JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[1], exception); size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, sizeof(localDataBuffer)); - std::string localData(localDataBuffer, localDataMaxSize); + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); free(localDataBuffer); @@ -299,8 +305,9 @@ JSValueRef JSCDocument::createAttributeCallback(JSContextRef ctx, JSObjectRef fu JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -332,8 +339,9 @@ JSValueRef JSCDocument::createEntityReferenceCallback(JSContextRef ctx, JSObject JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -365,8 +373,9 @@ JSValueRef JSCDocument::getElementsByTagNameCallback(JSContextRef ctx, JSObjectR JSStringRef stringReflocalTagname = JSValueToStringCopy(ctx, arguments[0], exception); size_t localTagnameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTagname); char* localTagnameBuffer = new char[localTagnameMaxSize]; - JSStringGetUTF8CString(stringReflocalTagname, localTagnameBuffer, sizeof(localTagnameBuffer)); - std::string localTagname(localTagnameBuffer, localTagnameMaxSize); + JSStringGetUTF8CString(stringReflocalTagname, localTagnameBuffer, localTagnameMaxSize); + std::string localTagname(localTagnameBuffer); + JSStringRelease(stringReflocalTagname); free(localTagnameBuffer); @@ -395,7 +404,7 @@ JSValueRef JSCDocument::importNodeCallback(JSContextRef ctx, JSObjectRef functio struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localImportedNode = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Node<std::string>* localImportedNode = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; bool localDeep = JSValueToBoolean(ctx, arguments[1]); Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->importNode(*localImportedNode, localDeep)); @@ -426,15 +435,17 @@ JSValueRef JSCDocument::createElementNSCallback(JSContextRef ctx, JSObjectRef fu JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, 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, sizeof(localQualifiedNameBuffer)); - std::string localQualifiedName(localQualifiedNameBuffer, localQualifiedNameMaxSize); + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); free(localQualifiedNameBuffer); @@ -466,15 +477,17 @@ JSValueRef JSCDocument::createAttributeNSCallback(JSContextRef ctx, JSObjectRef JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, 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, sizeof(localQualifiedNameBuffer)); - std::string localQualifiedName(localQualifiedNameBuffer, localQualifiedNameMaxSize); + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); free(localQualifiedNameBuffer); @@ -506,15 +519,17 @@ JSValueRef JSCDocument::getElementsByTagNameNSCallback(JSContextRef ctx, JSObjec JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); @@ -546,8 +561,9 @@ JSValueRef JSCDocument::getElementByIdCallback(JSContextRef ctx, JSObjectRef fun JSStringRef stringReflocalElementId = JSValueToStringCopy(ctx, arguments[0], exception); size_t localElementIdMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalElementId); char* localElementIdBuffer = new char[localElementIdMaxSize]; - JSStringGetUTF8CString(stringReflocalElementId, localElementIdBuffer, sizeof(localElementIdBuffer)); - std::string localElementId(localElementIdBuffer, localElementIdMaxSize); + JSStringGetUTF8CString(stringReflocalElementId, localElementIdBuffer, localElementIdMaxSize); + std::string localElementId(localElementIdBuffer); + JSStringRelease(stringReflocalElementId); free(localElementIdBuffer); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h index 3446cc2..6657f3b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.h @@ -70,6 +70,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp index 23cc0f9..c6fdce1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentCustom.cpp @@ -1,11 +1,76 @@ #include "JSCDocument.h" #include "JSCXPathResult.h" +#include "JSCNode.h" +#include <XPath/XPath.hpp> namespace Arabica { namespace DOM { -JSValueRef JSCDocument::evaluateCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { +JSValueRef JSCDocument::evaluateCustomCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef object, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(object); + + if (!privData->dom || !privData->dom->xpath) return JSValueMakeUndefined(ctx); + if (argumentCount < 1) { + std::string errorMsg = "Wrong number of arguments in evaluate"; + JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); + JSValueRef exceptionString = JSValueMakeString(ctx, string); + JSStringRelease(string); + *exception = JSValueToObject(ctx, exceptionString, NULL); + return JSValueMakeUndefined(ctx); + } + + // make sure first argument is a string + if (!JSValueIsString(ctx, arguments[0])) { + std::string errorMsg = "Expected xpath expression as first argument"; + JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); + JSValueRef exceptionString = JSValueMakeString(ctx, string); + JSStringRelease(string); + *exception = JSValueToObject(ctx, exceptionString, NULL); + return JSValueMakeUndefined(ctx); + } + + JSStringRef stringReflocalXPath = JSValueToStringCopy(ctx, arguments[0], NULL); + size_t localXPathMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalXPath); + char* localXPathBuffer = new char[localXPathMaxSize]; + JSStringGetUTF8CString(stringReflocalXPath, localXPathBuffer, localXPathMaxSize); + std::string localXPath(localXPathBuffer); + JSStringRelease(stringReflocalXPath); + free(localXPathBuffer); + + JSClassRef arbaicaRetClass = JSCXPathResult::getTmpl(); + + XPath::XPathValue<std::string>* retVal; + + try { + if (argumentCount > 1) { + // make sure second argument is a node + if (!JSValueIsObject(ctx, arguments[1])) { + std::string errorMsg = "Second argument is not of type node"; + JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); + JSValueRef exceptionString = JSValueMakeString(ctx, string); + JSStringRelease(string); + *exception = JSValueToObject(ctx, exceptionString, NULL); + return JSValueMakeUndefined(ctx); + } + + Arabica::DOM::Node<std::string>* localContextNode = (Arabica::DOM::Node<std::string>*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[1], NULL)); + retVal = new XPath::XPathValue<std::string>(privData->dom->xpath->evaluate(localXPath, *localContextNode)); + } else { + retVal = new XPath::XPathValue<std::string>(privData->dom->xpath->evaluate(localXPath, *privData->nativeObj)); + } + } catch (std::runtime_error e) { + std::cout << e.what() << std::endl; + return JSValueMakeUndefined(ctx); + } + + struct JSCXPathResult::JSCXPathResultPrivate* retPrivData = new JSCXPathResult::JSCXPathResultPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); + return arbaicaRetObj; + #if 0 if (args.Length() < 1) throw V8Exception("Wrong number of arguments in evaluate"); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h index 1d8a9c9..3a9d8d6 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentFragment.h @@ -52,6 +52,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h index 6f839a2..3dc46f4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.h @@ -58,6 +58,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp index ce77091..e0b403f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp @@ -57,8 +57,9 @@ JSValueRef JSCElement::getAttributeCallback(JSContextRef ctx, JSObjectRef functi JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -85,15 +86,17 @@ JSValueRef JSCElement::setAttributeCallback(JSContextRef ctx, JSObjectRef functi JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, arguments[1], exception); size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); char* localValueBuffer = new char[localValueMaxSize]; - JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, sizeof(localValueBuffer)); - std::string localValue(localValueBuffer, localValueMaxSize); + JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); + std::string localValue(localValueBuffer); + JSStringRelease(stringReflocalValue); free(localValueBuffer); @@ -118,8 +121,9 @@ JSValueRef JSCElement::removeAttributeCallback(JSContextRef ctx, JSObjectRef fun JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -144,8 +148,9 @@ JSValueRef JSCElement::getAttributeNodeCallback(JSContextRef ctx, JSObjectRef fu JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -174,7 +179,7 @@ JSValueRef JSCElement::setAttributeNodeCallback(JSContextRef ctx, JSObjectRef fu struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Attr<std::string>* localNewAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Attr<std::string>* localNewAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNode(*localNewAttr)); JSClassRef retClass = JSCAttr::getTmpl(); @@ -201,7 +206,7 @@ JSValueRef JSCElement::removeAttributeNodeCallback(JSContextRef ctx, JSObjectRef struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Attr<std::string>* localOldAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Attr<std::string>* localOldAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->removeAttributeNode(*localOldAttr)); JSClassRef retClass = JSCAttr::getTmpl(); @@ -231,8 +236,9 @@ JSValueRef JSCElement::getElementsByTagNameCallback(JSContextRef ctx, JSObjectRe JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -264,15 +270,17 @@ JSValueRef JSCElement::getAttributeNSCallback(JSContextRef ctx, JSObjectRef func JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); @@ -299,22 +307,25 @@ JSValueRef JSCElement::setAttributeNSCallback(JSContextRef ctx, JSObjectRef func JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, 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, sizeof(localQualifiedNameBuffer)); - std::string localQualifiedName(localQualifiedNameBuffer, localQualifiedNameMaxSize); + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); free(localQualifiedNameBuffer); JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, arguments[2], exception); size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); char* localValueBuffer = new char[localValueMaxSize]; - JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, sizeof(localValueBuffer)); - std::string localValue(localValueBuffer, localValueMaxSize); + JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); + std::string localValue(localValueBuffer); + JSStringRelease(stringReflocalValue); free(localValueBuffer); @@ -339,15 +350,17 @@ JSValueRef JSCElement::removeAttributeNSCallback(JSContextRef ctx, JSObjectRef f JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); @@ -372,15 +385,17 @@ JSValueRef JSCElement::getAttributeNodeNSCallback(JSContextRef ctx, JSObjectRef JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); @@ -409,7 +424,7 @@ JSValueRef JSCElement::setAttributeNodeNSCallback(JSContextRef ctx, JSObjectRef struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Attr<std::string>* localNewAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Attr<std::string>* localNewAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); JSClassRef retClass = JSCAttr::getTmpl(); @@ -439,15 +454,17 @@ JSValueRef JSCElement::getElementsByTagNameNSCallback(JSContextRef ctx, JSObject JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); @@ -479,8 +496,9 @@ JSValueRef JSCElement::hasAttributeCallback(JSContextRef ctx, JSObjectRef functi JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -505,15 +523,17 @@ JSValueRef JSCElement::hasAttributeNSCallback(JSContextRef ctx, JSObjectRef func JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h index 42dc2ac..9520a8b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.h @@ -68,6 +68,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h index e16cc1f..69f54a3 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntity.h @@ -55,6 +55,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h index d8e4803..428274f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCEntityReference.h @@ -52,6 +52,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp index aeb0913..c72b27b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp @@ -44,8 +44,9 @@ JSValueRef JSCNamedNodeMap::getNamedItemCallback(JSContextRef ctx, JSObjectRef f JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -74,7 +75,7 @@ JSValueRef JSCNamedNodeMap::setNamedItemCallback(JSContextRef ctx, JSObjectRef f struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localArg = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Node<std::string>* localArg = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItem(*localArg)); JSClassRef retClass = JSCNode::getTmpl(); @@ -104,8 +105,9 @@ JSValueRef JSCNamedNodeMap::removeNamedItemCallback(JSContextRef ctx, JSObjectRe JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, sizeof(localNameBuffer)); - std::string localName(localNameBuffer, localNameMaxSize); + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); free(localNameBuffer); @@ -164,15 +166,17 @@ JSValueRef JSCNamedNodeMap::getNamedItemNSCallback(JSContextRef ctx, JSObjectRef JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); @@ -201,7 +205,7 @@ JSValueRef JSCNamedNodeMap::setNamedItemNSCallback(JSContextRef ctx, JSObjectRef struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localArg = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Node<std::string>* localArg = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItemNS(*localArg)); JSClassRef retClass = JSCNode::getTmpl(); @@ -231,15 +235,17 @@ JSValueRef JSCNamedNodeMap::removeNamedItemNSCallback(JSContextRef ctx, JSObject JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, sizeof(localNamespaceURIBuffer)); - std::string localNamespaceURI(localNamespaceURIBuffer, localNamespaceURIMaxSize); + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); free(localNamespaceURIBuffer); JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, sizeof(localLocalNameBuffer)); - std::string localLocalName(localLocalNameBuffer, localLocalNameMaxSize); + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); free(localLocalNameBuffer); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp index 0e84442..22d048c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp @@ -77,8 +77,9 @@ bool JSCNode::nodeValueAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStrin JSStringRef stringReflocalNodeValue = JSValueToStringCopy(ctx, value, exception); size_t localNodeValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNodeValue); char* localNodeValueBuffer = new char[localNodeValueMaxSize]; - JSStringGetUTF8CString(stringReflocalNodeValue, localNodeValueBuffer, sizeof(localNodeValueBuffer)); - std::string localNodeValue(localNodeValueBuffer, localNodeValueMaxSize); + JSStringGetUTF8CString(stringReflocalNodeValue, localNodeValueBuffer, localNodeValueMaxSize); + std::string localNodeValue(localNodeValueBuffer); + JSStringRelease(stringReflocalNodeValue); free(localNodeValueBuffer); privData->nativeObj->setNodeValue(localNodeValue); @@ -237,8 +238,9 @@ bool JSCNode::prefixAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRe JSStringRef stringReflocalPrefix = JSValueToStringCopy(ctx, value, exception); size_t localPrefixMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalPrefix); char* localPrefixBuffer = new char[localPrefixMaxSize]; - JSStringGetUTF8CString(stringReflocalPrefix, localPrefixBuffer, sizeof(localPrefixBuffer)); - std::string localPrefix(localPrefixBuffer, localPrefixMaxSize); + JSStringGetUTF8CString(stringReflocalPrefix, localPrefixBuffer, localPrefixMaxSize); + std::string localPrefix(localPrefixBuffer); + JSStringRelease(stringReflocalPrefix); free(localPrefixBuffer); privData->nativeObj->setPrefix(localPrefix); @@ -314,8 +316,8 @@ JSValueRef JSCNode::insertBeforeCallback(JSContextRef ctx, JSObjectRef function, struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localNewChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; - Arabica::DOM::Node<std::string>* localRefChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Node<std::string>* localNewChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + Arabica::DOM::Node<std::string>* localRefChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[1], exception)))->nativeObj; Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); JSClassRef retClass = JSCNode::getTmpl(); @@ -342,8 +344,8 @@ JSValueRef JSCNode::replaceChildCallback(JSContextRef ctx, JSObjectRef function, struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localNewChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; - Arabica::DOM::Node<std::string>* localOldChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Node<std::string>* localNewChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + Arabica::DOM::Node<std::string>* localOldChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[1], exception)))->nativeObj; Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); JSClassRef retClass = JSCNode::getTmpl(); @@ -370,7 +372,7 @@ JSValueRef JSCNode::removeChildCallback(JSContextRef ctx, JSObjectRef function, struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localOldChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Node<std::string>* localOldChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeChild(*localOldChild)); JSClassRef retClass = JSCNode::getTmpl(); @@ -397,7 +399,7 @@ JSValueRef JSCNode::appendChildCallback(JSContextRef ctx, JSObjectRef function, struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localNewChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(thisObj))->nativeObj; + Arabica::DOM::Node<std::string>* localNewChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->appendChild(*localNewChild)); JSClassRef retClass = JSCNode::getTmpl(); @@ -476,15 +478,17 @@ JSValueRef JSCNode::isSupportedCallback(JSContextRef ctx, JSObjectRef function, JSStringRef stringReflocalFeature = JSValueToStringCopy(ctx, arguments[0], exception); size_t localFeatureMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalFeature); char* localFeatureBuffer = new char[localFeatureMaxSize]; - JSStringGetUTF8CString(stringReflocalFeature, localFeatureBuffer, sizeof(localFeatureBuffer)); - std::string localFeature(localFeatureBuffer, localFeatureMaxSize); + JSStringGetUTF8CString(stringReflocalFeature, localFeatureBuffer, localFeatureMaxSize); + std::string localFeature(localFeatureBuffer); + JSStringRelease(stringReflocalFeature); free(localFeatureBuffer); JSStringRef stringReflocalVersion = JSValueToStringCopy(ctx, arguments[1], exception); size_t localVersionMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalVersion); char* localVersionBuffer = new char[localVersionMaxSize]; - JSStringGetUTF8CString(stringReflocalVersion, localVersionBuffer, sizeof(localVersionBuffer)); - std::string localVersion(localVersionBuffer, localVersionMaxSize); + JSStringGetUTF8CString(stringReflocalVersion, localVersionBuffer, localVersionMaxSize); + std::string localVersion(localVersionBuffer); + JSStringRelease(stringReflocalVersion); free(localVersionBuffer); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h index 4a1ba11..fca81b8 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.h @@ -41,6 +41,8 @@ public: static JSValueRef itemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); + static bool hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); + static JSValueRef getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -53,6 +55,8 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp index 788c8ec..adb366e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp @@ -5,6 +5,77 @@ namespace Arabica { namespace DOM { +bool JSCNodeList::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + size_t propMaxSize = JSStringGetMaximumUTF8CStringSize(propertyName); + char* propBuffer = new char[propMaxSize]; + JSStringGetUTF8CString(propertyName, propBuffer, propMaxSize); + std::string propName(propBuffer); + free(propBuffer); + + std::string base = "0123456789"; + if (propName.find_first_not_of(base) != std::string::npos) { + return false; + } + + int index = boost::lexical_cast<int>(propName); + struct JSCNodeListPrivate* privData = (struct JSCNodeListPrivate*)JSObjectGetPrivate(object); + + if (privData->nativeObj->getLength() < index) { + return false; + } + + return true; +} + +JSValueRef JSCNodeList::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + size_t propMaxSize = JSStringGetMaximumUTF8CStringSize(propertyName); + char* propBuffer = new char[propMaxSize]; + JSStringGetUTF8CString(propertyName, propBuffer, propMaxSize); + std::string propName(propBuffer); + free(propBuffer); + + std::string base = "0123456789"; + if (propName.find_first_not_of(base) != std::string::npos) { + return JSValueMakeUndefined(ctx); + } + + int index = boost::lexical_cast<int>(propName); + struct JSCNodeListPrivate* privData = (struct JSCNodeListPrivate*)JSObjectGetPrivate(object); + if (privData->nativeObj->getLength() < index) { + return JSValueMakeUndefined(ctx); + } + + switch(privData->nativeObj->item(index).getNodeType()) { + case Node_base::ELEMENT_NODE: { + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->item(index)); + 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; + break; + } + default: { + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(index)); + JSClassRef retClass = JSCNode::getTmpl(); + + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + + return retObj; + } + } + + return JSValueMakeUndefined(ctx); +} + #if 0 v8::Handle<v8::Value> V8NodeList::indexedPropertyCustomGetter(uint32_t index, const v8::AccessorInfo &info) { v8::Local<v8::Object> self = info.Holder(); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h index 42b4f29..b38d04e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.h @@ -42,6 +42,8 @@ public: static JSValueRef sizeAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef emptyAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); + static bool hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName); + static JSValueRef getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -54,6 +56,8 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp index 1591310..98f563e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSetCustom.cpp @@ -5,50 +5,77 @@ namespace Arabica { namespace DOM { -#if 0 -v8::Handle<v8::Value> V8NodeSet::indexedPropertyCustomGetter(uint32_t index, const v8::AccessorInfo &info) { - v8::Local<v8::Object> self = info.Holder(); - V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); - if (privData->nativeObj->size() >= index) { - switch((*privData->nativeObj)[index].getNodeType()) { - case Node_base::ELEMENT_NODE: { - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>((*privData->nativeObj)[index]); +bool JSCNodeSet::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + size_t propMaxSize = JSStringGetMaximumUTF8CStringSize(propertyName); + char* propBuffer = new char[propMaxSize]; + JSStringGetUTF8CString(propertyName, propBuffer, propMaxSize); + std::string propName(propBuffer); + free(propBuffer); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + std::string base = "0123456789"; + if (propName.find_first_not_of(base) != std::string::npos) { + return false; + } + + int index = boost::lexical_cast<int>(propName); + struct JSCNodeSetPrivate* privData = (struct JSCNodeSetPrivate*)JSObjectGetPrivate(object); + + if (privData->nativeObj->size() < index) { + return false; + } + + return true; +} - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; +JSValueRef JSCNodeSet::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + size_t propMaxSize = JSStringGetMaximumUTF8CStringSize(propertyName); + char* propBuffer = new char[propMaxSize]; + JSStringGetUTF8CString(propertyName, propBuffer, propMaxSize); + std::string propName(propBuffer); + free(propBuffer); - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + std::string base = "0123456789"; + if (propName.find_first_not_of(base) != std::string::npos) { + return JSValueMakeUndefined(ctx); + } - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; - } - default: { - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>((*privData->nativeObj)[index]); + int index = boost::lexical_cast<int>(propName); + struct JSCNodeSetPrivate* privData = (struct JSCNodeSetPrivate*)JSObjectGetPrivate(object); + if (privData->nativeObj->size() < index) { + return JSValueMakeUndefined(ctx); + } - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + switch((*privData->nativeObj)[index].getNodeType()) { + case Node_base::ELEMENT_NODE: { + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>((*privData->nativeObj)[index]); + JSClassRef retClass = JSCElement::getTmpl(); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; - } - } + return retObj; + break; } + default: { + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>((*privData->nativeObj)[index]); + JSClassRef retClass = JSCNode::getTmpl(); + + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - return v8::Undefined(); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + + return retObj; + } + } + return JSValueMakeUndefined(ctx); } -#endif } }
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h index ed793ed..bb84c50 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNotation.h @@ -54,6 +54,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp index d60c39b..9ea0220 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.cpp @@ -43,8 +43,9 @@ bool JSCProcessingInstruction::dataAttrSetter(JSContextRef ctx, JSObjectRef this JSStringRef stringReflocalData = JSValueToStringCopy(ctx, value, exception); size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, sizeof(localDataBuffer)); - std::string localData(localDataBuffer, localDataMaxSize); + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); free(localDataBuffer); privData->nativeObj->setData(localData); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h index fdf7bc5..fc8c44b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCProcessingInstruction.h @@ -55,6 +55,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCNode::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h index a6fdbbd..786df27 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.h @@ -53,6 +53,7 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.parentClass = JSCCharacterData::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); |