diff options
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript')
89 files changed, 7303 insertions, 3252 deletions
diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h index e88851e..5953c0e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h @@ -31,6 +31,7 @@ public: virtual ~JSCDOM(); uscxml::Storage* storage; Arabica::XPath::XPath<std::string>* xpath; + }; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index c714735..173a0ed 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -8,6 +8,18 @@ #include "dom/JSCCDATASection.h" #include "dom/JSCSCXMLEvent.h" +#include "dom/JSCArrayBuffer.h" +#include "dom/JSCInt8Array.h" +#include "dom/JSCUint8Array.h" +#include "dom/JSCUint8ClampedArray.h" +#include "dom/JSCInt16Array.h" +#include "dom/JSCUint16Array.h" +#include "dom/JSCInt32Array.h" +#include "dom/JSCUint32Array.h" +#include "dom/JSCFloat32Array.h" +#include "dom/JSCFloat64Array.h" +#include "dom/JSCDataView.h" + #include "uscxml/Message.h" #include <glog/logging.h> @@ -22,6 +34,12 @@ privData->nativeObj = new type<std::string>(node); \ JSObjectRef retObj = JSObjectMake(_ctx, JSC##type::getTmpl(), privData);\ return retObj; +#define JSC_ADD_GLOBAL_OBJECT(name, constructor)\ +JSStringRef name##Name = JSStringCreateWithUTF8CString(#name);\ +JSObjectRef name = JSObjectMake(dm->_ctx, constructor, NULL);\ +JSObjectSetProperty(dm->_ctx, JSContextGetGlobalObject(dm->_ctx), name##Name, name, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete, NULL);\ +JSStringRelease(name##Name); + namespace uscxml { using namespace Arabica::XPath; @@ -127,6 +145,18 @@ boost::shared_ptr<DataModelImpl> JSCDataModel::create(InterpreterImpl* interpret JSStringRelease(sessionIdName); JSStringRelease(sessionId); + JSC_ADD_GLOBAL_OBJECT(ArrayBuffer, JSCArrayBuffer::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Int8Array, JSCInt8Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Uint8Array, JSCUint8Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Uint8ClampedArray, JSCUint8ClampedArray::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Int16Array, JSCInt16Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Uint16Array, JSCUint16Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Int32Array, JSCInt32Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Uint32Array, JSCUint32Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Float32Array, JSCFloat32Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(Float64Array, JSCFloat64Array::getTmpl()); + JSC_ADD_GLOBAL_OBJECT(DataView, JSCDataView::getTmpl()); + JSCDocument::JSCDocumentPrivate* privData = new JSCDocument::JSCDocumentPrivate(); if (interpreter) { privData->nativeObj = new Document<std::string>(interpreter->getDocument()); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.cpp index 39c8dab..a7c27e1 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.cpp @@ -17,60 +17,105 @@ JSStaticFunction JSCArrayBuffer::staticFunctions[] = { { 0, 0, 0 } }; +JSObjectRef JSCArrayBuffer::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::ArrayBuffer* localInstance = NULL; + + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::ArrayBuffer(localLength); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for ArrayBuffer"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCArrayBuffer::getTmpl(); + + struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCArrayBuffer::byteLengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(object); return JSValueMakeNumber(ctx, privData->nativeObj->getByteLength()); } + JSValueRef JSCArrayBuffer::sliceCallback(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 slice"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(thisObj); - long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd)); - JSClassRef retClass = JSCArrayBuffer::getTmpl(); + uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd)); + JSClassRef retClass = JSCArrayBuffer::getTmpl(); - struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + long localBegin = (long)JSValueToNumber(ctx, arguments[0], exception); + + uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin)); + JSClassRef retClass = JSCArrayBuffer::getTmpl(); + + struct JSCArrayBuffer::JSCArrayBufferPrivate* retPrivData = new JSCArrayBuffer::JSCArrayBufferPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; + + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling slice"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCArrayBuffer::isViewCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in isView"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCArrayBufferPrivate* privData = (struct JSCArrayBufferPrivate*)JSObjectGetPrivate(thisObj); - void* localValue = JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)); + if (false) { + } else if (argumentCount == 1 && + true) { + void* localValue = JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)); - bool retVal = privData->nativeObj->isView(localValue); + bool retVal = privData->nativeObj->isView(localValue); - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; -} + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling isView"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.h index e3e7a14..b3fa8ea 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBuffer.h @@ -42,7 +42,11 @@ public: static JSValueRef sliceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef isViewCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef byteLengthAttrGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -55,6 +59,10 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBufferView.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBufferView.cpp index f599aff..031bed5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBufferView.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCArrayBufferView.cpp @@ -30,7 +30,7 @@ JSValueRef JSCArrayBufferView::bufferAttrGetter(JSContextRef ctx, JSObjectRef ob retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp index 3f967dd..e870216 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCAttr.cpp @@ -74,7 +74,7 @@ JSValueRef JSCAttr::ownerElementAttrGetter(JSContextRef ctx, JSObjectRef object, retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp index f64b4c9..1b87bcc 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCCharacterData.cpp @@ -53,134 +53,144 @@ JSValueRef JSCCharacterData::lengthAttrGetter(JSContextRef ctx, JSObjectRef obje return JSValueMakeNumber(ctx, privData->nativeObj->getLength()); } + JSValueRef JSCCharacterData::substringDataCallback(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 substringData"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned long localCount = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned long localCount = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); - std::string retVal = privData->nativeObj->substringData(localOffset, localCount); + std::string retVal = privData->nativeObj->substringData(localOffset, localCount); - JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); - JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); - JSStringRelease(jscString); - return jscRetVal; + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling substringData"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCCharacterData::appendDataCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in appendData"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); - char* localArgBuffer = new char[localArgMaxSize]; - JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); - std::string localArg(localArgBuffer); - JSStringRelease(stringReflocalArg); - free(localArgBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); + char* localArgBuffer = new char[localArgMaxSize]; + JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); + std::string localArg(localArgBuffer); + JSStringRelease(stringReflocalArg); + free(localArgBuffer); - privData->nativeObj->appendData(localArg); + privData->nativeObj->appendData(localArg); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling appendData"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCCharacterData::insertDataCallback(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 insertData"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); - char* localArgBuffer = new char[localArgMaxSize]; - JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); - std::string localArg(localArgBuffer); - JSStringRelease(stringReflocalArg); - free(localArgBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); + char* localArgBuffer = new char[localArgMaxSize]; + JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); + std::string localArg(localArgBuffer); + JSStringRelease(stringReflocalArg); + free(localArgBuffer); + + privData->nativeObj->insertData(localOffset, localArg); - privData->nativeObj->insertData(localOffset, localArg); + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling insertData"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCCharacterData::deleteDataCallback(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 deleteData"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned long localCount = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned long localCount = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); - privData->nativeObj->deleteData(localOffset, localCount); + privData->nativeObj->deleteData(localOffset, localCount); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling deleteData"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCCharacterData::replaceDataCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in replaceData"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCCharacterDataPrivate* privData = (struct JSCCharacterDataPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned long localCount = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); - JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[2], exception); - size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); - char* localArgBuffer = new char[localArgMaxSize]; - JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); - std::string localArg(localArgBuffer); - JSStringRelease(stringReflocalArg); - free(localArgBuffer); - - - privData->nativeObj->replaceData(localOffset, localCount, localArg); + if (false) { + } else if (argumentCount == 3 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsString(ctx, arguments[2])) { + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned long localCount = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + JSStringRef stringReflocalArg = JSValueToStringCopy(ctx, arguments[2], exception); + size_t localArgMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalArg); + char* localArgBuffer = new char[localArgMaxSize]; + JSStringGetUTF8CString(stringReflocalArg, localArgBuffer, localArgMaxSize); + std::string localArg(localArgBuffer); + JSStringRelease(stringReflocalArg); + free(localArgBuffer); + + + privData->nativeObj->replaceData(localOffset, localCount, localArg); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling replaceData"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } - } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp index 72d4beb..81b3e46 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOMImplementation.cpp @@ -18,134 +18,142 @@ JSStaticFunction JSCDOMImplementation::staticFunctions[] = { { "createDocument", createDocumentCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; + JSValueRef JSCDOMImplementation::hasFeatureCallback(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 hasFeature"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDOMImplementationPrivate* privData = (struct JSCDOMImplementationPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalFeature = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localFeatureMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalFeature); - char* localFeatureBuffer = new char[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, localVersionMaxSize); - std::string localVersion(localVersionBuffer); - JSStringRelease(stringReflocalVersion); - free(localVersionBuffer); - - - bool retVal = privData->nativeObj->hasFeature(localFeature, localVersion); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalFeature = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localFeatureMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalFeature); + char* localFeatureBuffer = new char[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, localVersionMaxSize); + std::string localVersion(localVersionBuffer); + JSStringRelease(stringReflocalVersion); + free(localVersionBuffer); + + + bool retVal = privData->nativeObj->hasFeature(localFeature, localVersion); + + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling hasFeature"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDOMImplementation::createDocumentTypeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in createDocumentType"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDOMImplementationPrivate* privData = (struct JSCDOMImplementationPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); - char* localQualifiedNameBuffer = new char[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, 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, localSystemIdMaxSize); - std::string localSystemId(localSystemIdBuffer); - JSStringRelease(stringReflocalSystemId); - free(localSystemIdBuffer); + if (false) { + } else if (argumentCount == 3 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1]) && + JSValueIsString(ctx, arguments[2])) { + JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); + char* localQualifiedNameBuffer = new char[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, 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, localSystemIdMaxSize); + std::string localSystemId(localSystemIdBuffer); + JSStringRelease(stringReflocalSystemId); + free(localSystemIdBuffer); + + + Arabica::DOM::DocumentType<std::string>* retVal = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->createDocumentType(localQualifiedName, localPublicId, localSystemId)); + JSClassRef retClass = JSCDocumentType::getTmpl(); + + struct JSCDocumentType::JSCDocumentTypePrivate* retPrivData = new JSCDocumentType::JSCDocumentTypePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + + return retObj; + } - Arabica::DOM::DocumentType<std::string>* retVal = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->createDocumentType(localQualifiedName, localPublicId, localSystemId)); - JSClassRef retClass = JSCDocumentType::getTmpl(); - - struct JSCDocumentType::JSCDocumentTypePrivate* retPrivData = new JSCDocumentType::JSCDocumentTypePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - - return retObj; - + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createDocumentType"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDOMImplementation::createDocumentCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in createDocument"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDOMImplementationPrivate* privData = (struct JSCDOMImplementationPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 3 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1]) && + JSValueIsObject(ctx, arguments[2]) && JSValueIsObjectOfClass(ctx, arguments[2], JSCDocumentType::getTmpl())) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); - JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); - char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; - JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); - std::string localQualifiedName(localQualifiedNameBuffer); - JSStringRelease(stringReflocalQualifiedName); - free(localQualifiedNameBuffer); + JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); + char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); + free(localQualifiedNameBuffer); - Arabica::DOM::DocumentType<std::string>* localDoctype = ((struct JSCDocumentType::JSCDocumentTypePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[2], exception)))->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(); + Arabica::DOM::Document<std::string>* retVal = new Arabica::DOM::Document<std::string>(privData->nativeObj->createDocument(localNamespaceURI, localQualifiedName, *localDoctype)); + JSClassRef retClass = JSCDocument::getTmpl(); - struct JSCDocument::JSCDocumentPrivate* retPrivData = new JSCDocument::JSCDocumentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCDocument::JSCDocumentPrivate* retPrivData = new JSCDocument::JSCDocumentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createDocument"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.cpp index 5e6ee80..530e157 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCDataView.h" namespace Arabica { @@ -29,346 +31,535 @@ JSStaticFunction JSCDataView::staticFunctions[] = { { "setFloat64", setFloat64Callback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; -JSValueRef JSCDataView::getInt8Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getInt8"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; + +JSObjectRef JSCDataView::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::DataView* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localByteLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::DataView(localBuffer, localByteOffset, localByteLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::DataView(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::DataView(localBuffer); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for DataView"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); } + JSClassRef retClass = JSCDataView::getTmpl(); + + struct JSCDataView::JSCDataViewPrivate* retPrivData = new JSCDataView::JSCDataViewPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + +JSValueRef JSCDataView::getInt8Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { + struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + + char retVal = privData->nativeObj->getInt8(localByteOffset); - char retVal = privData->nativeObj->getInt8(localByteOffset); + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getInt8"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::getUint8Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getUint8"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - char retVal = privData->nativeObj->getUint8(localByteOffset); + unsigned char retVal = privData->nativeObj->getUint8(localByteOffset); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getUint8"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::getInt16Callback(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 getInt16"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsBoolean(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + + short retVal = privData->nativeObj->getInt16(localByteOffset, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - short retVal = privData->nativeObj->getInt16(localByteOffset, localLittleEndian); + short retVal = privData->nativeObj->getInt16(localByteOffset); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getInt16"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::getUint16Callback(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 getUint16"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsBoolean(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + + unsigned short retVal = privData->nativeObj->getUint16(localByteOffset, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned short retVal = privData->nativeObj->getUint16(localByteOffset, localLittleEndian); + unsigned short retVal = privData->nativeObj->getUint16(localByteOffset); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getUint16"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::getInt32Callback(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 getInt32"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsBoolean(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + + long retVal = privData->nativeObj->getInt32(localByteOffset, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - long retVal = privData->nativeObj->getInt32(localByteOffset, localLittleEndian); + long retVal = privData->nativeObj->getInt32(localByteOffset); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getInt32"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::getUint32Callback(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 getUint32"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsBoolean(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + + unsigned long retVal = privData->nativeObj->getUint32(localByteOffset, localLittleEndian); - unsigned long retVal = privData->nativeObj->getUint32(localByteOffset, localLittleEndian); + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + unsigned long retVal = privData->nativeObj->getUint32(localByteOffset); + + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getUint32"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::getFloat32Callback(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 getFloat32"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsBoolean(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + + float retVal = privData->nativeObj->getFloat32(localByteOffset, localLittleEndian); - float retVal = privData->nativeObj->getFloat32(localByteOffset, localLittleEndian); + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + float retVal = privData->nativeObj->getFloat32(localByteOffset); + + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getFloat32"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::getFloat64Callback(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 getFloat64"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsBoolean(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[1]); + + double retVal = privData->nativeObj->getFloat64(localByteOffset, localLittleEndian); - double retVal = privData->nativeObj->getFloat64(localByteOffset, localLittleEndian); + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + double retVal = privData->nativeObj->getFloat64(localByteOffset); + + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getFloat64"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setInt8Callback(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 setInt8"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); - privData->nativeObj->setInt8(localByteOffset, localValue); + privData->nativeObj->setInt8(localByteOffset, localValue); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setInt8"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setUint8Callback(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 setUint8"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned char localValue = (unsigned char)JSValueToNumber(ctx, arguments[1], exception); - privData->nativeObj->setUint8(localByteOffset, localValue); + privData->nativeObj->setUint8(localByteOffset, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setUint8"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setInt16Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in setInt16"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - short localValue = (short)JSValueToNumber(ctx, arguments[1], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); - - privData->nativeObj->setInt16(localByteOffset, localValue, localLittleEndian); + if (false) { + } else if (argumentCount == 3 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsBoolean(ctx, arguments[2])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + short localValue = (short)JSValueToNumber(ctx, arguments[1], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); + + privData->nativeObj->setInt16(localByteOffset, localValue, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + short localValue = (short)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->setInt16(localByteOffset, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setInt16"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setUint16Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in setUint16"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned short localValue = (unsigned short)JSValueToNumber(ctx, arguments[1], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); - - privData->nativeObj->setUint16(localByteOffset, localValue, localLittleEndian); + if (false) { + } else if (argumentCount == 3 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsBoolean(ctx, arguments[2])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned short localValue = (unsigned short)JSValueToNumber(ctx, arguments[1], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); + + privData->nativeObj->setUint16(localByteOffset, localValue, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned short localValue = (unsigned short)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->setUint16(localByteOffset, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setUint16"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setInt32Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in setInt32"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - long localValue = (long)JSValueToNumber(ctx, arguments[1], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); - - privData->nativeObj->setInt32(localByteOffset, localValue, localLittleEndian); + if (false) { + } else if (argumentCount == 3 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsBoolean(ctx, arguments[2])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + long localValue = (long)JSValueToNumber(ctx, arguments[1], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); + + privData->nativeObj->setInt32(localByteOffset, localValue, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + long localValue = (long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->setInt32(localByteOffset, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setInt32"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setUint32Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in setUint32"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned long localValue = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); - - privData->nativeObj->setUint32(localByteOffset, localValue, localLittleEndian); + if (false) { + } else if (argumentCount == 3 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsBoolean(ctx, arguments[2])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned long localValue = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); + + privData->nativeObj->setUint32(localByteOffset, localValue, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned long localValue = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->setUint32(localByteOffset, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setUint32"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setFloat32Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in setFloat32"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - float localValue = (float)JSValueToNumber(ctx, arguments[1], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); - - privData->nativeObj->setFloat32(localByteOffset, localValue, localLittleEndian); + if (false) { + } else if (argumentCount == 3 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsBoolean(ctx, arguments[2])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + float localValue = (float)JSValueToNumber(ctx, arguments[1], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); + + privData->nativeObj->setFloat32(localByteOffset, localValue, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + float localValue = (float)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->setFloat32(localByteOffset, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setFloat32"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDataView::setFloat64Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in setFloat64"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDataViewPrivate* privData = (struct JSCDataViewPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - double localValue = (double)JSValueToNumber(ctx, arguments[1], exception); - bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); - - privData->nativeObj->setFloat64(localByteOffset, localValue, localLittleEndian); + if (false) { + } else if (argumentCount == 3 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsBoolean(ctx, arguments[2])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + double localValue = (double)JSValueToNumber(ctx, arguments[1], exception); + bool localLittleEndian = JSValueToBoolean(ctx, arguments[2]); + + privData->nativeObj->setFloat64(localByteOffset, localValue, localLittleEndian); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + double localValue = (double)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->setFloat64(localByteOffset, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setFloat64"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } - } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.h index 4d37120..e63805a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDataView.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -56,6 +57,7 @@ public: static JSValueRef setFloat32Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef setFloat64Callback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSStaticValue staticValues[]; @@ -68,6 +70,8 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp index a7f170f..a80bad8 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocument.cpp @@ -57,7 +57,7 @@ JSValueRef JSCDocument::doctypeAttrGetter(JSContextRef ctx, JSObjectRef object, retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -74,7 +74,7 @@ JSValueRef JSCDocument::implementationAttrGetter(JSContextRef ctx, JSObjectRef o retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -91,496 +91,522 @@ JSValueRef JSCDocument::documentElementAttrGetter(JSContextRef ctx, JSObjectRef retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } + JSValueRef JSCDocument::createElementCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in createElement"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalTagName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localTagNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTagName); - char* localTagNameBuffer = new char[localTagNameMaxSize]; - JSStringGetUTF8CString(stringReflocalTagName, localTagNameBuffer, localTagNameMaxSize); - std::string localTagName(localTagNameBuffer); - JSStringRelease(stringReflocalTagName); - free(localTagNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalTagName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localTagNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTagName); + char* localTagNameBuffer = new char[localTagNameMaxSize]; + JSStringGetUTF8CString(stringReflocalTagName, localTagNameBuffer, localTagNameMaxSize); + std::string localTagName(localTagNameBuffer); + JSStringRelease(stringReflocalTagName); + free(localTagNameBuffer); - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElement(localTagName)); - JSClassRef retClass = JSCElement::getTmpl(); + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElement(localTagName)); + JSClassRef retClass = JSCElement::getTmpl(); - struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createElement"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createDocumentFragmentCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - Arabica::DOM::DocumentFragment<std::string>* retVal = new Arabica::DOM::DocumentFragment<std::string>(privData->nativeObj->createDocumentFragment()); - JSClassRef retClass = JSCDocumentFragment::getTmpl(); + Arabica::DOM::DocumentFragment<std::string>* retVal = new Arabica::DOM::DocumentFragment<std::string>(privData->nativeObj->createDocumentFragment()); + JSClassRef retClass = JSCDocumentFragment::getTmpl(); - struct JSCDocumentFragment::JSCDocumentFragmentPrivate* retPrivData = new JSCDocumentFragment::JSCDocumentFragmentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCDocumentFragment::JSCDocumentFragmentPrivate* retPrivData = new JSCDocumentFragment::JSCDocumentFragmentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createDocumentFragment"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createTextNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in createTextNode"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); - char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); - std::string localData(localDataBuffer); - JSStringRelease(stringReflocalData); - free(localDataBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); + char* localDataBuffer = new char[localDataMaxSize]; + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); + free(localDataBuffer); - Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->createTextNode(localData)); - JSClassRef retClass = JSCText::getTmpl(); + Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->createTextNode(localData)); + JSClassRef retClass = JSCText::getTmpl(); - struct JSCText::JSCTextPrivate* retPrivData = new JSCText::JSCTextPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCText::JSCTextPrivate* retPrivData = new JSCText::JSCTextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createTextNode"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createCommentCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in createComment"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); - char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); - std::string localData(localDataBuffer); - JSStringRelease(stringReflocalData); - free(localDataBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); + char* localDataBuffer = new char[localDataMaxSize]; + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); + free(localDataBuffer); - Arabica::DOM::Comment<std::string>* retVal = new Arabica::DOM::Comment<std::string>(privData->nativeObj->createComment(localData)); - JSClassRef retClass = JSCComment::getTmpl(); + Arabica::DOM::Comment<std::string>* retVal = new Arabica::DOM::Comment<std::string>(privData->nativeObj->createComment(localData)); + JSClassRef retClass = JSCComment::getTmpl(); - struct JSCComment::JSCCommentPrivate* retPrivData = new JSCComment::JSCCommentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCComment::JSCCommentPrivate* retPrivData = new JSCComment::JSCCommentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createComment"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createCDATASectionCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in createCDATASection"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); - char* localDataBuffer = new char[localDataMaxSize]; - JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); - std::string localData(localDataBuffer); - JSStringRelease(stringReflocalData); - free(localDataBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); + char* localDataBuffer = new char[localDataMaxSize]; + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); + free(localDataBuffer); - Arabica::DOM::CDATASection<std::string>* retVal = new Arabica::DOM::CDATASection<std::string>(privData->nativeObj->createCDATASection(localData)); - JSClassRef retClass = JSCCDATASection::getTmpl(); + Arabica::DOM::CDATASection<std::string>* retVal = new Arabica::DOM::CDATASection<std::string>(privData->nativeObj->createCDATASection(localData)); + JSClassRef retClass = JSCCDATASection::getTmpl(); - struct JSCCDATASection::JSCCDATASectionPrivate* retPrivData = new JSCCDATASection::JSCCDATASectionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCCDATASection::JSCCDATASectionPrivate* retPrivData = new JSCCDATASection::JSCCDATASectionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createCDATASection"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createProcessingInstructionCallback(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 createProcessingInstruction"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalTarget = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localTargetMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTarget); - char* localTargetBuffer = new char[localTargetMaxSize]; - JSStringGetUTF8CString(stringReflocalTarget, localTargetBuffer, localTargetMaxSize); - std::string localTarget(localTargetBuffer); - JSStringRelease(stringReflocalTarget); - free(localTargetBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalTarget = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localTargetMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTarget); + char* localTargetBuffer = new char[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, localDataMaxSize); - std::string localData(localDataBuffer); - JSStringRelease(stringReflocalData); - free(localDataBuffer); + JSStringRef stringReflocalData = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localDataMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalData); + char* localDataBuffer = new char[localDataMaxSize]; + JSStringGetUTF8CString(stringReflocalData, localDataBuffer, localDataMaxSize); + std::string localData(localDataBuffer); + JSStringRelease(stringReflocalData); + free(localDataBuffer); - Arabica::DOM::ProcessingInstruction<std::string>* retVal = new Arabica::DOM::ProcessingInstruction<std::string>(privData->nativeObj->createProcessingInstruction(localTarget, localData)); - JSClassRef retClass = JSCProcessingInstruction::getTmpl(); + Arabica::DOM::ProcessingInstruction<std::string>* retVal = new Arabica::DOM::ProcessingInstruction<std::string>(privData->nativeObj->createProcessingInstruction(localTarget, localData)); + JSClassRef retClass = JSCProcessingInstruction::getTmpl(); - struct JSCProcessingInstruction::JSCProcessingInstructionPrivate* retPrivData = new JSCProcessingInstruction::JSCProcessingInstructionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCProcessingInstruction::JSCProcessingInstructionPrivate* retPrivData = new JSCProcessingInstruction::JSCProcessingInstructionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createProcessingInstruction"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createAttributeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in createAttribute"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttribute(localName)); - JSClassRef retClass = JSCAttr::getTmpl(); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttribute(localName)); + JSClassRef retClass = JSCAttr::getTmpl(); - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createAttribute"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createEntityReferenceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in createEntityReference"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); - Arabica::DOM::EntityReference<std::string>* retVal = new Arabica::DOM::EntityReference<std::string>(privData->nativeObj->createEntityReference(localName)); - JSClassRef retClass = JSCEntityReference::getTmpl(); + Arabica::DOM::EntityReference<std::string>* retVal = new Arabica::DOM::EntityReference<std::string>(privData->nativeObj->createEntityReference(localName)); + JSClassRef retClass = JSCEntityReference::getTmpl(); - struct JSCEntityReference::JSCEntityReferencePrivate* retPrivData = new JSCEntityReference::JSCEntityReferencePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCEntityReference::JSCEntityReferencePrivate* retPrivData = new JSCEntityReference::JSCEntityReferencePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createEntityReference"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::getElementsByTagNameCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getElementsByTagName"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalTagname = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localTagnameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTagname); - char* localTagnameBuffer = new char[localTagnameMaxSize]; - JSStringGetUTF8CString(stringReflocalTagname, localTagnameBuffer, localTagnameMaxSize); - std::string localTagname(localTagnameBuffer); - JSStringRelease(stringReflocalTagname); - free(localTagnameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalTagname = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localTagnameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalTagname); + char* localTagnameBuffer = new char[localTagnameMaxSize]; + JSStringGetUTF8CString(stringReflocalTagname, localTagnameBuffer, localTagnameMaxSize); + std::string localTagname(localTagnameBuffer); + JSStringRelease(stringReflocalTagname); + free(localTagnameBuffer); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(localTagname)); - JSClassRef retClass = JSCNodeList::getTmpl(); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(localTagname)); + JSClassRef retClass = JSCNodeList::getTmpl(); - struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getElementsByTagName"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::importNodeCallback(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 importNode"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localImportedNode = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; - bool localDeep = JSValueToBoolean(ctx, arguments[1]); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCNode::getTmpl()) && + JSValueIsBoolean(ctx, arguments[1])) { + 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)); - JSClassRef retClass = JSCNode::getTmpl(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->importNode(*localImportedNode, localDeep)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling importNode"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createElementNSCallback(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 createElementNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); - JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); - char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; - JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); - std::string localQualifiedName(localQualifiedNameBuffer); - JSStringRelease(stringReflocalQualifiedName); - free(localQualifiedNameBuffer); + JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); + char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); + free(localQualifiedNameBuffer); - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(localNamespaceURI, localQualifiedName)); - JSClassRef retClass = JSCElement::getTmpl(); + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(localNamespaceURI, localQualifiedName)); + JSClassRef retClass = JSCElement::getTmpl(); - struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createElementNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::createAttributeNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 2) { - std::string errorMsg = "Wrong number of arguments in createAttributeNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); - JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); - char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; - JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); - std::string localQualifiedName(localQualifiedNameBuffer); - JSStringRelease(stringReflocalQualifiedName); - free(localQualifiedNameBuffer); + JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); + char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); + free(localQualifiedNameBuffer); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(localNamespaceURI, localQualifiedName)); - JSClassRef retClass = JSCAttr::getTmpl(); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(localNamespaceURI, localQualifiedName)); + JSClassRef retClass = JSCAttr::getTmpl(); - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling createAttributeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::getElementsByTagNameNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 2) { - std::string errorMsg = "Wrong number of arguments in getElementsByTagNameNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(localNamespaceURI, localLocalName)); - JSClassRef retClass = JSCNodeList::getTmpl(); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(localNamespaceURI, localLocalName)); + JSClassRef retClass = JSCNodeList::getTmpl(); - struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getElementsByTagNameNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCDocument::getElementByIdCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getElementById"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCDocumentPrivate* privData = (struct JSCDocumentPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalElementId = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localElementIdMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalElementId); - char* localElementIdBuffer = new char[localElementIdMaxSize]; - JSStringGetUTF8CString(stringReflocalElementId, localElementIdBuffer, localElementIdMaxSize); - std::string localElementId(localElementIdBuffer); - JSStringRelease(stringReflocalElementId); - free(localElementIdBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalElementId = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localElementIdMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalElementId); + char* localElementIdBuffer = new char[localElementIdMaxSize]; + JSStringGetUTF8CString(stringReflocalElementId, localElementIdBuffer, localElementIdMaxSize); + std::string localElementId(localElementIdBuffer); + JSStringRelease(stringReflocalElementId); + free(localElementIdBuffer); - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->getElementById(localElementId)); - JSClassRef retClass = JSCElement::getTmpl(); + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->getElementById(localElementId)); + JSClassRef retClass = JSCElement::getTmpl(); - struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCElement::JSCElementPrivate* retPrivData = new JSCElement::JSCElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getElementById"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp index 954f748..b57424f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDocumentType.cpp @@ -44,7 +44,7 @@ JSValueRef JSCDocumentType::entitiesAttrGetter(JSContextRef ctx, JSObjectRef obj retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -61,7 +61,7 @@ JSValueRef JSCDocumentType::notationsAttrGetter(JSContextRef ctx, JSObjectRef ob retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp index e0b403f..5bf50cf 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCElement.cpp @@ -42,507 +42,530 @@ JSValueRef JSCElement::tagNameAttrGetter(JSContextRef ctx, JSObjectRef object, J return retVal; } + JSValueRef JSCElement::getAttributeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getAttribute"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); - std::string retVal = privData->nativeObj->getAttribute(localName); + std::string retVal = privData->nativeObj->getAttribute(localName); + + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; + } - JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); - JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); - JSStringRelease(jscString); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getAttribute"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::setAttributeCallback(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 setAttribute"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[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, localValueMaxSize); - std::string localValue(localValueBuffer); - JSStringRelease(stringReflocalValue); - free(localValueBuffer); - - - privData->nativeObj->setAttribute(localName, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[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, localValueMaxSize); + std::string localValue(localValueBuffer); + JSStringRelease(stringReflocalValue); + free(localValueBuffer); + + + privData->nativeObj->setAttribute(localName, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setAttribute"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::removeAttributeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in removeAttribute"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); - privData->nativeObj->removeAttribute(localName); + privData->nativeObj->removeAttribute(localName); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling removeAttribute"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::getAttributeNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getAttributeNode"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNode(localName)); - JSClassRef retClass = JSCAttr::getTmpl(); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNode(localName)); + JSClassRef retClass = JSCAttr::getTmpl(); - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getAttributeNode"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::setAttributeNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in setAttributeNode"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Attr<std::string>* localNewAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + if (false) { + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCAttr::getTmpl())) { + 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(); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNode(*localNewAttr)); + JSClassRef retClass = JSCAttr::getTmpl(); - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setAttributeNode"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::removeAttributeNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in removeAttributeNode"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Attr<std::string>* localOldAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + if (false) { + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCAttr::getTmpl())) { + 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(); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->removeAttributeNode(*localOldAttr)); - JSClassRef retClass = JSCAttr::getTmpl(); + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling removeAttributeNode"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::getElementsByTagNameCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getElementsByTagName"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); + + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(localName)); + JSClassRef retClass = JSCNodeList::getTmpl(); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(localName)); - JSClassRef retClass = JSCNodeList::getTmpl(); + struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getElementsByTagName"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::getAttributeNSCallback(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 getAttributeNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); - - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); - - - std::string retVal = privData->nativeObj->getAttributeNS(localNamespaceURI, localLocalName); - - JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); - JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); - JSStringRelease(jscString); - return jscRetVal; + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); + + + std::string retVal = privData->nativeObj->getAttributeNS(localNamespaceURI, localLocalName); + + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getAttributeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::setAttributeNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 3) { - std::string errorMsg = "Wrong number of arguments in setAttributeNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); - - JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); - char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; - JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); - std::string localQualifiedName(localQualifiedNameBuffer); - JSStringRelease(stringReflocalQualifiedName); - free(localQualifiedNameBuffer); - - JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, arguments[2], exception); - size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); - char* localValueBuffer = new char[localValueMaxSize]; - JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); - std::string localValue(localValueBuffer); - JSStringRelease(stringReflocalValue); - free(localValueBuffer); - - - privData->nativeObj->setAttributeNS(localNamespaceURI, localQualifiedName, localValue); - - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + if (false) { + } else if (argumentCount == 3 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1]) && + JSValueIsString(ctx, arguments[2])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalQualifiedName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localQualifiedNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalQualifiedName); + char* localQualifiedNameBuffer = new char[localQualifiedNameMaxSize]; + JSStringGetUTF8CString(stringReflocalQualifiedName, localQualifiedNameBuffer, localQualifiedNameMaxSize); + std::string localQualifiedName(localQualifiedNameBuffer); + JSStringRelease(stringReflocalQualifiedName); + free(localQualifiedNameBuffer); + + JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, arguments[2], exception); + size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); + char* localValueBuffer = new char[localValueMaxSize]; + JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); + std::string localValue(localValueBuffer); + JSStringRelease(stringReflocalValue); + free(localValueBuffer); + + + privData->nativeObj->setAttributeNS(localNamespaceURI, localQualifiedName, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setAttributeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::removeAttributeNSCallback(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 removeAttributeNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); - - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); - - - privData->nativeObj->removeAttributeNS(localNamespaceURI, localLocalName); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); + + + privData->nativeObj->removeAttributeNS(localNamespaceURI, localLocalName); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling removeAttributeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::getAttributeNodeNSCallback(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 getAttributeNodeNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNodeNS(localNamespaceURI, localLocalName)); + JSClassRef retClass = JSCAttr::getTmpl(); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNodeNS(localNamespaceURI, localLocalName)); - JSClassRef retClass = JSCAttr::getTmpl(); + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getAttributeNodeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::setAttributeNodeNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in setAttributeNodeNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Attr<std::string>* localNewAttr = ((struct JSCAttr::JSCAttrPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + if (false) { + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCAttr::getTmpl())) { + 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(); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); - JSClassRef retClass = JSCAttr::getTmpl(); + struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCAttr::JSCAttrPrivate* retPrivData = new JSCAttr::JSCAttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setAttributeNodeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::getElementsByTagNameNSCallback(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 getElementsByTagNameNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(localNamespaceURI, localLocalName)); - JSClassRef retClass = JSCNodeList::getTmpl(); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(localNamespaceURI, localLocalName)); + JSClassRef retClass = JSCNodeList::getTmpl(); - struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNodeList::JSCNodeListPrivate* retPrivData = new JSCNodeList::JSCNodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getElementsByTagNameNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::hasAttributeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in hasAttribute"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); + + bool retVal = privData->nativeObj->hasAttribute(localName); - bool retVal = privData->nativeObj->hasAttribute(localName); + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling hasAttribute"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCElement::hasAttributeNSCallback(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 hasAttributeNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCElementPrivate* privData = (struct JSCElementPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); - - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); - - - bool retVal = privData->nativeObj->hasAttributeNS(localNamespaceURI, localLocalName); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); + + + bool retVal = privData->nativeObj->hasAttributeNS(localNamespaceURI, localLocalName); + + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling hasAttributeNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } - } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp index f22ba32..8b2c8ef 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCFloat32Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCFloat32Array::staticValues[] = { JSStaticFunction JSCFloat32Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCFloat32Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Float32Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Float32Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Float32Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat32Array::getTmpl())) { + + uscxml::Float32Array* localArray = ((struct JSCFloat32Array::JSCFloat32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Float32Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Float32Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Float32Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<float> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Float32Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Float32Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCFloat32Array::getTmpl(); + + struct JSCFloat32Array::JSCFloat32ArrayPrivate* retPrivData = new JSCFloat32Array::JSCFloat32ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCFloat32Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCFloat32ArrayPrivate* privData = (struct JSCFloat32ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCFloat32Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObj return JSValueMakeNumber(ctx, 4); } + JSValueRef JSCFloat32Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat32ArrayPrivate* privData = (struct JSCFloat32ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - float retVal = privData->nativeObj->get(localIndex); + float retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCFloat32Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat32ArrayPrivate* privData = (struct JSCFloat32ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - float localValue = (float)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat32Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Float32Array* localArray = ((struct JSCFloat32Array::JSCFloat32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + float localValue = (float)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<float> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat32Array::getTmpl())) { + uscxml::Float32Array* localArray = ((struct JSCFloat32Array::JSCFloat32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<float> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCFloat32Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat32ArrayPrivate* privData = (struct JSCFloat32ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Float32Array* retVal = new uscxml::Float32Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCFloat32Array::getTmpl(); + uscxml::Float32Array* retVal = new uscxml::Float32Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCFloat32Array::getTmpl(); - struct JSCFloat32Array::JSCFloat32ArrayPrivate* retPrivData = new JSCFloat32Array::JSCFloat32ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCFloat32Array::JSCFloat32ArrayPrivate* retPrivData = new JSCFloat32Array::JSCFloat32ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.h index 21d4c59..62fce52 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat32Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp index 06ca510..2bf524c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCFloat64Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCFloat64Array::staticValues[] = { JSStaticFunction JSCFloat64Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCFloat64Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Float64Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Float64Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Float64Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat64Array::getTmpl())) { + + uscxml::Float64Array* localArray = ((struct JSCFloat64Array::JSCFloat64ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Float64Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Float64Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Float64Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<double> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Float64Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Float64Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCFloat64Array::getTmpl(); + + struct JSCFloat64Array::JSCFloat64ArrayPrivate* retPrivData = new JSCFloat64Array::JSCFloat64ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCFloat64Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCFloat64Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObj return JSValueMakeNumber(ctx, 8); } + JSValueRef JSCFloat64Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - double retVal = privData->nativeObj->get(localIndex); + double retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCFloat64Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - double localValue = (double)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat64Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Float64Array* localArray = ((struct JSCFloat64Array::JSCFloat64ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + double localValue = (double)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<double> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCFloat64Array::getTmpl())) { + uscxml::Float64Array* localArray = ((struct JSCFloat64Array::JSCFloat64ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<double> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCFloat64Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCFloat64ArrayPrivate* privData = (struct JSCFloat64ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCFloat64Array::getTmpl(); + uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCFloat64Array::getTmpl(); - struct JSCFloat64Array::JSCFloat64ArrayPrivate* retPrivData = new JSCFloat64Array::JSCFloat64ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCFloat64Array::JSCFloat64ArrayPrivate* retPrivData = new JSCFloat64Array::JSCFloat64ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.h index f21962d..3b8fb44 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCFloat64Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp index 2844b75..f0ca42a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCInt16Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCInt16Array::staticValues[] = { JSStaticFunction JSCInt16Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCInt16Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Int16Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Int16Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Int16Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl())) { + + uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Int16Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Int16Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Int16Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<short> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Int16Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Int16Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCInt16Array::getTmpl(); + + struct JSCInt16Array::JSCInt16ArrayPrivate* retPrivData = new JSCInt16Array::JSCInt16ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCInt16Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCInt16ArrayPrivate* privData = (struct JSCInt16ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCInt16Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObjec return JSValueMakeNumber(ctx, 2); } + JSValueRef JSCInt16Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt16ArrayPrivate* privData = (struct JSCInt16ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - short retVal = privData->nativeObj->get(localIndex); + short retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCInt16Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt16ArrayPrivate* privData = (struct JSCInt16ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - short localValue = (short)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + short localValue = (short)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<short> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt16Array::getTmpl())) { + uscxml::Int16Array* localArray = ((struct JSCInt16Array::JSCInt16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<short> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCInt16Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt16ArrayPrivate* privData = (struct JSCInt16ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Int16Array* retVal = new uscxml::Int16Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCInt16Array::getTmpl(); + uscxml::Int16Array* retVal = new uscxml::Int16Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCInt16Array::getTmpl(); - struct JSCInt16Array::JSCInt16ArrayPrivate* retPrivData = new JSCInt16Array::JSCInt16ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCInt16Array::JSCInt16ArrayPrivate* retPrivData = new JSCInt16Array::JSCInt16ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.h index 7510336..992984e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt16Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp index 09d8f76..b10fa96 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCInt32Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCInt32Array::staticValues[] = { JSStaticFunction JSCInt32Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCInt32Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Int32Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Int32Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Int32Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt32Array::getTmpl())) { + + uscxml::Int32Array* localArray = ((struct JSCInt32Array::JSCInt32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Int32Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Int32Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Int32Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<long> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Int32Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Int32Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCInt32Array::getTmpl(); + + struct JSCInt32Array::JSCInt32ArrayPrivate* retPrivData = new JSCInt32Array::JSCInt32ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCInt32Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCInt32Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObjec return JSValueMakeNumber(ctx, 4); } + JSValueRef JSCInt32Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - long retVal = privData->nativeObj->get(localIndex); + long retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCInt32Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - long localValue = (long)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt32Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Int32Array* localArray = ((struct JSCInt32Array::JSCInt32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + long localValue = (long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<long> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt32Array::getTmpl())) { + uscxml::Int32Array* localArray = ((struct JSCInt32Array::JSCInt32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<long> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCInt32Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt32ArrayPrivate* privData = (struct JSCInt32ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Int32Array* retVal = new uscxml::Int32Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCInt32Array::getTmpl(); + uscxml::Int32Array* retVal = new uscxml::Int32Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCInt32Array::getTmpl(); - struct JSCInt32Array::JSCInt32ArrayPrivate* retPrivData = new JSCInt32Array::JSCInt32ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCInt32Array::JSCInt32ArrayPrivate* retPrivData = new JSCInt32Array::JSCInt32ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.h index 901eb3c..0174759 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt32Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp index 509481e..00c717c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCInt8Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCInt8Array::staticValues[] = { JSStaticFunction JSCInt8Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCInt8Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Int8Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Int8Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Int8Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt8Array::getTmpl())) { + + uscxml::Int8Array* localArray = ((struct JSCInt8Array::JSCInt8ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Int8Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Int8Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Int8Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Int8Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Int8Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCInt8Array::getTmpl(); + + struct JSCInt8Array::JSCInt8ArrayPrivate* retPrivData = new JSCInt8Array::JSCInt8ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCInt8Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCInt8Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObject return JSValueMakeNumber(ctx, 1); } + JSValueRef JSCInt8Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - char retVal = privData->nativeObj->get(localIndex); + char retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCInt8Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt8Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Int8Array* localArray = ((struct JSCInt8Array::JSCInt8ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCInt8Array::getTmpl())) { + uscxml::Int8Array* localArray = ((struct JSCInt8Array::JSCInt8ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCInt8Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCInt8ArrayPrivate* privData = (struct JSCInt8ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Int8Array* retVal = new uscxml::Int8Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCInt8Array::getTmpl(); + uscxml::Int8Array* retVal = new uscxml::Int8Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCInt8Array::getTmpl(); - struct JSCInt8Array::JSCInt8ArrayPrivate* retPrivData = new JSCInt8Array::JSCInt8ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCInt8Array::JSCInt8ArrayPrivate* retPrivData = new JSCInt8Array::JSCInt8ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.h index a693f2a..6d24a03 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCInt8Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::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 c72b27b..4efde43 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNamedNodeMap.cpp @@ -29,239 +29,248 @@ JSValueRef JSCNamedNodeMap::lengthAttrGetter(JSContextRef ctx, JSObjectRef objec return JSValueMakeNumber(ctx, privData->nativeObj->getLength()); } + JSValueRef JSCNamedNodeMap::getNamedItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getNamedItem"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); + + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItem(localName)); + JSClassRef retClass = JSCNode::getTmpl(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItem(localName)); - JSClassRef retClass = JSCNode::getTmpl(); + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getNamedItem"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNamedNodeMap::setNamedItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in setNamedItem"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localArg = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + if (false) { + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCNode::getTmpl())) { + 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(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItem(*localArg)); - JSClassRef retClass = JSCNode::getTmpl(); + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setNamedItem"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNamedNodeMap::removeNamedItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in removeNamedItem"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); - char* localNameBuffer = new char[localNameMaxSize]; - JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); - std::string localName(localNameBuffer); - JSStringRelease(stringReflocalName); - free(localNameBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalName = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalName); + char* localNameBuffer = new char[localNameMaxSize]; + JSStringGetUTF8CString(stringReflocalName, localNameBuffer, localNameMaxSize); + std::string localName(localNameBuffer); + JSStringRelease(stringReflocalName); + free(localNameBuffer); + + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItem(localName)); + JSClassRef retClass = JSCNode::getTmpl(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItem(localName)); - JSClassRef retClass = JSCNode::getTmpl(); + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling removeNamedItem"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNamedNodeMap::itemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in item"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); - JSClassRef retClass = JSCNode::getTmpl(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling item"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNamedNodeMap::getNamedItemNSCallback(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 getNamedItemNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); + + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItemNS(localNamespaceURI, localLocalName)); + JSClassRef retClass = JSCNode::getTmpl(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItemNS(localNamespaceURI, localLocalName)); - JSClassRef retClass = JSCNode::getTmpl(); + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getNamedItemNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNamedNodeMap::setNamedItemNSCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in setNamedItemNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localArg = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + if (false) { + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCNode::getTmpl())) { + 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(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItemNS(*localArg)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setNamedItemNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNamedNodeMap::removeNamedItemNSCallback(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 removeNamedItemNS"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNamedNodeMapPrivate* privData = (struct JSCNamedNodeMapPrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); - char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; - JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); - std::string localNamespaceURI(localNamespaceURIBuffer); - JSStringRelease(stringReflocalNamespaceURI); - free(localNamespaceURIBuffer); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalNamespaceURI = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localNamespaceURIMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalNamespaceURI); + char* localNamespaceURIBuffer = new char[localNamespaceURIMaxSize]; + JSStringGetUTF8CString(stringReflocalNamespaceURI, localNamespaceURIBuffer, localNamespaceURIMaxSize); + std::string localNamespaceURI(localNamespaceURIBuffer); + JSStringRelease(stringReflocalNamespaceURI); + free(localNamespaceURIBuffer); - JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); - char* localLocalNameBuffer = new char[localLocalNameMaxSize]; - JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); - std::string localLocalName(localLocalNameBuffer); - JSStringRelease(stringReflocalLocalName); - free(localLocalNameBuffer); + JSStringRef stringReflocalLocalName = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localLocalNameMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalLocalName); + char* localLocalNameBuffer = new char[localLocalNameMaxSize]; + JSStringGetUTF8CString(stringReflocalLocalName, localLocalNameBuffer, localLocalNameMaxSize); + std::string localLocalName(localLocalNameBuffer); + JSStringRelease(stringReflocalLocalName); + free(localLocalNameBuffer); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItemNS(localNamespaceURI, localLocalName)); - JSClassRef retClass = JSCNode::getTmpl(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItemNS(localNamespaceURI, localLocalName)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling removeNamedItemNS"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp index 22d048c..2abf023 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp @@ -105,7 +105,7 @@ JSValueRef JSCNode::parentNodeAttrGetter(JSContextRef ctx, JSObjectRef object, J retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -122,7 +122,7 @@ JSValueRef JSCNode::childNodesAttrGetter(JSContextRef ctx, JSObjectRef object, J retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -139,7 +139,7 @@ JSValueRef JSCNode::firstChildAttrGetter(JSContextRef ctx, JSObjectRef object, J retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -156,7 +156,7 @@ JSValueRef JSCNode::lastChildAttrGetter(JSContextRef ctx, JSObjectRef object, JS retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -173,7 +173,7 @@ JSValueRef JSCNode::previousSiblingAttrGetter(JSContextRef ctx, JSObjectRef obje retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -190,7 +190,7 @@ JSValueRef JSCNode::nextSiblingAttrGetter(JSContextRef ctx, JSObjectRef object, retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -207,7 +207,7 @@ JSValueRef JSCNode::ownerDocumentAttrGetter(JSContextRef ctx, JSObjectRef object retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } @@ -304,211 +304,244 @@ JSValueRef JSCNode::NOTATION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisO 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"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - 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; + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCNode::getTmpl()) && + JSValueIsObject(ctx, arguments[1]) && JSValueIsObjectOfClass(ctx, arguments[1], JSCNode::getTmpl())) { + 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(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling insertBefore"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::replaceChildCallback(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 replaceChild"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - 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; + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCNode::getTmpl()) && + JSValueIsObject(ctx, arguments[1]) && JSValueIsObjectOfClass(ctx, arguments[1], JSCNode::getTmpl())) { + 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(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling replaceChild"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::removeChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in removeChild"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localOldChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + if (false) { + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCNode::getTmpl())) { + 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(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeChild(*localOldChild)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling removeChild"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::appendChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in appendChild"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - Arabica::DOM::Node<std::string>* localNewChild = ((struct JSCNode::JSCNodePrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + if (false) { + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCNode::getTmpl())) { + 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(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->appendChild(*localNewChild)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling appendChild"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::hasChildNodesCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - bool retVal = privData->nativeObj->hasChildNodes(); + bool retVal = privData->nativeObj->hasChildNodes(); - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling hasChildNodes"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::cloneNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in cloneNode"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - bool localDeep = JSValueToBoolean(ctx, arguments[0]); + if (false) { + } else if (argumentCount == 1 && + JSValueIsBoolean(ctx, arguments[0])) { + bool localDeep = JSValueToBoolean(ctx, arguments[0]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->cloneNode(localDeep)); - JSClassRef retClass = JSCNode::getTmpl(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->cloneNode(localDeep)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling cloneNode"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::normalizeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - privData->nativeObj->normalize(); + privData->nativeObj->normalize(); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling normalize"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::isSupportedCallback(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 isSupported"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalFeature = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localFeatureMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalFeature); - char* localFeatureBuffer = new char[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, localVersionMaxSize); - std::string localVersion(localVersionBuffer); - JSStringRelease(stringReflocalVersion); - free(localVersionBuffer); - - - bool retVal = privData->nativeObj->isSupported(localFeature, localVersion); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalFeature = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localFeatureMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalFeature); + char* localFeatureBuffer = new char[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, localVersionMaxSize); + std::string localVersion(localVersionBuffer); + JSStringRelease(stringReflocalVersion); + free(localVersionBuffer); + + + bool retVal = privData->nativeObj->isSupported(localFeature, localVersion); + + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling isSupported"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCNode::hasAttributesCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCNodePrivate* privData = (struct JSCNodePrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - bool retVal = privData->nativeObj->hasAttributes(); + bool retVal = privData->nativeObj->hasAttributes(); - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; -} + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling hasAttributes"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp index b6e5723..793e989 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeList.cpp @@ -23,33 +23,34 @@ JSValueRef JSCNodeList::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, J return JSValueMakeNumber(ctx, privData->nativeObj->getLength()); } + JSValueRef JSCNodeList::itemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in item"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCNodeListPrivate* privData = (struct JSCNodeListPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); - JSClassRef retClass = JSCNode::getTmpl(); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); + JSClassRef retClass = JSCNode::getTmpl(); - struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCNode::JSCNodePrivate* retPrivData = new JSCNode::JSCNodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling item"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp index adb366e..547288b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeListCustom.cpp @@ -76,49 +76,5 @@ JSValueRef JSCNodeList::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef 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(); - V8NodeListPrivate* privData = V8DOM::toClassPtr<V8NodeListPrivate >(self->GetInternalField(0)); - - if (privData->nativeObj->getLength() >= index) { - 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)); - - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; - } - default: { - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(index)); - - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::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 3aad9a4..ea7e64b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNodeSet.cpp @@ -30,17 +30,25 @@ JSValueRef JSCNodeSet::emptyAttrGetter(JSContextRef ctx, JSObjectRef object, JSS return JSValueMakeBoolean(ctx, privData->nativeObj->empty()); } + JSValueRef JSCNodeSet::toDocumentOrderCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCNodeSetPrivate* privData = (struct JSCNodeSetPrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - privData->nativeObj->to_document_order(); + privData->nativeObj->to_document_order(); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; -} + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling toDocumentOrder"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp index de3a93f..9a7b8bb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCSCXMLEvent.cpp @@ -84,7 +84,7 @@ JSValueRef JSCSCXMLEvent::domAttrGetter(JSContextRef ctx, JSObjectRef object, JS retPrivData->dom = privData->dom; retPrivData->nativeObj = arabicaRet; - JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, arabicaRet); + JSObjectRef arbaicaRetObj = JSObjectMake(ctx, arbaicaRetClass, retPrivData); return arbaicaRetObj; } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp index f3c709b..4ad6f74 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp @@ -26,130 +26,143 @@ JSValueRef JSCStorage::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JS return JSValueMakeNumber(ctx, privData->nativeObj->getLength()); } + JSValueRef JSCStorage::keyCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in key"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - std::string retVal = privData->nativeObj->key(localIndex); + std::string retVal = privData->nativeObj->key(localIndex); - JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); - JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); - JSStringRelease(jscString); - return jscRetVal; + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling key"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCStorage::getItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in getItem"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); - char* localKeyBuffer = new char[localKeyMaxSize]; - JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); - std::string localKey(localKeyBuffer); - JSStringRelease(stringReflocalKey); - free(localKeyBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); + char* localKeyBuffer = new char[localKeyMaxSize]; + JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); + std::string localKey(localKeyBuffer); + JSStringRelease(stringReflocalKey); + free(localKeyBuffer); - std::string retVal = privData->nativeObj->getItem(localKey); + std::string retVal = privData->nativeObj->getItem(localKey); - JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); - JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); - JSStringRelease(jscString); - return jscRetVal; + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling getItem"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCStorage::setItemCallback(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 setItem"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); - char* localKeyBuffer = new char[localKeyMaxSize]; - JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); - std::string localKey(localKeyBuffer); - JSStringRelease(stringReflocalKey); - free(localKeyBuffer); - - JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, arguments[1], exception); - size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); - char* localValueBuffer = new char[localValueMaxSize]; - JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); - std::string localValue(localValueBuffer); - JSStringRelease(stringReflocalValue); - free(localValueBuffer); - - - privData->nativeObj->setItem(localKey, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsString(ctx, arguments[0]) && + JSValueIsString(ctx, arguments[1])) { + JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); + char* localKeyBuffer = new char[localKeyMaxSize]; + JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); + std::string localKey(localKeyBuffer); + JSStringRelease(stringReflocalKey); + free(localKeyBuffer); + + JSStringRef stringReflocalValue = JSValueToStringCopy(ctx, arguments[1], exception); + size_t localValueMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalValue); + char* localValueBuffer = new char[localValueMaxSize]; + JSStringGetUTF8CString(stringReflocalValue, localValueBuffer, localValueMaxSize); + std::string localValue(localValueBuffer); + JSStringRelease(stringReflocalValue); + free(localValueBuffer); + + + privData->nativeObj->setItem(localKey, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling setItem"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCStorage::removeItemCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in removeItem"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); - JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); - size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); - char* localKeyBuffer = new char[localKeyMaxSize]; - JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); - std::string localKey(localKeyBuffer); - JSStringRelease(stringReflocalKey); - free(localKeyBuffer); + if (false) { + } else if (argumentCount == 1 && + JSValueIsString(ctx, arguments[0])) { + JSStringRef stringReflocalKey = JSValueToStringCopy(ctx, arguments[0], exception); + size_t localKeyMaxSize = JSStringGetMaximumUTF8CStringSize(stringReflocalKey); + char* localKeyBuffer = new char[localKeyMaxSize]; + JSStringGetUTF8CString(stringReflocalKey, localKeyBuffer, localKeyMaxSize); + std::string localKey(localKeyBuffer); + JSStringRelease(stringReflocalKey); + free(localKeyBuffer); - privData->nativeObj->removeItem(localKey); + privData->nativeObj->removeItem(localKey); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling removeItem"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCStorage::clearCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCStoragePrivate* privData = (struct JSCStoragePrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - privData->nativeObj->clear(); + privData->nativeObj->clear(); - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; -} + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling clear"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp index ba0b992..84ff887 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCText.cpp @@ -15,33 +15,34 @@ JSStaticFunction JSCText::staticFunctions[] = { { "splitText", splitTextCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; + JSValueRef JSCText::splitTextCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in splitText"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCTextPrivate* privData = (struct JSCTextPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->splitText(localOffset)); - JSClassRef retClass = JSCText::getTmpl(); + Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->splitText(localOffset)); + JSClassRef retClass = JSCText::getTmpl(); - struct JSCText::JSCTextPrivate* retPrivData = new JSCText::JSCTextPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCText::JSCTextPrivate* retPrivData = new JSCText::JSCTextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling splitText"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCTypedArrayCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCTypedArrayCustom.cpp new file mode 100644 index 0000000..4ef0b8e --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCTypedArrayCustom.cpp @@ -0,0 +1,243 @@ +#include "../../TypedArray.h" +#include "JSCArrayBuffer.h" +#include "JSCInt8Array.h" +#include "JSCUint8Array.h" +#include "JSCUint8ClampedArray.h" +#include "JSCInt16Array.h" +#include "JSCUint16Array.h" +#include "JSCInt32Array.h" +#include "JSCUint32Array.h" +#include "JSCFloat32Array.h" +#include "JSCFloat64Array.h" +#include "JSCDataView.h" + +#define JSC_VALUE_TO_STRING(name, stringName)\ +size_t name##MaxSize = JSStringGetMaximumUTF8CStringSize(name);\ +char* name##Buffer = new char[name##MaxSize];\ +JSStringGetUTF8CString(name, name##Buffer, name##MaxSize);\ +std::string stringName(name##Buffer);\ +free(name##Buffer);\ + + +#define JSC_TYPED_ARRAY_GET_PROP_RETURN(type)\ +size_t propMaxSize = JSStringGetMaximumUTF8CStringSize(propertyName);\ +char* propBuffer = new char[propMaxSize];\ +JSStringGetUTF8CString(propertyName, propBuffer, propMaxSize);\ +std::string propName(propBuffer);\ +free(propBuffer);\ +if (strcmp(propName.c_str(), "prototype") == 0) {\ + JSStringRef prototypeName = JSStringCreateWithUTF8CString(#type);\ + JSValueRef prototype = JSObjectGetProperty(ctx, JSContextGetGlobalObject(ctx), prototypeName, exception);\ + assert(!JSValueIsUndefined(ctx, prototype) && !JSValueIsNull(ctx, prototype));\ + JSStringRelease(prototypeName);\ + return prototype;\ +}\ +JSStaticValue* prop = JSC##type::staticValues;\ +while(prop->name) {\ + if (strcmp(propName.c_str(), prop->name) == 0) {\ + return (prop->getProperty)(ctx, object, propertyName, exception);\ + }\ + prop++;\ +}\ +\ +JSC##type::JSC##type##Private* privObj = (JSC##type::JSC##type##Private*)JSObjectGetPrivate(object);\ +if (!privObj)\ + return JSValueMakeUndefined(ctx);\ +\ +uscxml::type* array = ((JSC##type::JSC##type##Private*)JSObjectGetPrivate(object))->nativeObj;\ +std::string base = "0123456789";\ +if (propName.find_first_not_of(base) != std::string::npos) {\ + return JSValueMakeUndefined(ctx);\ +}\ +unsigned long index = boost::lexical_cast<unsigned long>(propName);\ +return JSValueMakeNumber(ctx, array->get(index)); + + + +#define JSC_TYPED_ARRAY_SET_PROP_RETURN(type)\ +if (!JSValueIsNumber(ctx, value)) {\ + return false;\ +}\ +size_t propMaxSize = JSStringGetMaximumUTF8CStringSize(propertyName);\ +char* propBuffer = new char[propMaxSize];\ +JSStringGetUTF8CString(propertyName, propBuffer, propMaxSize);\ +std::string propName(propBuffer);\ +free(propBuffer);\ +uscxml::type* array = ((JSC##type::JSC##type##Private*)JSObjectGetPrivate(object))->nativeObj;\ +std::string base = "0123456789";\ +if (propName.find_first_not_of(base) != std::string::npos) {\ + return JSValueMakeUndefined(ctx);\ +}\ +unsigned long index = boost::lexical_cast<unsigned long>(propName);\ +if (index >= array->getLength()) {\ + return false;\ +}\ +array->set(index, JSValueToNumber(ctx, value, exception));\ +return true; + + +#define JSC_TYPED_ARRAY_HAS_PROP_RETURN(type)\ +size_t propertyNameMaxSize = JSStringGetMaximumUTF8CStringSize(propertyName);\ +char* propertyNameBuffer = new char[propertyNameMaxSize];\ +JSStringGetUTF8CString(propertyName, propertyNameBuffer, propertyNameMaxSize);\ +std::string propName(propertyNameBuffer);\ +free(propertyNameBuffer);\ +\ +if (strcmp(propName.c_str(), "prototype") == 0)\ + return true;\ +\ +if (strcmp(propName.c_str(), "length") == 0)\ + return true;\ +\ +JSStaticValue* prop = JSC##type::staticValues;\ +while(prop->name) {\ + if (strcmp(propName.c_str(), prop->name) == 0) {\ + return true;\ + }\ + prop++;\ +}\ +\ +JSC##type::JSC##type##Private* privObj = (JSC##type::JSC##type##Private*)JSObjectGetPrivate(object);\ +if (!privObj)\ + return false;\ +\ +uscxml::type* array = ((JSC##type::JSC##type##Private*)JSObjectGetPrivate(object))->nativeObj;\ +std::string base = "0123456789";\ +if (propName.find_first_not_of(base) != std::string::npos) {\ + return false;\ +}\ +unsigned long index = boost::lexical_cast<unsigned long>(propName);\ +if (array->getLength() > index)\ + return true;\ +return false;\ + +namespace Arabica { +namespace DOM { + +bool JSCInt8Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Int8Array); +} + +bool JSCInt16Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Int16Array); +} + +bool JSCInt32Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Int32Array); +} + +bool JSCUint8Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Uint8Array); +} + +bool JSCUint16Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Uint16Array); +} + +bool JSCUint32Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Uint32Array); +} + +bool JSCFloat32Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Float32Array); +} + +bool JSCFloat64Array::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Float64Array); +} + +bool JSCUint8ClampedArray::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(Uint8ClampedArray); +} + +bool JSCArrayBuffer::hasPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName) { + JSC_TYPED_ARRAY_HAS_PROP_RETURN(ArrayBuffer); +} + +// ----------------- + +JSValueRef JSCInt8Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Int8Array); +} + +JSValueRef JSCInt16Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Int16Array); +} + +JSValueRef JSCInt32Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Int32Array); +} + +JSValueRef JSCUint8Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Uint8Array); +} + +JSValueRef JSCUint16Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Uint16Array); +} + +JSValueRef JSCUint32Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Uint32Array); +} + +JSValueRef JSCFloat32Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Float32Array); +} + +JSValueRef JSCFloat64Array::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Float64Array); +} + +JSValueRef JSCUint8ClampedArray::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(Uint8ClampedArray); +} + +JSValueRef JSCArrayBuffer::getPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef* exception) { + JSC_TYPED_ARRAY_GET_PROP_RETURN(ArrayBuffer); +} + +// ---------------- + +bool JSCInt8Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Int8Array); +} + +bool JSCInt16Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Int16Array); +} + +bool JSCInt32Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Int32Array); +} + +bool JSCUint8Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Uint8Array); +} + +bool JSCUint16Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Uint16Array); +} + +bool JSCUint32Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Uint32Array); +} + +bool JSCFloat32Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Float32Array); +} + +bool JSCFloat64Array::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Float64Array); +} + +bool JSCUint8ClampedArray::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(Uint8ClampedArray); +} + +bool JSCArrayBuffer::setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { + JSC_TYPED_ARRAY_SET_PROP_RETURN(ArrayBuffer); +} + + +} +}
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp index 88e71d6..3ea7177 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCUint16Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCUint16Array::staticValues[] = { JSStaticFunction JSCUint16Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCUint16Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Uint16Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Uint16Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Uint16Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint16Array::getTmpl())) { + + uscxml::Uint16Array* localArray = ((struct JSCUint16Array::JSCUint16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint16Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint16Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Uint16Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<unsigned short> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Uint16Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Uint16Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCUint16Array::getTmpl(); + + struct JSCUint16Array::JSCUint16ArrayPrivate* retPrivData = new JSCUint16Array::JSCUint16ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCUint16Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCUint16ArrayPrivate* privData = (struct JSCUint16ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCUint16Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObje return JSValueMakeNumber(ctx, 2); } + JSValueRef JSCUint16Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint16ArrayPrivate* privData = (struct JSCUint16ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned short retVal = privData->nativeObj->get(localIndex); + unsigned short retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint16Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint16ArrayPrivate* privData = (struct JSCUint16ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned short localValue = (unsigned short)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint16Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Uint16Array* localArray = ((struct JSCUint16Array::JSCUint16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned short localValue = (unsigned short)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<unsigned short> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint16Array::getTmpl())) { + uscxml::Uint16Array* localArray = ((struct JSCUint16Array::JSCUint16ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<unsigned short> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint16Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint16ArrayPrivate* privData = (struct JSCUint16ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Uint16Array* retVal = new uscxml::Uint16Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCUint16Array::getTmpl(); + uscxml::Uint16Array* retVal = new uscxml::Uint16Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCUint16Array::getTmpl(); - struct JSCUint16Array::JSCUint16ArrayPrivate* retPrivData = new JSCUint16Array::JSCUint16ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCUint16Array::JSCUint16ArrayPrivate* retPrivData = new JSCUint16Array::JSCUint16ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.h index dfc6cc8..90b92f4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint16Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp index 9887423..f259940 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCUint32Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCUint32Array::staticValues[] = { JSStaticFunction JSCUint32Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCUint32Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Uint32Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Uint32Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Uint32Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint32Array::getTmpl())) { + + uscxml::Uint32Array* localArray = ((struct JSCUint32Array::JSCUint32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint32Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint32Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Uint32Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<unsigned long> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Uint32Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Uint32Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCUint32Array::getTmpl(); + + struct JSCUint32Array::JSCUint32ArrayPrivate* retPrivData = new JSCUint32Array::JSCUint32ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCUint32Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCUint32ArrayPrivate* privData = (struct JSCUint32ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCUint32Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObje return JSValueMakeNumber(ctx, 4); } + JSValueRef JSCUint32Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint32ArrayPrivate* privData = (struct JSCUint32ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned long retVal = privData->nativeObj->get(localIndex); + unsigned long retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint32Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint32ArrayPrivate* privData = (struct JSCUint32ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned long localValue = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint32Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Uint32Array* localArray = ((struct JSCUint32Array::JSCUint32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned long localValue = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<unsigned long> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint32Array::getTmpl())) { + uscxml::Uint32Array* localArray = ((struct JSCUint32Array::JSCUint32ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<unsigned long> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint32Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint32ArrayPrivate* privData = (struct JSCUint32ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Uint32Array* retVal = new uscxml::Uint32Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCUint32Array::getTmpl(); + uscxml::Uint32Array* retVal = new uscxml::Uint32Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCUint32Array::getTmpl(); - struct JSCUint32Array::JSCUint32ArrayPrivate* retPrivData = new JSCUint32Array::JSCUint32ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCUint32Array::JSCUint32ArrayPrivate* retPrivData = new JSCUint32Array::JSCUint32ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.h index 0fac7fc..9516f5f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint32Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp index 62c49af..b828182 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCUint8Array.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCUint8Array::staticValues[] = { JSStaticFunction JSCUint8Array::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCUint8Array::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Uint8Array* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Uint8Array(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Uint8Array(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint8Array::getTmpl())) { + + uscxml::Uint8Array* localArray = ((struct JSCUint8Array::JSCUint8ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint8Array(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint8Array(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Uint8Array(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<unsigned char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Uint8Array(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Uint8Array"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCUint8Array::getTmpl(); + + struct JSCUint8Array::JSCUint8ArrayPrivate* retPrivData = new JSCUint8Array::JSCUint8ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCUint8Array::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCUint8ArrayPrivate* privData = (struct JSCUint8ArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCUint8Array::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, JSObjec return JSValueMakeNumber(ctx, 1); } + JSValueRef JSCUint8Array::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint8ArrayPrivate* privData = (struct JSCUint8ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - char retVal = privData->nativeObj->get(localIndex); + unsigned char retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint8Array::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint8ArrayPrivate* privData = (struct JSCUint8ArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint8Array::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Uint8Array* localArray = ((struct JSCUint8Array::JSCUint8ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned char localValue = (unsigned char)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<unsigned char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint8Array::getTmpl())) { + uscxml::Uint8Array* localArray = ((struct JSCUint8Array::JSCUint8ArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<unsigned char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint8Array::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint8ArrayPrivate* privData = (struct JSCUint8ArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCUint8Array::getTmpl(); + uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCUint8Array::getTmpl(); - struct JSCUint8Array::JSCUint8ArrayPrivate* retPrivData = new JSCUint8Array::JSCUint8ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCUint8Array::JSCUint8ArrayPrivate* retPrivData = new JSCUint8Array::JSCUint8ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.h index d45cee3..5510c99 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp index 85222dc..df5de18 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.cpp @@ -1,3 +1,5 @@ +#include "JSCArrayBuffer.h" +#include "JSCArrayBufferView.h" #include "JSCUint8ClampedArray.h" namespace Arabica { @@ -15,12 +17,84 @@ JSStaticValue JSCUint8ClampedArray::staticValues[] = { JSStaticFunction JSCUint8ClampedArray::staticFunctions[] = { { "get", getCallback, kJSPropertyAttributeDontDelete }, { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, - { "set", setCallback, kJSPropertyAttributeDontDelete }, { "subarray", subarrayCallback, kJSPropertyAttributeDontDelete }, { 0, 0, 0 } }; +JSObjectRef JSCUint8ClampedArray::jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception) { + uscxml::Uint8ClampedArray* localInstance = NULL; + + if (false) { + } else if (argumentCount == 3 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1]) && + JSValueIsNumber(ctx, arguments[2])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[2], exception); + localInstance = new uscxml::Uint8ClampedArray(localBuffer, localByteOffset, localLength); + + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localByteOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + localInstance = new uscxml::Uint8ClampedArray(localBuffer, localByteOffset); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint8ClampedArray::getTmpl())) { + + uscxml::Uint8ClampedArray* localArray = ((struct JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint8ClampedArray(localArray); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCArrayBuffer::getTmpl())) { + + uscxml::ArrayBuffer* localBuffer = ((struct JSCArrayBuffer::JSCArrayBufferPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + localInstance = new uscxml::Uint8ClampedArray(localBuffer); + + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + + unsigned long localLength = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + localInstance = new uscxml::Uint8ClampedArray(localLength); + + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + + std::vector<unsigned char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + localInstance = new uscxml::Uint8ClampedArray(localArray); + + } + if (!localInstance) { + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling constructor for Uint8ClampedArray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return (JSObjectRef)JSValueMakeNull(ctx); + } + + JSClassRef retClass = JSCUint8ClampedArray::getTmpl(); + + struct JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate* retPrivData = new JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate(); + retPrivData->nativeObj = localInstance; + + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; +} + JSValueRef JSCUint8ClampedArray::lengthAttrGetter(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { struct JSCUint8ClampedArrayPrivate* privData = (struct JSCUint8ClampedArrayPrivate*)JSObjectGetPrivate(object); @@ -31,75 +105,138 @@ JSValueRef JSCUint8ClampedArray::BYTES_PER_ELEMENTConstGetter(JSContextRef ctx, return JSValueMakeNumber(ctx, 1); } + JSValueRef JSCUint8ClampedArray::getCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { - if (argumentCount < 1) { - std::string errorMsg = "Wrong number of arguments in get"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint8ClampedArrayPrivate* privData = (struct JSCUint8ClampedArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + if (false) { + } else if (argumentCount == 1 && + JSValueIsNumber(ctx, arguments[0])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - char retVal = privData->nativeObj->get(localIndex); + unsigned char retVal = privData->nativeObj->get(localIndex); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling get"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint8ClampedArray::setCallback(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 set"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint8ClampedArrayPrivate* privData = (struct JSCUint8ClampedArrayPrivate*)JSObjectGetPrivate(thisObj); - unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); - unsigned char localValue = (char)JSValueToNumber(ctx, arguments[1], exception); - - privData->nativeObj->set(localIndex, localValue); + if (false) { + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint8ClampedArray::getTmpl()) && + JSValueIsNumber(ctx, arguments[1])) { + uscxml::Uint8ClampedArray* localArray = ((struct JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + unsigned long localIndex = (unsigned long)JSValueToNumber(ctx, arguments[0], exception); + unsigned char localValue = (unsigned char)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localIndex, localValue); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 2 && + JSValueIsObject(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + + std::vector<unsigned char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + unsigned long localOffset = (unsigned long)JSValueToNumber(ctx, arguments[1], exception); + + privData->nativeObj->set(localArray, localOffset); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0]) && JSValueIsObjectOfClass(ctx, arguments[0], JSCUint8ClampedArray::getTmpl())) { + uscxml::Uint8ClampedArray* localArray = ((struct JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate*)JSObjectGetPrivate(JSValueToObject(ctx, arguments[0], exception)))->nativeObj; + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } else if (argumentCount == 1 && + JSValueIsObject(ctx, arguments[0])) { + + std::vector<unsigned char> localArray; + + JSValueRef localArrayItem; + unsigned int localArrayIndex = 0; + while((localArrayItem = JSObjectGetPropertyAtIndex(ctx, JSValueToObject(ctx, arguments[0], exception), localArrayIndex, exception))) { + if (JSValueIsUndefined(ctx, localArrayItem)) + break; + if (JSValueIsNumber(ctx,localArrayItem)) + localArray.push_back(JSValueToNumber(ctx, localArrayItem, exception)); + localArrayIndex++; + } + + privData->nativeObj->set(localArray); + + JSValueRef jscRetVal = JSValueMakeUndefined(ctx); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeUndefined(ctx); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling set"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCUint8ClampedArray::subarrayCallback(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 subarray"; - JSStringRef string = JSStringCreateWithUTF8CString(errorMsg.c_str()); - JSValueRef exceptionString =JSValueMakeString(ctx, string); - JSStringRelease(string); - *exception = JSValueToObject(ctx, exceptionString, NULL); - return NULL; - } struct JSCUint8ClampedArrayPrivate* privData = (struct JSCUint8ClampedArrayPrivate*)JSObjectGetPrivate(thisObj); - long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); - long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); + if (false) { + } else if (argumentCount == 2 && + JSValueIsNumber(ctx, arguments[0]) && + JSValueIsNumber(ctx, arguments[1])) { + long localStart = (long)JSValueToNumber(ctx, arguments[0], exception); + long localEnd = (long)JSValueToNumber(ctx, arguments[1], exception); - uscxml::Uint8ClampedArray* retVal = new uscxml::Uint8ClampedArray(privData->nativeObj->subarray(localStart, localEnd)); - JSClassRef retClass = JSCUint8ClampedArray::getTmpl(); + uscxml::Uint8ClampedArray* retVal = new uscxml::Uint8ClampedArray(privData->nativeObj->subarray(localStart, localEnd)); + JSClassRef retClass = JSCUint8ClampedArray::getTmpl(); - struct JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate* retPrivData = new JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate* retPrivData = new JSCUint8ClampedArray::JSCUint8ClampedArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - return retObj; + return retObj; -} + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling subarray"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.h index 76cd77b..36e7d8a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCUint8ClampedArray.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "JSCArrayBufferView.h" #include <JavaScriptCore/JavaScriptCore.h> #include "uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDOM.h" @@ -43,8 +44,12 @@ public: static JSValueRef setCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); static JSValueRef subarrayCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception); + static JSObjectRef jsConstructor(JSContextRef ctx, JSObjectRef constructor, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception); static JSValueRef lengthAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception); static JSValueRef BYTES_PER_ELEMENTConstGetter(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 bool setPropertyCustomCallback(JSContextRef ctx, JSObjectRef object, JSStringRef propertyName, JSValueRef value, JSValueRef* exception); static JSStaticValue staticValues[]; @@ -57,6 +62,11 @@ public: classDef.staticValues = staticValues; classDef.staticFunctions = staticFunctions; classDef.finalize = jsDestructor; + classDef.hasProperty = hasPropertyCustomCallback; + classDef.getProperty = getPropertyCustomCallback; + classDef.setProperty = setPropertyCustomCallback; + classDef.callAsConstructor = jsConstructor; + classDef.parentClass = JSCArrayBufferView::getTmpl(); Tmpl = JSClassCreate(&classDef); JSClassRetain(Tmpl); diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp index 69b7969..a53585f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCXPathResult.cpp @@ -46,59 +46,91 @@ JSValueRef JSCXPathResult::booleanValueAttrGetter(JSContextRef ctx, JSObjectRef return JSValueMakeBoolean(ctx, privData->nativeObj->asBool()); } + JSValueRef JSCXPathResult::asNodeSetCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCXPathResultPrivate* privData = (struct JSCXPathResultPrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { + + Arabica::XPath::NodeSet<std::string>* retVal = new Arabica::XPath::NodeSet<std::string>(privData->nativeObj->asNodeSet()); + JSClassRef retClass = JSCNodeSet::getTmpl(); - Arabica::XPath::NodeSet<std::string>* retVal = new Arabica::XPath::NodeSet<std::string>(privData->nativeObj->asNodeSet()); - JSClassRef retClass = JSCNodeSet::getTmpl(); + struct JSCNodeSet::JSCNodeSetPrivate* retPrivData = new JSCNodeSet::JSCNodeSetPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - struct JSCNodeSet::JSCNodeSetPrivate* retPrivData = new JSCNodeSet::JSCNodeSetPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); - JSObjectRef retObj = JSObjectMake(ctx, retClass, retPrivData); + return retObj; - return retObj; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling asNodeSet"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCXPathResult::asBoolCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCXPathResultPrivate* privData = (struct JSCXPathResultPrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { + + bool retVal = privData->nativeObj->asBool(); - bool retVal = privData->nativeObj->asBool(); + JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); + return jscRetVal; + } - JSValueRef jscRetVal = JSValueMakeBoolean(ctx, retVal); - return jscRetVal; + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling asBool"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCXPathResult::asStringCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCXPathResultPrivate* privData = (struct JSCXPathResultPrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - std::string retVal = privData->nativeObj->asString(); + std::string retVal = privData->nativeObj->asString(); - JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); - JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); - JSStringRelease(jscString); - return jscRetVal; + JSStringRef jscString = JSStringCreateWithUTF8CString(retVal.c_str()); + JSValueRef jscRetVal = JSValueMakeString(ctx, jscString); + JSStringRelease(jscString); + return jscRetVal; + } + + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling asString"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); } JSValueRef JSCXPathResult::asNumberCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { struct JSCXPathResultPrivate* privData = (struct JSCXPathResultPrivate*)JSObjectGetPrivate(thisObj); + if (false) { + } else if (argumentCount == 0) { - double retVal = privData->nativeObj->asNumber(); + double retVal = privData->nativeObj->asNumber(); - JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); - return jscRetVal; -} + JSValueRef jscRetVal = JSValueMakeNumber(ctx, retVal); + return jscRetVal; + } + JSStringRef exceptionString = JSStringCreateWithUTF8CString("Parameter mismatch while calling asNumber"); + *exception = JSValueMakeString(ctx, exceptionString); + JSStringRelease(exceptionString); + return JSValueMakeUndefined(ctx); +} } } diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp index d6e2ada..98859da 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.cpp @@ -1,89 +1,156 @@ #include "TypedArray.h" #include <iostream> +#define DATAVIEW_TYPED_RETURN(type) \ +type retVal;\ +memcpy(&retVal, _buffer->_data + (_start + index), sizeof(type));\ +return retVal; + +#define DATAVIEW_TYPED_SET(type) \ +memcpy(_buffer->_data + (_start + index), &value, sizeof(type)); + namespace uscxml { -unsigned long ArrayBuffer::getByteLength() {} -ArrayBuffer ArrayBuffer::slice(long begin, long end) {} -bool ArrayBuffer::isView(void*) {} -ArrayBuffer::operator bool() {} - -ArrayBuffer ArrayBufferView::getBuffer() {} -unsigned long ArrayBufferView::getByteOffset() {} -unsigned long ArrayBufferView::getByteLength() {} - -ArrayBuffer DataView::getBuffer() {} -unsigned long DataView::getByteOffset() {} -unsigned long DataView::getByteLength() {} -char DataView::getInt8(unsigned long) {} -unsigned char DataView::getUint8(unsigned long) {} -short DataView::getInt16(unsigned long, bool) {} -unsigned short DataView::getUint16(unsigned long, bool) {} -long DataView::getInt32(unsigned long, bool) {} -unsigned long DataView::getUint32(unsigned long, bool) {} -float DataView::getFloat32(unsigned long, bool) {} -double DataView::getFloat64(unsigned long, bool) {} -void DataView::setInt8(long, char) {} -void DataView::setUint8(long, unsigned char) {} -void DataView::setInt16(long, short, bool) {} -void DataView::setUint16(long, unsigned short, bool) {} -void DataView::setInt32(long, long, bool) {} -void DataView::setUint32(long, unsigned long, bool) {} -void DataView::setFloat32(long, float, bool) {} -void DataView::setFloat64(long, double, bool) {} - -Uint8Array::Uint8Array(Uint8Array* other) {} -unsigned char Uint8Array::get(unsigned long) {} -void Uint8Array::set(unsigned long, char) {} -Uint8Array* Uint8Array::subarray(long, long) {} -unsigned long Uint8Array::getLength() {} - -Uint8ClampedArray::Uint8ClampedArray(Uint8ClampedArray* other) {} -unsigned char Uint8ClampedArray::get(unsigned long) {} -void Uint8ClampedArray::set(unsigned long, char) {} -Uint8ClampedArray* Uint8ClampedArray::subarray(long, long) {} -unsigned long Uint8ClampedArray::getLength() {} - -Int8Array::Int8Array(Int8Array* other) {} -char Int8Array::get(unsigned long) {} -void Int8Array::set(unsigned long, char) {} -Int8Array* Int8Array::subarray(long, long) {} -unsigned long Int8Array::getLength() {} - -Int16Array::Int16Array(Int16Array* other) {} -short Int16Array::get(unsigned long) {} -void Int16Array::set(unsigned long, short) {} -Int16Array* Int16Array::subarray(long, long) {} -unsigned long Int16Array::getLength() {} - -Uint16Array::Uint16Array(Uint16Array* other) {} -unsigned short Uint16Array::get(unsigned long) {} -void Uint16Array::set(unsigned long, unsigned short) {} -Uint16Array* Uint16Array::subarray(long, long) {} -unsigned long Uint16Array::getLength() {} - -Int32Array::Int32Array(Int32Array* other) {} -long Int32Array::get(unsigned long) {} -void Int32Array::set(unsigned long, long) {} -Int32Array* Int32Array::subarray(long, long) {} -unsigned long Int32Array::getLength() {} - -Uint32Array::Uint32Array(Uint32Array* other) {} -unsigned long Uint32Array::get(unsigned long) {} -void Uint32Array::set(unsigned long, unsigned long) {} -Uint32Array* Uint32Array::subarray(long, long) {} -unsigned long Uint32Array::getLength() {} - -Float32Array::Float32Array(Float32Array* other) {} -float Float32Array::get(unsigned long) {} -void Float32Array::set(unsigned long, float) {} -Float32Array* Float32Array::subarray(long, long) {} -unsigned long Float32Array::getLength() {} - -Float64Array::Float64Array(Float64Array* other) {} -double Float64Array::get(unsigned long) {} -void Float64Array::set(unsigned long, double) {} -Float64Array* Float64Array::subarray(long, long) {} -unsigned long Float64Array::getLength() {} +ArrayBuffer::Buffer::~Buffer() { + free(_data); +} + +ArrayBuffer::Buffer::Buffer(size_t size) { + _data = (char*)malloc(size); + memset(_data, 0, size); + _size = size; +} + +ArrayBuffer::Buffer::Buffer(void* data, size_t size) { + _data = (char*)malloc(size); + memcpy(_data, data, size); + _size = size; +} + +ArrayBuffer::ArrayBuffer(unsigned long length) { + _buffer = boost::shared_ptr<Buffer>(new Buffer(length)); +} + +ArrayBuffer::ArrayBuffer(boost::shared_ptr<ArrayBuffer::Buffer> buffer) : _buffer(buffer) { +} + +unsigned long ArrayBuffer::getByteLength() { + return _buffer->_size; +} + +ArrayBuffer ArrayBuffer::slice(long begin, long length) { + ArrayBuffer arrBuffer(length); + memcpy(arrBuffer._buffer->_data, _buffer->_data + begin, length); + return arrBuffer; +} + +ArrayBuffer ArrayBuffer::slice(long begin) { + return slice(begin, _buffer->_size - begin); +} + +bool ArrayBuffer::isView(void*) { + return true; +} + +ArrayBuffer::operator bool() { + return _buffer; +} + +ArrayBuffer ArrayBufferView::getBuffer() { + return ArrayBuffer(_buffer); +} + +DataView::DataView(ArrayBuffer* buffer, unsigned long start, unsigned long length) { + _start = start; + _end = start + length; + _buffer = buffer->_buffer; +} + +DataView::DataView(ArrayBuffer* buffer , unsigned long start) { + _start = start; + _end = buffer->_buffer->_size; + _buffer = buffer->_buffer; +} + +DataView::DataView(ArrayBuffer* buffer) { + _start = 0; + _end = (buffer->_buffer->_size); + _buffer = buffer->_buffer; +} + +unsigned long DataView::getByteOffset() { + return _start; +} + +unsigned long DataView::getByteLength() { + return _end - _start; +} + +unsigned long DataView::getLength() { + return _end - _start; +} + +char DataView::getInt8(unsigned long index) { + DATAVIEW_TYPED_RETURN(int8_t); +} + +unsigned char DataView::getUint8(unsigned long index) { + DATAVIEW_TYPED_RETURN(uint8_t); +} + +short DataView::getInt16(unsigned long index, bool littleEndian) { + DATAVIEW_TYPED_RETURN(int16_t); +} + +unsigned short DataView::getUint16(unsigned long index, bool littleEndian) { + DATAVIEW_TYPED_RETURN(uint16_t); +} + +long DataView::getInt32(unsigned long index, bool littleEndian) { + DATAVIEW_TYPED_RETURN(int32_t); +} + +unsigned long DataView::getUint32(unsigned long index, bool littleEndian) { + DATAVIEW_TYPED_RETURN(uint32_t); +} + +float DataView::getFloat32(unsigned long index, bool littleEndian) { + DATAVIEW_TYPED_RETURN(float); +} + +double DataView::getFloat64(unsigned long index, bool littleEndian) { + DATAVIEW_TYPED_RETURN(double); +} + +void DataView::setInt8(long index, char value) { + DATAVIEW_TYPED_SET(int8_t); +} + +void DataView::setUint8(long index, unsigned char value) { + DATAVIEW_TYPED_SET(uint8_t); +} + +void DataView::setInt16(long index, short value, bool) { + DATAVIEW_TYPED_SET(int16_t); +} +void DataView::setUint16(long index, unsigned short value, bool littleEndian) { + DATAVIEW_TYPED_SET(uint16_t); +} + +void DataView::setInt32(long index, long value, bool littleEndian) { + DATAVIEW_TYPED_SET(int32_t); +} + +void DataView::setUint32(long index, unsigned long value, bool littleEndian) { + DATAVIEW_TYPED_SET(uint32_t); +} + +void DataView::setFloat32(long index, float value, bool littleEndian) { + DATAVIEW_TYPED_SET(float); +} + +void DataView::setFloat64(long index, double value, bool littleEndian) { + DATAVIEW_TYPED_SET(double); +} }
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h index 0d3b786..82da629 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h +++ b/src/uscxml/plugins/datamodel/ecmascript/TypedArray.h @@ -2,148 +2,198 @@ #define TYPEDARRAY_H_99815BLY #include <string> -#include <map> +#include <vector> +#include <boost/shared_ptr.hpp> namespace uscxml { class ArrayBuffer { public: + class Buffer { + public: + ~Buffer(); + Buffer(size_t size); + Buffer(void* data, size_t size); + char* _data; + size_t _size; + }; + + ArrayBuffer(unsigned long length); + ArrayBuffer(boost::shared_ptr<ArrayBuffer::Buffer>); unsigned long getByteLength(); - ArrayBuffer slice(long begin, long end); + ArrayBuffer slice(long begin, long length); + ArrayBuffer slice(long begin); static bool isView(void*); + unsigned long getLength() { + return getByteLength(); + } operator bool(); + bool operator== (const ArrayBuffer& other) { + return other._buffer == _buffer; + } + unsigned char get(unsigned long index) { + if (index >= getLength()) + return 0; + unsigned char retVal; + memcpy(&retVal, _buffer->_data + index * sizeof(unsigned char), sizeof(unsigned char)); + return retVal; + } + + void set(unsigned long index, unsigned char value) { + memcpy(_buffer->_data + index * sizeof(unsigned char), &value, sizeof(unsigned char)); + } + + boost::shared_ptr<Buffer> _buffer; }; class ArrayBufferView { public: ArrayBuffer getBuffer(); - unsigned long getByteOffset(); - unsigned long getByteLength(); - + virtual unsigned long getByteOffset() = 0; + virtual unsigned long getByteLength() = 0; + virtual unsigned long getLength() = 0; +protected: + boost::shared_ptr<ArrayBuffer::Buffer> _buffer; + unsigned long _start; + unsigned long _end; }; -class DataView { +class DataView : ArrayBufferView { public: - ArrayBuffer getBuffer(); + DataView(ArrayBuffer*, unsigned long, unsigned long); + DataView(ArrayBuffer*, unsigned long); + DataView(ArrayBuffer*); + unsigned long getByteOffset(); unsigned long getByteLength(); + unsigned long getLength(); char getInt8(unsigned long); unsigned char getUint8(unsigned long); - short getInt16(unsigned long, bool); - unsigned short getUint16(unsigned long, bool); - long getInt32(unsigned long, bool); - unsigned long getUint32(unsigned long, bool); - float getFloat32(unsigned long, bool); - double getFloat64(unsigned long, bool); + short getInt16(unsigned long, bool = false); + unsigned short getUint16(unsigned long, bool = false); + long getInt32(unsigned long, bool = false); + unsigned long getUint32(unsigned long, bool = false); + float getFloat32(unsigned long, bool = false); + double getFloat64(unsigned long, bool = false); void setInt8(long, char); void setUint8(long, unsigned char); - void setInt16(long, short, bool); - void setUint16(long, unsigned short, bool); - void setInt32(long, long, bool); - void setUint32(long, unsigned long, bool); - void setFloat32(long, float, bool); - void setFloat64(long, double, bool); - -}; - -class JSArray { -public: - virtual unsigned long getLength() = 0; -protected: - std::string _data; -}; - -class Uint8Array : public JSArray { -public: - virtual ~Uint8Array() {} - Uint8Array(Uint8Array* other); - unsigned char get(unsigned long); - void set(unsigned long, char); - Uint8Array* subarray(long, long); - unsigned long getLength(); -}; - -class Uint8ClampedArray : public JSArray { -public: - virtual ~Uint8ClampedArray() {} - Uint8ClampedArray(Uint8ClampedArray* other); - unsigned char get(unsigned long); - void set(unsigned long, char); - Uint8ClampedArray* subarray(long, long); - unsigned long getLength(); -}; + void setInt16(long, short, bool = false); + void setUint16(long, unsigned short, bool = false); + void setInt32(long, long, bool = false); + void setUint32(long, unsigned long, bool = false); + void setFloat32(long, float, bool = false); + void setFloat64(long, double, bool = false); -class Int8Array : public JSArray { -public: - virtual ~Int8Array() {} - Int8Array(Int8Array* other); - char get(unsigned long); - void set(unsigned long, char); - Int8Array* subarray(long, long); - unsigned long getLength(); }; -class Int16Array : public JSArray { +template<class T, class S> class TypedArray : public ArrayBufferView { public: - virtual ~Int16Array() {} - Int16Array(Int16Array* other); - short get(unsigned long); - void set(unsigned long, short); - Int16Array* subarray(long, long); - unsigned long getLength(); -}; + virtual ~TypedArray() {} + TypedArray(uscxml::ArrayBuffer* buffer, unsigned long start, unsigned long length) { + _start = start; + _end = start + length; + _buffer = buffer->_buffer; + } + TypedArray(uscxml::ArrayBuffer* buffer, unsigned long start) { + _start = start / sizeof(S); + _end = buffer->_buffer->_size / sizeof(S); + _buffer = buffer->_buffer; + } + TypedArray(uscxml::ArrayBuffer* buffer) { + _start = 0; + _end = (buffer->_buffer->_size) / sizeof(S); + _buffer = buffer->_buffer; + } + + TypedArray(boost::shared_ptr<ArrayBuffer::Buffer> buffer, unsigned long start, unsigned long length) { + _start = start; + _end = start + length; + _buffer = buffer; + } + TypedArray(unsigned long length) { + _start = 0; + _end = length; + _buffer = boost::shared_ptr<ArrayBuffer::Buffer>(new ArrayBuffer::Buffer(length * sizeof(S))); + } + TypedArray(std::vector<T> data) { + _start = 0; + _end = data.size(); + if (sizeof(T) == sizeof(S)) { + _buffer = boost::shared_ptr<ArrayBuffer::Buffer>(new ArrayBuffer::Buffer(((void*)&data[0]), data.size() * sizeof(T))); + } else { + S* buffer = (S*)malloc(data.size() * sizeof(S)); + typename std::vector<T>::const_iterator dataIter = data.begin(); + unsigned long i = 0; + while(dataIter != data.end()) { + buffer[i] = *dataIter; + dataIter++; + i++; + } + _buffer = boost::shared_ptr<ArrayBuffer::Buffer>(new ArrayBuffer::Buffer(buffer, data.size() * sizeof(S))); + } + } + TypedArray(TypedArray* other) { + _start = other->_start; + _end = other->_end; + _buffer = other->_buffer; + } + T get(unsigned long index) { + if (index >= getLength()) + return static_cast<T>(0); + S retVal; + memcpy(&retVal, _buffer->_data + (_start + index) * sizeof(S), sizeof(S)); + return retVal; + } + void set(unsigned long index, T value) { + memcpy(_buffer->_data + (_start + index) * sizeof(S), &value, sizeof(S)); + } + + void set(TypedArray<T, S>* value, unsigned long offset) { + memcpy(_buffer->_data + (_start) * sizeof(S), &value->_buffer->_data[offset], value->_buffer->_size); + } + + void set(TypedArray<T, S>* value) { + set(value, 0); + } + + void set(std::vector<T> data, unsigned long offset) { + } + + void set(std::vector<T> data) { + set(data, 0); + } + + TypedArray* subarray(long start, long end) { + return new TypedArray<T, S>(_buffer, start, end); + } + + unsigned long getLength() { + return _end - _start; + } + + unsigned long getByteLength() { + return (_end - _start) * sizeof(S); + } + + unsigned long getByteOffset() { + return _start * sizeof(S); + } -class Uint16Array : public JSArray { -public: - virtual ~Uint16Array() {} - Uint16Array(Uint16Array* other); - unsigned short get(unsigned long); - void set(unsigned long, unsigned short); - Uint16Array* subarray(long, long); - unsigned long getLength(); -}; -class Int32Array : public JSArray { -public: - virtual ~Int32Array() {} - Int32Array(Int32Array* other); - long get(unsigned long); - void set(unsigned long, long); - Int32Array* subarray(long, long); - unsigned long getLength(); }; -class Uint32Array : public JSArray { -public: - virtual ~Uint32Array() {} - Uint32Array(Uint32Array* other); - unsigned long get(unsigned long); - void set(unsigned long, unsigned long); - Uint32Array* subarray(long, long); - unsigned long getLength(); -}; - -class Float32Array : public JSArray { -public: - virtual ~Float32Array() {} - Float32Array(Float32Array* other); - float get(unsigned long); - void set(unsigned long, float); - Float32Array* subarray(long, long); - unsigned long getLength(); -}; +typedef TypedArray<unsigned char, uint8_t> Uint8Array; +typedef TypedArray<unsigned char, uint8_t> Uint8ClampedArray; +typedef TypedArray<char, int8_t> Int8Array; +typedef TypedArray<short, int16_t> Int16Array; +typedef TypedArray<unsigned short, uint16_t> Uint16Array; +typedef TypedArray<long, int32_t> Int32Array; +typedef TypedArray<unsigned long, uint32_t> Uint32Array; +typedef TypedArray<float, float> Float32Array; +typedef TypedArray<double, double> Float64Array; -class Float64Array : public JSArray { -public: - virtual ~Float64Array() {} - Float64Array(Float64Array* other); - double get(unsigned long); - void set(unsigned long, double); - Float64Array* subarray(long, long); - unsigned long getLength(); -}; } #endif /* end of include guard: TYPEDARRAY_H_99815BLY */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index ea112f1..aef41ca 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -9,6 +9,18 @@ #include "dom/V8CDATASection.h" #include "dom/V8SCXMLEvent.h" +#include "dom/V8ArrayBuffer.h" +#include "dom/V8Int8Array.h" +#include "dom/V8Uint8Array.h" +#include "dom/V8Uint8ClampedArray.h" +#include "dom/V8Int16Array.h" +#include "dom/V8Uint16Array.h" +#include "dom/V8Int32Array.h" +#include "dom/V8Uint32Array.h" +#include "dom/V8Float32Array.h" +#include "dom/V8Float64Array.h" +#include "dom/V8DataView.h" + #include "uscxml/Message.h" #include <glog/logging.h> @@ -86,6 +98,20 @@ boost::shared_ptr<DataModelImpl> V8DataModel::create(InterpreterImpl* interprete context->Global()->Set(v8::String::New("document"), docObj); + // setup constructors + context->Global()->Set(v8::String::New("ArrayBuffer"), V8ArrayBuffer::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Int8Array"), V8Int8Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Uint8Array"), V8Uint8Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Uint8ClampedArray"), V8Uint8ClampedArray::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Int16Array"), V8Int16Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Uint16Array"), V8Uint16Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Int32Array"), V8Int32Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Uint32Array"), V8Uint32Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Float32Array"), V8Float32Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("Float64Array"), V8Float64Array::getConstructor()->GetFunction()); + context->Global()->Set(v8::String::New("DataView"), V8DataView::getConstructor()->GetFunction()); + + context->Global()->SetAccessor(v8::String::New("_sessionid"), V8DataModel::getAttribute, V8DataModel::setWithException, diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp index d4146fe..ce51887 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.cpp @@ -4,7 +4,37 @@ namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8ArrayBuffer::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8ArrayBuffer::Constr; +v8::Handle<v8::Value> V8ArrayBuffer::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::ArrayBuffer* localInstance = NULL; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::ArrayBuffer(localLength); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for ArrayBuffer"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8ArrayBuffer::byteLengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,43 +42,69 @@ v8::Handle<v8::Value> V8ArrayBuffer::byteLengthAttrGetter(v8::Local<v8::String> return v8::Integer::New(privData->nativeObj->getByteLength()); } + v8::Handle<v8::Value> V8ArrayBuffer::sliceCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in slice"); v8::Local<v8::Object> self = args.Holder(); struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0)); - long localBegin = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localBegin = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd)); - v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin, localEnd)); + v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); + return retObj; + } else if (args.Length() == 1 && + args[0]->IsInt32()) { + long localBegin = args[0]->ToNumber()->Int32Value(); + + uscxml::ArrayBuffer* retVal = new uscxml::ArrayBuffer(privData->nativeObj->slice(localBegin)); + v8::Handle<v8::Function> retCtor = V8ArrayBuffer::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8ArrayBuffer::V8ArrayBufferPrivate* retPrivData = new V8ArrayBuffer::V8ArrayBufferPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8ArrayBuffer::jsDestructor); + return retObj; + + } + throw V8Exception("Parameter mismatch while calling slice"); + return v8::Undefined(); } v8::Handle<v8::Value> V8ArrayBuffer::isViewCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in isView"); v8::Local<v8::Object> self = args.Holder(); struct V8ArrayBufferPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0)); - void* localValue = v8::External::Unwrap(args[0]->ToObject()->GetInternalField(0)); + if (false) { + } else if (args.Length() == 1 && + true) { + void* localValue = v8::External::Unwrap(args[0]->ToObject()->GetInternalField(0)); - bool retVal = privData->nativeObj->isView(localValue); + bool retVal = privData->nativeObj->isView(localValue); - return v8::Boolean::New(retVal); + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling isView"); + return v8::Undefined(); } - bool V8ArrayBuffer::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.h index 3399575..d4229eb 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBuffer.h @@ -45,6 +45,18 @@ public: static v8::Handle<v8::Value> isViewCallback(const v8::Arguments&); static v8::Handle<v8::Value> byteLengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -62,6 +74,7 @@ public: instance->SetAccessor(v8::String::NewSymbol("byteLength"), V8ArrayBuffer::byteLengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8ArrayBuffer::indexedPropertyCustomGetter, V8ArrayBuffer::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("slice"), v8::FunctionTemplate::New(V8ArrayBuffer::sliceCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("isView"), diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBufferView.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBufferView.cpp index ff0b744..562b9f3 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBufferView.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ArrayBufferView.cpp @@ -6,7 +6,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8ArrayBufferView::Tmpl; - v8::Handle<v8::Value> V8ArrayBufferView::bufferAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8ArrayBufferViewPrivate* privData = V8DOM::toClassPtr<V8ArrayBufferViewPrivate >(self->GetInternalField(0)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp index bee6042..efb9a75 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp @@ -7,7 +7,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Attr::Tmpl; - v8::Handle<v8::Value> V8Attr::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8AttrPrivate* privData = V8DOM::toClassPtr<V8AttrPrivate >(self->GetInternalField(0)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp index a9e5ac9..a348cd5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp @@ -5,7 +5,6 @@ namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8CDATASection::Tmpl; - bool V8CDATASection::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp index 459cf96..673e6a8 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp @@ -6,7 +6,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8CharacterData::Tmpl; - v8::Handle<v8::Value> V8CharacterData::dataAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); @@ -27,76 +26,101 @@ v8::Handle<v8::Value> V8CharacterData::lengthAttrGetter(v8::Local<v8::String> pr return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8CharacterData::substringDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in substringData"); v8::Local<v8::Object> self = args.Holder(); struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); - - std::string retVal = privData->nativeObj->substringData(localOffset, localCount); - - return v8::String::New(retVal.c_str()); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + + std::string retVal = privData->nativeObj->substringData(localOffset, localCount); + + return v8::String::New(retVal.c_str()); + } + throw V8Exception("Parameter mismatch while calling substringData"); + return v8::Undefined(); } v8::Handle<v8::Value> V8CharacterData::appendDataCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in appendData"); v8::Local<v8::Object> self = args.Holder(); struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localArg(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localArg(args[0]); - privData->nativeObj->appendData(*localArg); + privData->nativeObj->appendData(*localArg); + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling appendData"); return v8::Undefined(); } v8::Handle<v8::Value> V8CharacterData::insertDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in insertData"); v8::Local<v8::Object> self = args.Holder(); struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - v8::String::AsciiValue localArg(args[1]); - - privData->nativeObj->insertData(localOffset, *localArg); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsString()) { + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + v8::String::AsciiValue localArg(args[1]); + + privData->nativeObj->insertData(localOffset, *localArg); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling insertData"); return v8::Undefined(); } v8::Handle<v8::Value> V8CharacterData::deleteDataCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in deleteData"); v8::Local<v8::Object> self = args.Holder(); struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); - - privData->nativeObj->deleteData(localOffset, localCount); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->deleteData(localOffset, localCount); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling deleteData"); return v8::Undefined(); } v8::Handle<v8::Value> V8CharacterData::replaceDataCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in replaceData"); v8::Local<v8::Object> self = args.Holder(); struct V8CharacterDataPrivate* privData = V8DOM::toClassPtr<V8CharacterDataPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localCount = args[1]->ToNumber()->Uint32Value(); - v8::String::AsciiValue localArg(args[2]); - - privData->nativeObj->replaceData(localOffset, localCount, *localArg); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsUint32() && + args[1]->IsUint32() && + args[2]->IsString()) { + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + v8::String::AsciiValue localArg(args[2]); + + privData->nativeObj->replaceData(localOffset, localCount, *localArg); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling replaceData"); return v8::Undefined(); } - bool V8CharacterData::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp index f754ea7..97cd948 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp @@ -5,7 +5,6 @@ namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Comment::Tmpl; - bool V8Comment::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp index f7a7575..00fe645 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp @@ -8,71 +8,85 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8DOMImplementation::Tmpl; v8::Handle<v8::Value> V8DOMImplementation::hasFeatureCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in hasFeature"); v8::Local<v8::Object> self = args.Holder(); struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localFeature(args[0]); - v8::String::AsciiValue localVersion(args[1]); - - bool retVal = privData->nativeObj->hasFeature(*localFeature, *localVersion); - - return v8::Boolean::New(retVal); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localFeature(args[0]); + v8::String::AsciiValue localVersion(args[1]); + + bool retVal = privData->nativeObj->hasFeature(*localFeature, *localVersion); + + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling hasFeature"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DOMImplementation::createDocumentTypeCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in createDocumentType"); v8::Local<v8::Object> self = args.Holder(); struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localQualifiedName(args[0]); - v8::String::AsciiValue localPublicId(args[1]); - v8::String::AsciiValue localSystemId(args[2]); - - Arabica::DOM::DocumentType<std::string>* retVal = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->createDocumentType(*localQualifiedName, *localPublicId, *localSystemId)); - v8::Handle<v8::Function> retCtor = V8DocumentType::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - - struct V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - - retObj.MakeWeak(0, V8DocumentType::jsDestructor); - return retObj; - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsString() && + args[1]->IsString() && + args[2]->IsString()) { + v8::String::AsciiValue localQualifiedName(args[0]); + v8::String::AsciiValue localPublicId(args[1]); + v8::String::AsciiValue localSystemId(args[2]); + + Arabica::DOM::DocumentType<std::string>* retVal = new Arabica::DOM::DocumentType<std::string>(privData->nativeObj->createDocumentType(*localQualifiedName, *localPublicId, *localSystemId)); + v8::Handle<v8::Function> retCtor = V8DocumentType::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8DocumentType::jsDestructor); + return retObj; + + } + throw V8Exception("Parameter mismatch while calling createDocumentType"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DOMImplementation::createDocumentCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in createDocument"); - if (!(V8DocumentType::hasInstance(args[2]))) - throw V8Exception("Parameter mismatch while calling createDocument"); v8::Local<v8::Object> self = args.Holder(); struct V8DOMImplementationPrivate* privData = V8DOM::toClassPtr<V8DOMImplementationPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - Arabica::DOM::DocumentType<std::string>* localDoctype = V8DOM::toClassPtr<V8DocumentType::V8DocumentTypePrivate >(args[2]->ToObject()->GetInternalField(0))->nativeObj; - - Arabica::DOM::Document<std::string>* retVal = new Arabica::DOM::Document<std::string>(privData->nativeObj->createDocument(*localNamespaceURI, *localQualifiedName, *localDoctype)); - v8::Handle<v8::Function> retCtor = V8Document::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - - struct V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; - - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - - retObj.MakeWeak(0, V8Document::jsDestructor); - return retObj; - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsString() && + args[1]->IsString() && + args[2]->IsObject() && V8DocumentType::hasInstance(args[2])) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + Arabica::DOM::DocumentType<std::string>* localDoctype = V8DOM::toClassPtr<V8DocumentType::V8DocumentTypePrivate >(args[2]->ToObject()->GetInternalField(0))->nativeObj; + + Arabica::DOM::Document<std::string>* retVal = new Arabica::DOM::Document<std::string>(privData->nativeObj->createDocument(*localNamespaceURI, *localQualifiedName, *localDoctype)); + v8::Handle<v8::Function> retCtor = V8Document::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Document::jsDestructor); + return retObj; + + } + throw V8Exception("Parameter mismatch while calling createDocument"); + return v8::Undefined(); } - bool V8DOMImplementation::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.cpp index 4a756ee..4611595 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.cpp @@ -1,238 +1,468 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8DataView.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8DataView::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8DataView::Constr; + +v8::Handle<v8::Value> V8DataView::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::DataView* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localByteLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::DataView(localBuffer, localByteOffset, localByteLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::DataView(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::DataView(localBuffer); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for DataView"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8DataView::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8DataView::V8DataViewPrivate* retPrivData = new V8DataView::V8DataViewPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8DataView::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8DataView::getInt8Callback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getInt8"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - char retVal = privData->nativeObj->getInt8(localByteOffset); + char retVal = privData->nativeObj->getInt8(localByteOffset); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getInt8"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::getUint8Callback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getUint8"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - char retVal = privData->nativeObj->getUint8(localByteOffset); + unsigned char retVal = privData->nativeObj->getUint8(localByteOffset); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getUint8"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::getInt16Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getInt16"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + + short retVal = privData->nativeObj->getInt16(localByteOffset, localLittleEndian); - short retVal = privData->nativeObj->getInt16(localByteOffset, localLittleEndian); + return v8::Number::New(retVal); + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - return v8::Number::New(retVal); + short retVal = privData->nativeObj->getInt16(localByteOffset); + + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getInt16"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::getUint16Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getUint16"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + + unsigned short retVal = privData->nativeObj->getUint16(localByteOffset, localLittleEndian); - unsigned short retVal = privData->nativeObj->getUint16(localByteOffset, localLittleEndian); + return v8::Number::New(retVal); + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - return v8::Number::New(retVal); + unsigned short retVal = privData->nativeObj->getUint16(localByteOffset); + + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getUint16"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::getInt32Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getInt32"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + + long retVal = privData->nativeObj->getInt32(localByteOffset, localLittleEndian); - long retVal = privData->nativeObj->getInt32(localByteOffset, localLittleEndian); + return v8::Number::New(retVal); + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - return v8::Number::New(retVal); + long retVal = privData->nativeObj->getInt32(localByteOffset); + + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getInt32"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::getUint32Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getUint32"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + + unsigned long retVal = privData->nativeObj->getUint32(localByteOffset, localLittleEndian); - unsigned long retVal = privData->nativeObj->getUint32(localByteOffset, localLittleEndian); + return v8::Number::New(retVal); + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - return v8::Number::New(retVal); + unsigned long retVal = privData->nativeObj->getUint32(localByteOffset); + + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getUint32"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::getFloat32Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getFloat32"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + + float retVal = privData->nativeObj->getFloat32(localByteOffset, localLittleEndian); + + return v8::Number::New(retVal); + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - float retVal = privData->nativeObj->getFloat32(localByteOffset, localLittleEndian); + float retVal = privData->nativeObj->getFloat32(localByteOffset); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getFloat32"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::getFloat64Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getFloat64"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[1]->ToBoolean()->BooleanValue(); + + double retVal = privData->nativeObj->getFloat64(localByteOffset, localLittleEndian); + + return v8::Number::New(retVal); + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - double retVal = privData->nativeObj->getFloat64(localByteOffset, localLittleEndian); + double retVal = privData->nativeObj->getFloat64(localByteOffset); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling getFloat64"); + return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setInt8Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in setInt8"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - char localValue = args[1]->ToNumber()->Int32Value(); - - privData->nativeObj->setInt8(localByteOffset, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsInt32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + char localValue = args[1]->ToNumber()->Int32Value(); + + privData->nativeObj->setInt8(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setInt8"); return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setUint8Callback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in setUint8"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - unsigned char localValue = args[1]->ToNumber()->Uint32Value(); - - privData->nativeObj->setUint8(localByteOffset, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + unsigned char localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->setUint8(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setUint8"); return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setInt16Callback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setInt16"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - short localValue = args[1]->ToNumber()->Int32Value(); - bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); - - privData->nativeObj->setInt16(localByteOffset, localValue, localLittleEndian); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsUint32() && + args[1]->IsInt32() && + args[2]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + short localValue = args[1]->ToNumber()->Int32Value(); + bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); + + privData->nativeObj->setInt16(localByteOffset, localValue, localLittleEndian); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsInt32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + short localValue = args[1]->ToNumber()->Int32Value(); + + privData->nativeObj->setInt16(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setInt16"); return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setUint16Callback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setUint16"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - unsigned short localValue = args[1]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); - - privData->nativeObj->setUint16(localByteOffset, localValue, localLittleEndian); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsUint32() && + args[1]->IsUint32() && + args[2]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + unsigned short localValue = args[1]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); + + privData->nativeObj->setUint16(localByteOffset, localValue, localLittleEndian); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + unsigned short localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->setUint16(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setUint16"); return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setInt32Callback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setInt32"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - long localValue = args[1]->ToNumber()->Int32Value(); - bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); - - privData->nativeObj->setInt32(localByteOffset, localValue, localLittleEndian); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsUint32() && + args[1]->IsInt32() && + args[2]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + long localValue = args[1]->ToNumber()->Int32Value(); + bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); + + privData->nativeObj->setInt32(localByteOffset, localValue, localLittleEndian); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsInt32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + long localValue = args[1]->ToNumber()->Int32Value(); + + privData->nativeObj->setInt32(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setInt32"); return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setUint32Callback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setUint32"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - unsigned long localValue = args[1]->ToNumber()->Uint32Value(); - bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); - - privData->nativeObj->setUint32(localByteOffset, localValue, localLittleEndian); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsUint32() && + args[1]->IsUint32() && + args[2]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localValue = args[1]->ToNumber()->Uint32Value(); + bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); + + privData->nativeObj->setUint32(localByteOffset, localValue, localLittleEndian); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->setUint32(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setUint32"); return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setFloat32Callback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setFloat32"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - float localValue = args[1]->ToNumber()->Value(); - bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); - - privData->nativeObj->setFloat32(localByteOffset, localValue, localLittleEndian); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsUint32() && + args[1]->IsNumber() && + args[2]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + float localValue = args[1]->ToNumber()->Value(); + bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); + + privData->nativeObj->setFloat32(localByteOffset, localValue, localLittleEndian); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsNumber()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + float localValue = args[1]->ToNumber()->Value(); + + privData->nativeObj->setFloat32(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setFloat32"); return v8::Undefined(); } v8::Handle<v8::Value> V8DataView::setFloat64Callback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setFloat64"); v8::Local<v8::Object> self = args.Holder(); struct V8DataViewPrivate* privData = V8DOM::toClassPtr<V8DataViewPrivate >(self->GetInternalField(0)); - unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); - double localValue = args[1]->ToNumber()->Value(); - bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); - - privData->nativeObj->setFloat64(localByteOffset, localValue, localLittleEndian); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsUint32() && + args[1]->IsNumber() && + args[2]->IsBoolean()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + double localValue = args[1]->ToNumber()->Value(); + bool localLittleEndian = args[2]->ToBoolean()->BooleanValue(); + + privData->nativeObj->setFloat64(localByteOffset, localValue, localLittleEndian); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsNumber()) { + unsigned long localByteOffset = args[0]->ToNumber()->Uint32Value(); + double localValue = args[1]->ToNumber()->Value(); + + privData->nativeObj->setFloat64(localByteOffset, localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setFloat64"); return v8::Undefined(); } - bool V8DataView::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.h index 476ff87..e2d2351 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DataView.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -59,6 +60,16 @@ public: static v8::Handle<v8::Value> setFloat64Callback(const v8::Arguments&); + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } + static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { if (Tmpl.IsEmpty()) { @@ -107,6 +118,7 @@ public: v8::FunctionTemplate::New(V8DataView::setFloat64Callback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp index 06191ea..c45039c 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp @@ -17,7 +17,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Document::Tmpl; - v8::Handle<v8::Value> V8Document::doctypeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); @@ -77,332 +76,392 @@ v8::Handle<v8::Value> V8Document::documentElementAttrGetter(v8::Local<v8::String return arbaicaRetObj; } + v8::Handle<v8::Value> V8Document::createElementCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createElement"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localTagName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localTagName(args[0]); - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElement(*localTagName)); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElement(*localTagName)); + v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createElement"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createDocumentFragmentCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - Arabica::DOM::DocumentFragment<std::string>* retVal = new Arabica::DOM::DocumentFragment<std::string>(privData->nativeObj->createDocumentFragment()); - v8::Handle<v8::Function> retCtor = V8DocumentFragment::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::DocumentFragment<std::string>* retVal = new Arabica::DOM::DocumentFragment<std::string>(privData->nativeObj->createDocumentFragment()); + v8::Handle<v8::Function> retCtor = V8DocumentFragment::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8DocumentFragment::V8DocumentFragmentPrivate* retPrivData = new V8DocumentFragment::V8DocumentFragmentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8DocumentFragment::V8DocumentFragmentPrivate* retPrivData = new V8DocumentFragment::V8DocumentFragmentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8DocumentFragment::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8DocumentFragment::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createDocumentFragment"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createTextNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createTextNode"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localData(args[0]); - Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->createTextNode(*localData)); - v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->createTextNode(*localData)); + v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Text::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Text::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createTextNode"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createCommentCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createComment"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localData(args[0]); - Arabica::DOM::Comment<std::string>* retVal = new Arabica::DOM::Comment<std::string>(privData->nativeObj->createComment(*localData)); - v8::Handle<v8::Function> retCtor = V8Comment::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Comment<std::string>* retVal = new Arabica::DOM::Comment<std::string>(privData->nativeObj->createComment(*localData)); + v8::Handle<v8::Function> retCtor = V8Comment::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Comment::V8CommentPrivate* retPrivData = new V8Comment::V8CommentPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Comment::V8CommentPrivate* retPrivData = new V8Comment::V8CommentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Comment::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Comment::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createComment"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createCDATASectionCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createCDATASection"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localData(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localData(args[0]); - Arabica::DOM::CDATASection<std::string>* retVal = new Arabica::DOM::CDATASection<std::string>(privData->nativeObj->createCDATASection(*localData)); - v8::Handle<v8::Function> retCtor = V8CDATASection::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::CDATASection<std::string>* retVal = new Arabica::DOM::CDATASection<std::string>(privData->nativeObj->createCDATASection(*localData)); + v8::Handle<v8::Function> retCtor = V8CDATASection::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8CDATASection::V8CDATASectionPrivate* retPrivData = new V8CDATASection::V8CDATASectionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8CDATASection::V8CDATASectionPrivate* retPrivData = new V8CDATASection::V8CDATASectionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8CDATASection::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8CDATASection::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createCDATASection"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createProcessingInstructionCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in createProcessingInstruction"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localTarget(args[0]); - v8::String::AsciiValue localData(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localTarget(args[0]); + v8::String::AsciiValue localData(args[1]); - Arabica::DOM::ProcessingInstruction<std::string>* retVal = new Arabica::DOM::ProcessingInstruction<std::string>(privData->nativeObj->createProcessingInstruction(*localTarget, *localData)); - v8::Handle<v8::Function> retCtor = V8ProcessingInstruction::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::ProcessingInstruction<std::string>* retVal = new Arabica::DOM::ProcessingInstruction<std::string>(privData->nativeObj->createProcessingInstruction(*localTarget, *localData)); + v8::Handle<v8::Function> retCtor = V8ProcessingInstruction::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8ProcessingInstruction::V8ProcessingInstructionPrivate* retPrivData = new V8ProcessingInstruction::V8ProcessingInstructionPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8ProcessingInstruction::V8ProcessingInstructionPrivate* retPrivData = new V8ProcessingInstruction::V8ProcessingInstructionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8ProcessingInstruction::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8ProcessingInstruction::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createProcessingInstruction"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createAttribute"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttribute(*localName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttribute(*localName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createAttribute"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createEntityReferenceCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in createEntityReference"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::EntityReference<std::string>* retVal = new Arabica::DOM::EntityReference<std::string>(privData->nativeObj->createEntityReference(*localName)); - v8::Handle<v8::Function> retCtor = V8EntityReference::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::EntityReference<std::string>* retVal = new Arabica::DOM::EntityReference<std::string>(privData->nativeObj->createEntityReference(*localName)); + v8::Handle<v8::Function> retCtor = V8EntityReference::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8EntityReference::V8EntityReferencePrivate* retPrivData = new V8EntityReference::V8EntityReferencePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8EntityReference::V8EntityReferencePrivate* retPrivData = new V8EntityReference::V8EntityReferencePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8EntityReference::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8EntityReference::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createEntityReference"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::getElementsByTagNameCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getElementsByTagName"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localTagname(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localTagname(args[0]); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localTagname)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localTagname)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getElementsByTagName"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::importNodeCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in importNode"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling importNode"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localImportedNode = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - bool localDeep = args[1]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Node::hasInstance(args[0]) && + args[1]->IsBoolean()) { + Arabica::DOM::Node<std::string>* localImportedNode = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + bool localDeep = args[1]->ToBoolean()->BooleanValue(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->importNode(*localImportedNode, localDeep)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->importNode(*localImportedNode, localDeep)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling importNode"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createElementNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in createElementNS"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->createElementNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createElementNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::createAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in createAttributeNS"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->createAttributeNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling createAttributeNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::getElementsByTagNameNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getElementsByTagNameNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Document::getElementByIdCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getElementById"); v8::Local<v8::Object> self = args.Holder(); struct V8DocumentPrivate* privData = V8DOM::toClassPtr<V8DocumentPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localElementId(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localElementId(args[0]); - Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->getElementById(*localElementId)); - v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Element<std::string>* retVal = new Arabica::DOM::Element<std::string>(privData->nativeObj->getElementById(*localElementId)); + v8::Handle<v8::Function> retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Element::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getElementById"); + return v8::Undefined(); } - bool V8Document::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp index 1403574..fa655ae 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp @@ -5,7 +5,6 @@ namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8DocumentFragment::Tmpl; - bool V8DocumentFragment::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp index 6b9a7b0..3b60da4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp @@ -7,7 +7,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8DocumentType::Tmpl; - v8::Handle<v8::Value> V8DocumentType::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8DocumentTypePrivate* privData = V8DOM::toClassPtr<V8DocumentTypePrivate >(self->GetInternalField(0)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp index 680dd5e..87ea5be 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp @@ -8,292 +8,353 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Element::Tmpl; - v8::Handle<v8::Value> V8Element::tagNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); return v8::String::New(privData->nativeObj->getTagName().c_str()); } + v8::Handle<v8::Value> V8Element::getAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getAttribute"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - std::string retVal = privData->nativeObj->getAttribute(*localName); + std::string retVal = privData->nativeObj->getAttribute(*localName); - return v8::String::New(retVal.c_str()); + return v8::String::New(retVal.c_str()); + } + throw V8Exception("Parameter mismatch while calling getAttribute"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::setAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in setAttribute"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); - v8::String::AsciiValue localValue(args[1]); - - privData->nativeObj->setAttribute(*localName, *localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localName(args[0]); + v8::String::AsciiValue localValue(args[1]); + + privData->nativeObj->setAttribute(*localName, *localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setAttribute"); return v8::Undefined(); } v8::Handle<v8::Value> V8Element::removeAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeAttribute"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - privData->nativeObj->removeAttribute(*localName); + privData->nativeObj->removeAttribute(*localName); + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling removeAttribute"); return v8::Undefined(); } v8::Handle<v8::Value> V8Element::getAttributeNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getAttributeNode"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNode(*localName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNode(*localName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getAttributeNode"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::setAttributeNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setAttributeNode"); - if (!(V8Attr::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setAttributeNode"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Attr::hasInstance(args[0])) { + Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNode(*localNewAttr)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNode(*localNewAttr)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling setAttributeNode"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::removeAttributeNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeAttributeNode"); - if (!(V8Attr::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling removeAttributeNode"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - Arabica::DOM::Attr<std::string>* localOldAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Attr::hasInstance(args[0])) { + Arabica::DOM::Attr<std::string>* localOldAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->removeAttributeNode(*localOldAttr)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->removeAttributeNode(*localOldAttr)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling removeAttributeNode"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::getElementsByTagNameCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getElementsByTagName"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localName)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagName(*localName)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getElementsByTagName"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::getAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getAttributeNS"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); - - std::string retVal = privData->nativeObj->getAttributeNS(*localNamespaceURI, *localLocalName); - - return v8::String::New(retVal.c_str()); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + std::string retVal = privData->nativeObj->getAttributeNS(*localNamespaceURI, *localLocalName); + + return v8::String::New(retVal.c_str()); + } + throw V8Exception("Parameter mismatch while calling getAttributeNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::setAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 3) - throw V8Exception("Wrong number of arguments in setAttributeNS"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localQualifiedName(args[1]); - v8::String::AsciiValue localValue(args[2]); - - privData->nativeObj->setAttributeNS(*localNamespaceURI, *localQualifiedName, *localValue); - + if (false) { + } else if (args.Length() == 3 && + args[0]->IsString() && + args[1]->IsString() && + args[2]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + v8::String::AsciiValue localValue(args[2]); + + privData->nativeObj->setAttributeNS(*localNamespaceURI, *localQualifiedName, *localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setAttributeNS"); return v8::Undefined(); } v8::Handle<v8::Value> V8Element::removeAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in removeAttributeNS"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); - - privData->nativeObj->removeAttributeNS(*localNamespaceURI, *localLocalName); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + privData->nativeObj->removeAttributeNS(*localNamespaceURI, *localLocalName); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling removeAttributeNS"); return v8::Undefined(); } v8::Handle<v8::Value> V8Element::getAttributeNodeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getAttributeNodeNS"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNodeNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->getAttributeNodeNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getAttributeNodeNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::setAttributeNodeNSCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setAttributeNodeNS"); - if (!(V8Attr::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setAttributeNodeNS"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Attr::hasInstance(args[0])) { + Arabica::DOM::Attr<std::string>* localNewAttr = V8DOM::toClassPtr<V8Attr::V8AttrPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); - v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Attr<std::string>* retVal = new Arabica::DOM::Attr<std::string>(privData->nativeObj->setAttributeNodeNS(*localNewAttr)); + v8::Handle<v8::Function> retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Attr::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling setAttributeNodeNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::getElementsByTagNameNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::NodeList<std::string>* retVal = new Arabica::DOM::NodeList<std::string>(privData->nativeObj->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeList::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getElementsByTagNameNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::hasAttributeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in hasAttribute"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - bool retVal = privData->nativeObj->hasAttribute(*localName); + bool retVal = privData->nativeObj->hasAttribute(*localName); - return v8::Boolean::New(retVal); + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling hasAttribute"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Element::hasAttributeNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in hasAttributeNS"); v8::Local<v8::Object> self = args.Holder(); struct V8ElementPrivate* privData = V8DOM::toClassPtr<V8ElementPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); - - bool retVal = privData->nativeObj->hasAttributeNS(*localNamespaceURI, *localLocalName); - - return v8::Boolean::New(retVal); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + bool retVal = privData->nativeObj->hasAttributeNS(*localNamespaceURI, *localLocalName); + + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling hasAttributeNS"); + return v8::Undefined(); } - bool V8Element::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp index f3ce21d..2cb07ae 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp @@ -6,7 +6,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Entity::Tmpl; - v8::Handle<v8::Value> V8Entity::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8EntityPrivate* privData = V8DOM::toClassPtr<V8EntityPrivate >(self->GetInternalField(0)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp index 197fadd..228ac79 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp @@ -5,7 +5,6 @@ namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8EntityReference::Tmpl; - bool V8EntityReference::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp index 6d3fa47..1fe74e6 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Float32Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Float32Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Float32Array::Constr; +v8::Handle<v8::Value> V8Float32Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Float32Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Float32Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Float32Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Float32Array::hasInstance(args[0])) { + + uscxml::Float32Array* localArray = V8DOM::toClassPtr<V8Float32Array::V8Float32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Float32Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Float32Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Float32Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<float> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToNumber()->Value()); + } + localInstance = new uscxml::Float32Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Float32Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Float32Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Float32Array::V8Float32ArrayPrivate* retPrivData = new V8Float32Array::V8Float32ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Float32Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Float32Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Float32Array::lengthAttrGetter(v8::Local<v8::String> pro return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Float32Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Float32ArrayPrivate* privData = V8DOM::toClassPtr<V8Float32ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - float retVal = privData->nativeObj->get(localIndex); + float retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Float32Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Float32ArrayPrivate* privData = V8DOM::toClassPtr<V8Float32ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - float localValue = args[1]->ToNumber()->Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Float32Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Float32Array* localArray = V8DOM::toClassPtr<V8Float32Array::V8Float32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsNumber()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + float localValue = args[1]->ToNumber()->Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<float> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToNumber()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Float32Array::hasInstance(args[0])) { + uscxml::Float32Array* localArray = V8DOM::toClassPtr<V8Float32Array::V8Float32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<float> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToNumber()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Float32Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Float32ArrayPrivate* privData = V8DOM::toClassPtr<V8Float32ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Float32Array* retVal = new uscxml::Float32Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Float32Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Float32Array* retVal = new uscxml::Float32Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Float32Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Float32Array::V8Float32ArrayPrivate* retPrivData = new V8Float32Array::V8Float32ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Float32Array::V8Float32ArrayPrivate* retPrivData = new V8Float32Array::V8Float32ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Float32Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Float32Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Float32Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.h index ffb5fa7..0eec20f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float32Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Float32Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Float32Array::indexedPropertyCustomGetter, V8Float32Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Float32Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Float32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Float32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Float32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Float32Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp index 3dc69d0..92d468d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Float64Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Float64Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Float64Array::Constr; +v8::Handle<v8::Value> V8Float64Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Float64Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Float64Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Float64Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Float64Array::hasInstance(args[0])) { + + uscxml::Float64Array* localArray = V8DOM::toClassPtr<V8Float64Array::V8Float64ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Float64Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Float64Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Float64Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<double> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToNumber()->Value()); + } + localInstance = new uscxml::Float64Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Float64Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Float64Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Float64Array::V8Float64ArrayPrivate* retPrivData = new V8Float64Array::V8Float64ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Float64Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Float64Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Float64Array::lengthAttrGetter(v8::Local<v8::String> pro return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Float64Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Float64ArrayPrivate* privData = V8DOM::toClassPtr<V8Float64ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - double retVal = privData->nativeObj->get(localIndex); + double retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Float64Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Float64ArrayPrivate* privData = V8DOM::toClassPtr<V8Float64ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - double localValue = args[1]->ToNumber()->Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Float64Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Float64Array* localArray = V8DOM::toClassPtr<V8Float64Array::V8Float64ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsNumber()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + double localValue = args[1]->ToNumber()->Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<double> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToNumber()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Float64Array::hasInstance(args[0])) { + uscxml::Float64Array* localArray = V8DOM::toClassPtr<V8Float64Array::V8Float64ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<double> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToNumber()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Float64Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Float64ArrayPrivate* privData = V8DOM::toClassPtr<V8Float64ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Float64Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Float64Array* retVal = new uscxml::Float64Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Float64Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Float64Array::V8Float64ArrayPrivate* retPrivData = new V8Float64Array::V8Float64ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Float64Array::V8Float64ArrayPrivate* retPrivData = new V8Float64Array::V8Float64ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Float64Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Float64Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Float64Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.h index 8537a09..bd7755e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Float64Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Float64Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Float64Array::indexedPropertyCustomGetter, V8Float64Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Float64Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Float64Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Float64Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Float64Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Float64Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(8), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(8), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp index ba268da..d8f63f2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Int16Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Int16Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Int16Array::Constr; +v8::Handle<v8::Value> V8Int16Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Int16Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int16Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int16Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Int16Array::hasInstance(args[0])) { + + uscxml::Int16Array* localArray = V8DOM::toClassPtr<V8Int16Array::V8Int16ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Int16Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Int16Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int16Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<short> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInt32()->Value()); + } + localInstance = new uscxml::Int16Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Int16Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Int16Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Int16Array::V8Int16ArrayPrivate* retPrivData = new V8Int16Array::V8Int16ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Int16Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Int16Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Int16Array::lengthAttrGetter(v8::Local<v8::String> prope return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Int16Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Int16ArrayPrivate* privData = V8DOM::toClassPtr<V8Int16ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - short retVal = privData->nativeObj->get(localIndex); + short retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Int16Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Int16ArrayPrivate* privData = V8DOM::toClassPtr<V8Int16ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - short localValue = args[1]->ToNumber()->Int32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Int16Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Int16Array* localArray = V8DOM::toClassPtr<V8Int16Array::V8Int16ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsInt32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + short localValue = args[1]->ToNumber()->Int32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<short> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInt32()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Int16Array::hasInstance(args[0])) { + uscxml::Int16Array* localArray = V8DOM::toClassPtr<V8Int16Array::V8Int16ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<short> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInt32()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Int16Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Int16ArrayPrivate* privData = V8DOM::toClassPtr<V8Int16ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Int16Array* retVal = new uscxml::Int16Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Int16Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Int16Array* retVal = new uscxml::Int16Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Int16Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Int16Array::V8Int16ArrayPrivate* retPrivData = new V8Int16Array::V8Int16ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Int16Array::V8Int16ArrayPrivate* retPrivData = new V8Int16Array::V8Int16ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Int16Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Int16Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Int16Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.h index e221cdd..ea5cc21 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int16Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Int16Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Int16Array::indexedPropertyCustomGetter, V8Int16Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Int16Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Int16Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Int16Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Int16Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Int16Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp index 5d00d46..5c2d130 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Int32Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Int32Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Int32Array::Constr; +v8::Handle<v8::Value> V8Int32Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Int32Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int32Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int32Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Int32Array::hasInstance(args[0])) { + + uscxml::Int32Array* localArray = V8DOM::toClassPtr<V8Int32Array::V8Int32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Int32Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Int32Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int32Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<long> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInteger()->Value()); + } + localInstance = new uscxml::Int32Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Int32Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Int32Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Int32Array::V8Int32ArrayPrivate* retPrivData = new V8Int32Array::V8Int32ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Int32Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Int32Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Int32Array::lengthAttrGetter(v8::Local<v8::String> prope return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Int32Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Int32ArrayPrivate* privData = V8DOM::toClassPtr<V8Int32ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - long retVal = privData->nativeObj->get(localIndex); + long retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Int32Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Int32ArrayPrivate* privData = V8DOM::toClassPtr<V8Int32ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - long localValue = args[1]->ToNumber()->Int32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Int32Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Int32Array* localArray = V8DOM::toClassPtr<V8Int32Array::V8Int32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsInt32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + long localValue = args[1]->ToNumber()->Int32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<long> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInteger()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Int32Array::hasInstance(args[0])) { + uscxml::Int32Array* localArray = V8DOM::toClassPtr<V8Int32Array::V8Int32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<long> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInteger()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Int32Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Int32ArrayPrivate* privData = V8DOM::toClassPtr<V8Int32ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Int32Array* retVal = new uscxml::Int32Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Int32Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Int32Array* retVal = new uscxml::Int32Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Int32Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Int32Array::V8Int32ArrayPrivate* retPrivData = new V8Int32Array::V8Int32ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Int32Array::V8Int32ArrayPrivate* retPrivData = new V8Int32Array::V8Int32ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Int32Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Int32Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Int32Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.h index 892b666..d3c5b71 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int32Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Int32Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Int32Array::indexedPropertyCustomGetter, V8Int32Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Int32Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Int32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Int32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Int32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Int32Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp index fd64a8c..d78be76 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Int8Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Int8Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Int8Array::Constr; +v8::Handle<v8::Value> V8Int8Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Int8Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int8Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int8Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Int8Array::hasInstance(args[0])) { + + uscxml::Int8Array* localArray = V8DOM::toClassPtr<V8Int8Array::V8Int8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Int8Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Int8Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Int8Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInt32()->Value()); + } + localInstance = new uscxml::Int8Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Int8Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Int8Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Int8Array::V8Int8ArrayPrivate* retPrivData = new V8Int8Array::V8Int8ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Int8Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Int8Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Int8Array::lengthAttrGetter(v8::Local<v8::String> proper return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Int8Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Int8ArrayPrivate* privData = V8DOM::toClassPtr<V8Int8ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - char retVal = privData->nativeObj->get(localIndex); + char retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Int8Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Int8ArrayPrivate* privData = V8DOM::toClassPtr<V8Int8ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - char localValue = args[1]->ToNumber()->Int32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Int8Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Int8Array* localArray = V8DOM::toClassPtr<V8Int8Array::V8Int8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsInt32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + char localValue = args[1]->ToNumber()->Int32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInt32()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Int8Array::hasInstance(args[0])) { + uscxml::Int8Array* localArray = V8DOM::toClassPtr<V8Int8Array::V8Int8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToInt32()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Int8Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Int8ArrayPrivate* privData = V8DOM::toClassPtr<V8Int8ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Int8Array* retVal = new uscxml::Int8Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Int8Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Int8Array* retVal = new uscxml::Int8Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Int8Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Int8Array::V8Int8ArrayPrivate* retPrivData = new V8Int8Array::V8Int8ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Int8Array::V8Int8ArrayPrivate* retPrivData = new V8Int8Array::V8Int8ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Int8Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Int8Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Int8Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.h index bcfcc3c..2802c5f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Int8Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Int8Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Int8Array::indexedPropertyCustomGetter, V8Int8Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Int8Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Int8Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Int8Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Int8Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Int8Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp index 037d651..a405fd0 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp @@ -6,180 +6,205 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8NamedNodeMap::Tmpl; - v8::Handle<v8::Value> V8NamedNodeMap::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8NamedNodeMap::getNamedItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getNamedItem"); v8::Local<v8::Object> self = args.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItem(*localName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItem(*localName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getNamedItem"); + return v8::Undefined(); } v8::Handle<v8::Value> V8NamedNodeMap::setNamedItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setNamedItem"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setNamedItem"); v8::Local<v8::Object> self = args.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Node::hasInstance(args[0])) { + Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItem(*localArg)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItem(*localArg)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling setNamedItem"); + return v8::Undefined(); } v8::Handle<v8::Value> V8NamedNodeMap::removeNamedItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeNamedItem"); v8::Local<v8::Object> self = args.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localName(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localName(args[0]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItem(*localName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItem(*localName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling removeNamedItem"); + return v8::Undefined(); } v8::Handle<v8::Value> V8NamedNodeMap::itemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in item"); v8::Local<v8::Object> self = args.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling item"); + return v8::Undefined(); } v8::Handle<v8::Value> V8NamedNodeMap::getNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in getNamedItemNS"); v8::Local<v8::Object> self = args.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItemNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->getNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling getNamedItemNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8NamedNodeMap::setNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in setNamedItemNS"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling setNamedItemNS"); v8::Local<v8::Object> self = args.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Node::hasInstance(args[0])) { + Arabica::DOM::Node<std::string>* localArg = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItemNS(*localArg)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->setNamedItemNS(*localArg)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling setNamedItemNS"); + return v8::Undefined(); } v8::Handle<v8::Value> V8NamedNodeMap::removeNamedItemNSCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in removeNamedItemNS"); v8::Local<v8::Object> self = args.Holder(); struct V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr<V8NamedNodeMapPrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localNamespaceURI(args[0]); - v8::String::AsciiValue localLocalName(args[1]); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItemNS(*localNamespaceURI, *localLocalName)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling removeNamedItemNS"); + return v8::Undefined(); } - bool V8NamedNodeMap::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp index c5b1b83..9d0cd62 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp @@ -7,7 +7,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Node::Tmpl; - v8::Handle<v8::Value> V8Node::nodeNameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); @@ -203,175 +202,209 @@ v8::Handle<v8::Value> V8Node::localNameAttrGetter(v8::Local<v8::String> property return v8::String::New(privData->nativeObj->getLocalName().c_str()); } + v8::Handle<v8::Value> V8Node::insertBeforeCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in insertBefore"); - if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) - throw V8Exception("Parameter mismatch while calling insertBefore"); v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* localRefChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Node::hasInstance(args[0]) && + args[1]->IsObject() && V8Node::hasInstance(args[1])) { + Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + Arabica::DOM::Node<std::string>* localRefChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->insertBefore(*localNewChild, *localRefChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling insertBefore"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Node::replaceChildCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in replaceChild"); - if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) - throw V8Exception("Parameter mismatch while calling replaceChild"); v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Node::hasInstance(args[0]) && + args[1]->IsObject() && V8Node::hasInstance(args[1])) { + Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[1]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->replaceChild(*localNewChild, *localOldChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling replaceChild"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Node::removeChildCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeChild"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling removeChild"); v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Node::hasInstance(args[0])) { + Arabica::DOM::Node<std::string>* localOldChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeChild(*localOldChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->removeChild(*localOldChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling removeChild"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Node::appendChildCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in appendChild"); - if (!(V8Node::hasInstance(args[0]))) - throw V8Exception("Parameter mismatch while calling appendChild"); v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + if (false) { + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Node::hasInstance(args[0])) { + Arabica::DOM::Node<std::string>* localNewChild = V8DOM::toClassPtr<V8Node::V8NodePrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->appendChild(*localNewChild)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->appendChild(*localNewChild)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling appendChild"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Node::hasChildNodesCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - bool retVal = privData->nativeObj->hasChildNodes(); + bool retVal = privData->nativeObj->hasChildNodes(); - return v8::Boolean::New(retVal); + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling hasChildNodes"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Node::cloneNodeCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in cloneNode"); v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - bool localDeep = args[0]->ToBoolean()->BooleanValue(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsBoolean()) { + bool localDeep = args[0]->ToBoolean()->BooleanValue(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->cloneNode(localDeep)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->cloneNode(localDeep)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling cloneNode"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Node::normalizeCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - privData->nativeObj->normalize(); + privData->nativeObj->normalize(); + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling normalize"); return v8::Undefined(); } v8::Handle<v8::Value> V8Node::isSupportedCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in isSupported"); v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localFeature(args[0]); - v8::String::AsciiValue localVersion(args[1]); - - bool retVal = privData->nativeObj->isSupported(*localFeature, *localVersion); - - return v8::Boolean::New(retVal); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localFeature(args[0]); + v8::String::AsciiValue localVersion(args[1]); + + bool retVal = privData->nativeObj->isSupported(*localFeature, *localVersion); + + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling isSupported"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Node::hasAttributesCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8NodePrivate* privData = V8DOM::toClassPtr<V8NodePrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - bool retVal = privData->nativeObj->hasAttributes(); + bool retVal = privData->nativeObj->hasAttributes(); - return v8::Boolean::New(retVal); + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling hasAttributes"); + return v8::Undefined(); } - bool V8Node::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp index bee706e..4f37d14 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp @@ -6,36 +6,39 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8NodeList::Tmpl; - v8::Handle<v8::Value> V8NodeList::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8NodeListPrivate* privData = V8DOM::toClassPtr<V8NodeListPrivate >(self->GetInternalField(0)); return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8NodeList::itemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in item"); v8::Local<v8::Object> self = args.Holder(); struct V8NodeListPrivate* privData = V8DOM::toClassPtr<V8NodeListPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); - v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Node<std::string>* retVal = new Arabica::DOM::Node<std::string>(privData->nativeObj->item(localIndex)); + v8::Handle<v8::Function> retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Node::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling item"); + return v8::Undefined(); } - bool V8NodeList::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp index fade729..4580ef4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp @@ -5,7 +5,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8NodeSet::Tmpl; - v8::Handle<v8::Value> V8NodeSet::sizeAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); @@ -19,16 +18,21 @@ v8::Handle<v8::Value> V8NodeSet::emptyAttrGetter(v8::Local<v8::String> property, return v8::Boolean::New(privData->nativeObj->empty()); } + v8::Handle<v8::Value> V8NodeSet::toDocumentOrderCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8NodeSetPrivate* privData = V8DOM::toClassPtr<V8NodeSetPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - privData->nativeObj->to_document_order(); + privData->nativeObj->to_document_order(); + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling toDocumentOrder"); return v8::Undefined(); } - bool V8NodeSet::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp index 129563d..6a53ba6 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp @@ -6,7 +6,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Notation::Tmpl; - v8::Handle<v8::Value> V8Notation::publicIdAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8NotationPrivate* privData = V8DOM::toClassPtr<V8NotationPrivate >(self->GetInternalField(0)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp index c6d2b28..1b819d8 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp @@ -6,7 +6,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8ProcessingInstruction::Tmpl; - v8::Handle<v8::Value> V8ProcessingInstruction::targetAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr<V8ProcessingInstructionPrivate >(self->GetInternalField(0)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp index 9679d74..0f750ee 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8SCXMLEvent.cpp @@ -6,7 +6,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8SCXMLEvent::Tmpl; - v8::Handle<v8::Value> V8SCXMLEvent::nameAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8SCXMLEventPrivate* privData = V8DOM::toClassPtr<V8SCXMLEventPrivate >(self->GetInternalField(0)); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp index d9ab828..7cd90f9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Storage.cpp @@ -5,63 +5,80 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Storage::Tmpl; - v8::Handle<v8::Value> V8Storage::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Storage::keyCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in key"); v8::Local<v8::Object> self = args.Holder(); struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - std::string retVal = privData->nativeObj->key(localIndex); + std::string retVal = privData->nativeObj->key(localIndex); - return v8::String::New(retVal.c_str()); + return v8::String::New(retVal.c_str()); + } + throw V8Exception("Parameter mismatch while calling key"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Storage::getItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in getItem"); v8::Local<v8::Object> self = args.Holder(); struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localKey(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localKey(args[0]); - std::string retVal = privData->nativeObj->getItem(*localKey); + std::string retVal = privData->nativeObj->getItem(*localKey); - return v8::String::New(retVal.c_str()); + return v8::String::New(retVal.c_str()); + } + throw V8Exception("Parameter mismatch while calling getItem"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Storage::setItemCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in setItem"); v8::Local<v8::Object> self = args.Holder(); struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localKey(args[0]); - v8::String::AsciiValue localValue(args[1]); - - privData->nativeObj->setItem(*localKey, *localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsString() && + args[1]->IsString()) { + v8::String::AsciiValue localKey(args[0]); + v8::String::AsciiValue localValue(args[1]); + + privData->nativeObj->setItem(*localKey, *localValue); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling setItem"); return v8::Undefined(); } v8::Handle<v8::Value> V8Storage::removeItemCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in removeItem"); v8::Local<v8::Object> self = args.Holder(); struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); - v8::String::AsciiValue localKey(args[0]); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsString()) { + v8::String::AsciiValue localKey(args[0]); - privData->nativeObj->removeItem(*localKey); + privData->nativeObj->removeItem(*localKey); + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling removeItem"); return v8::Undefined(); } @@ -69,12 +86,16 @@ v8::Handle<v8::Value> V8Storage::clearCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8StoragePrivate* privData = V8DOM::toClassPtr<V8StoragePrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - privData->nativeObj->clear(); + privData->nativeObj->clear(); + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling clear"); return v8::Undefined(); } - bool V8Storage::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp index 42b298a..c37970f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp @@ -7,28 +7,31 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Text::Tmpl; v8::Handle<v8::Value> V8Text::splitTextCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in splitText"); v8::Local<v8::Object> self = args.Holder(); struct V8TextPrivate* privData = V8DOM::toClassPtr<V8TextPrivate >(self->GetInternalField(0)); - unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); - Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->splitText(localOffset)); - v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::DOM::Text<std::string>* retVal = new Arabica::DOM::Text<std::string>(privData->nativeObj->splitText(localOffset)); + v8::Handle<v8::Function> retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Text::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Text::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling splitText"); + return v8::Undefined(); } - bool V8Text::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8TypedArrayCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8TypedArrayCustom.cpp new file mode 100644 index 0000000..118eb46 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8TypedArrayCustom.cpp @@ -0,0 +1,144 @@ +#include "../../TypedArray.h" +#include "V8ArrayBuffer.h" +#include "V8Int8Array.h" +#include "V8Uint8Array.h" +#include "V8Uint8ClampedArray.h" +#include "V8Int16Array.h" +#include "V8Uint16Array.h" +#include "V8Int32Array.h" +#include "V8Uint32Array.h" +#include "V8Float32Array.h" +#include "V8Float64Array.h" +#include "V8DataView.h" + +#define V8_TYPED_ARRAY_GET_PRIVATE(type) \ +v8::Local<v8::Object> self = info.Holder(); \ +uscxml::type* array = V8DOM::toClassPtr<V8##type##Private >(self->GetInternalField(0))->nativeObj; \ +if (index > array->getLength()) \ + return v8::Undefined(); + + +namespace Arabica { +namespace DOM { + +v8::Handle<v8::Value> V8Int8Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Int8Array); + array->set(index, value->ToInt32()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Int16Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Int16Array); + array->set(index, value->ToInt32()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Int32Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Int32Array); + array->set(index, value->ToInt32()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Uint8Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint8Array); + array->set(index, value->ToUint32()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Uint16Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint16Array); + array->set(index, value->ToUint32()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Uint32Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint32Array); + array->set(index, value->ToUint32()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Float32Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Float32Array); + array->set(index, value->ToNumber()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Float64Array::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Float64Array); + array->set(index, value->ToNumber()->Value()); + return value; +} + +v8::Handle<v8::Value> V8Uint8ClampedArray::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint8ClampedArray); + array->set(index, value->ToUint32()->Value() & 0xff); + return value; +} + +v8::Handle<v8::Value> V8ArrayBuffer::indexedPropertyCustomSetter(unsigned int index, v8::Local<v8::Value> value, const v8::AccessorInfo &info) { + v8::Local<v8::Object> self = info.Holder(); + uscxml::ArrayBuffer* array = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0))->nativeObj; + if (index > array->getByteLength()) + return v8::Undefined(); + array->_buffer->_data[index] = value->ToInt32()->Value() & 0xff; + return value; + +} + +// ---------------- + +v8::Handle<v8::Value> V8Int8Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Int8Array); + return v8::Int32::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Int16Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Int16Array); + return v8::Int32::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Int32Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Int32Array); + return v8::Int32::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Uint8Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint8Array); + return v8::Uint32::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Uint16Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint16Array); + return v8::Uint32::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Uint32Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint32Array); + return v8::Uint32::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Float32Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Float32Array); + return v8::Number::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Float64Array::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Float64Array); + return v8::Number::New(array->get(index)); +} + +v8::Handle<v8::Value> V8Uint8ClampedArray::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + V8_TYPED_ARRAY_GET_PRIVATE(Uint8ClampedArray); + return v8::Uint32::New(array->get(index)); +} + +v8::Handle<v8::Value> V8ArrayBuffer::indexedPropertyCustomGetter(unsigned int index, const v8::AccessorInfo &info) { + v8::Local<v8::Object> self = info.Holder(); + uscxml::ArrayBuffer* array = V8DOM::toClassPtr<V8ArrayBufferPrivate >(self->GetInternalField(0))->nativeObj; + if (index > array->getByteLength()) + return v8::Undefined(); + return v8::Int32::New(array->_buffer->_data[index]); +} + +} +}
\ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp index c1d94d7..4c84081 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Uint16Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Uint16Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Uint16Array::Constr; +v8::Handle<v8::Value> V8Uint16Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Uint16Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint16Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint16Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint16Array::hasInstance(args[0])) { + + uscxml::Uint16Array* localArray = V8DOM::toClassPtr<V8Uint16Array::V8Uint16ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint16Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint16Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint16Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<unsigned short> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + localInstance = new uscxml::Uint16Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Uint16Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Uint16Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Uint16Array::V8Uint16ArrayPrivate* retPrivData = new V8Uint16Array::V8Uint16ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Uint16Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Uint16Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Uint16Array::lengthAttrGetter(v8::Local<v8::String> prop return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Uint16Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint16ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint16ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - unsigned short retVal = privData->nativeObj->get(localIndex); + unsigned short retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Uint16Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint16ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint16ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - unsigned short localValue = args[1]->ToNumber()->Uint32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Uint16Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Uint16Array* localArray = V8DOM::toClassPtr<V8Uint16Array::V8Uint16ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + unsigned short localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<unsigned short> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint16Array::hasInstance(args[0])) { + uscxml::Uint16Array* localArray = V8DOM::toClassPtr<V8Uint16Array::V8Uint16ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<unsigned short> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Uint16Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint16ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint16ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Uint16Array* retVal = new uscxml::Uint16Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Uint16Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Uint16Array* retVal = new uscxml::Uint16Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Uint16Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Uint16Array::V8Uint16ArrayPrivate* retPrivData = new V8Uint16Array::V8Uint16ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Uint16Array::V8Uint16ArrayPrivate* retPrivData = new V8Uint16Array::V8Uint16ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Uint16Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Uint16Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Uint16Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.h index e4d237d..ca9a40a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint16Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Uint16Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Uint16Array::indexedPropertyCustomGetter, V8Uint16Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Uint16Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Uint16Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint16Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint16Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Uint16Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(2), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp index 54b05aa..da3fdc2 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Uint32Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Uint32Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Uint32Array::Constr; +v8::Handle<v8::Value> V8Uint32Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Uint32Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint32Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint32Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint32Array::hasInstance(args[0])) { + + uscxml::Uint32Array* localArray = V8DOM::toClassPtr<V8Uint32Array::V8Uint32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint32Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint32Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint32Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<unsigned long> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + localInstance = new uscxml::Uint32Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Uint32Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Uint32Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Uint32Array::V8Uint32ArrayPrivate* retPrivData = new V8Uint32Array::V8Uint32ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Uint32Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Uint32Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Uint32Array::lengthAttrGetter(v8::Local<v8::String> prop return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Uint32Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint32ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint32ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - unsigned long retVal = privData->nativeObj->get(localIndex); + unsigned long retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Uint32Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint32ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint32ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - unsigned long localValue = args[1]->ToNumber()->Uint32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Uint32Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Uint32Array* localArray = V8DOM::toClassPtr<V8Uint32Array::V8Uint32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + unsigned long localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<unsigned long> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint32Array::hasInstance(args[0])) { + uscxml::Uint32Array* localArray = V8DOM::toClassPtr<V8Uint32Array::V8Uint32ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<unsigned long> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Uint32Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint32ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint32ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Uint32Array* retVal = new uscxml::Uint32Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Uint32Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Uint32Array* retVal = new uscxml::Uint32Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Uint32Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Uint32Array::V8Uint32ArrayPrivate* retPrivData = new V8Uint32Array::V8Uint32ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Uint32Array::V8Uint32ArrayPrivate* retPrivData = new V8Uint32Array::V8Uint32ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Uint32Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Uint32Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Uint32Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.h index 09098aa..a119719 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint32Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Uint32Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Uint32Array::indexedPropertyCustomGetter, V8Uint32Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Uint32Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Uint32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint32Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Uint32Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(4), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp index cc13bf0..b2eafe5 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Uint8Array.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Uint8Array::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Uint8Array::Constr; +v8::Handle<v8::Value> V8Uint8Array::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Uint8Array* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8Array(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8Array(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint8Array::hasInstance(args[0])) { + + uscxml::Uint8Array* localArray = V8DOM::toClassPtr<V8Uint8Array::V8Uint8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint8Array(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint8Array(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8Array(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + localInstance = new uscxml::Uint8Array(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Uint8Array"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Uint8Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Uint8Array::V8Uint8ArrayPrivate* retPrivData = new V8Uint8Array::V8Uint8ArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Uint8Array::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Uint8Array::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Uint8Array::lengthAttrGetter(v8::Local<v8::String> prope return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Uint8Array::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - char retVal = privData->nativeObj->get(localIndex); + unsigned char retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Uint8Array::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - unsigned char localValue = args[1]->ToNumber()->Uint32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Uint8Array::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Uint8Array* localArray = V8DOM::toClassPtr<V8Uint8Array::V8Uint8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + unsigned char localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint8Array::hasInstance(args[0])) { + uscxml::Uint8Array* localArray = V8DOM::toClassPtr<V8Uint8Array::V8Uint8ArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Uint8Array::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Uint8Array::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Uint8Array* retVal = new uscxml::Uint8Array(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Uint8Array::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Uint8Array::V8Uint8ArrayPrivate* retPrivData = new V8Uint8Array::V8Uint8ArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Uint8Array::V8Uint8ArrayPrivate* retPrivData = new V8Uint8Array::V8Uint8ArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Uint8Array::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Uint8Array::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Uint8Array::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.h index e59d8a6..e32007f 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8Array.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Uint8Array::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Uint8Array::indexedPropertyCustomGetter, V8Uint8Array::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Uint8Array::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Uint8Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint8Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint8Array::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Uint8Array::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp index 64c8d95..206b755 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.cpp @@ -1,10 +1,82 @@ +#include "V8ArrayBuffer.h" +#include "V8ArrayBufferView.h" #include "V8Uint8ClampedArray.h" namespace Arabica { namespace DOM { v8::Persistent<v8::FunctionTemplate> V8Uint8ClampedArray::Tmpl; +v8::Persistent<v8::FunctionTemplate> V8Uint8ClampedArray::Constr; +v8::Handle<v8::Value> V8Uint8ClampedArray::constructor(const v8::Arguments& args) { + if (!args.IsConstructCall()) + return v8::ThrowException(v8::String::New("Cannot call constructor as function")); + + uscxml::Uint8ClampedArray* localInstance = NULL; + if (false) { + } else if (args.Length() == 3 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32() && + args[2]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + unsigned long localLength = args[2]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8ClampedArray(localBuffer, localByteOffset, localLength); + + } else if (args.Length() == 2 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0]) && + args[1]->IsUint32()) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localByteOffset = args[1]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8ClampedArray(localBuffer, localByteOffset); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint8ClampedArray::hasInstance(args[0])) { + + uscxml::Uint8ClampedArray* localArray = V8DOM::toClassPtr<V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint8ClampedArray(localArray); + + } else if (args.Length() == 1 && + args[0]->IsObject() && V8ArrayBuffer::hasInstance(args[0])) { + + uscxml::ArrayBuffer* localBuffer = V8DOM::toClassPtr<V8ArrayBuffer::V8ArrayBufferPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + localInstance = new uscxml::Uint8ClampedArray(localBuffer); + + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + + unsigned long localLength = args[0]->ToNumber()->Uint32Value(); + localInstance = new uscxml::Uint8ClampedArray(localLength); + + } else if (args.Length() == 1 && + args[0]->IsArray()) { + + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + localInstance = new uscxml::Uint8ClampedArray(localArray); + + } + if (!localInstance) { + throw V8Exception("Parameter mismatch while calling constructor for Uint8ClampedArray"); + return v8::Undefined(); + } + + v8::Handle<v8::Function> retCtor = V8Uint8ClampedArray::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + + struct V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate* retPrivData = new V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate(); + retPrivData->nativeObj = localInstance; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Uint8ClampedArray::jsDestructor); + return retObj; +} v8::Handle<v8::Value> V8Uint8ClampedArray::lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); @@ -12,57 +84,111 @@ v8::Handle<v8::Value> V8Uint8ClampedArray::lengthAttrGetter(v8::Local<v8::String return v8::Integer::New(privData->nativeObj->getLength()); } + v8::Handle<v8::Value> V8Uint8ClampedArray::getCallback(const v8::Arguments& args) { - if (args.Length() < 1) - throw V8Exception("Wrong number of arguments in get"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ClampedArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ClampedArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + if (false) { + } else if (args.Length() == 1 && + args[0]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - char retVal = privData->nativeObj->get(localIndex); + unsigned char retVal = privData->nativeObj->get(localIndex); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling get"); + return v8::Undefined(); } v8::Handle<v8::Value> V8Uint8ClampedArray::setCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in set"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ClampedArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ClampedArrayPrivate >(self->GetInternalField(0)); - unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); - unsigned char localValue = args[1]->ToNumber()->Uint32Value(); - - privData->nativeObj->set(localIndex, localValue); - + if (false) { + } else if (args.Length() == 2 && + args[0]->IsObject() && V8Uint8ClampedArray::hasInstance(args[0]) && + args[1]->IsUint32()) { + uscxml::Uint8ClampedArray* localArray = V8DOM::toClassPtr<V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsUint32() && + args[1]->IsUint32()) { + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + unsigned char localValue = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localIndex, localValue); + + return v8::Undefined(); + } else if (args.Length() == 2 && + args[0]->IsArray() && + args[1]->IsUint32()) { + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + unsigned long localOffset = args[1]->ToNumber()->Uint32Value(); + + privData->nativeObj->set(localArray, localOffset); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsObject() && V8Uint8ClampedArray::hasInstance(args[0])) { + uscxml::Uint8ClampedArray* localArray = V8DOM::toClassPtr<V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate >(args[0]->ToObject()->GetInternalField(0))->nativeObj; + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } else if (args.Length() == 1 && + args[0]->IsArray()) { + std::vector<unsigned char> localArray; + v8::Handle<v8::Array> localArrayArray(v8::Array::Cast(*args[0])); + for (int i = 0; i < localArrayArray->Length(); i++) { + localArray.push_back(localArrayArray->Get(i)->ToUint32()->Value()); + } + + privData->nativeObj->set(localArray); + + return v8::Undefined(); + } + throw V8Exception("Parameter mismatch while calling set"); return v8::Undefined(); } v8::Handle<v8::Value> V8Uint8ClampedArray::subarrayCallback(const v8::Arguments& args) { - if (args.Length() < 2) - throw V8Exception("Wrong number of arguments in subarray"); v8::Local<v8::Object> self = args.Holder(); struct V8Uint8ClampedArrayPrivate* privData = V8DOM::toClassPtr<V8Uint8ClampedArrayPrivate >(self->GetInternalField(0)); - long localStart = args[0]->ToNumber()->Int32Value(); - long localEnd = args[1]->ToNumber()->Int32Value(); + if (false) { + } else if (args.Length() == 2 && + args[0]->IsInt32() && + args[1]->IsInt32()) { + long localStart = args[0]->ToNumber()->Int32Value(); + long localEnd = args[1]->ToNumber()->Int32Value(); - uscxml::Uint8ClampedArray* retVal = new uscxml::Uint8ClampedArray(privData->nativeObj->subarray(localStart, localEnd)); - v8::Handle<v8::Function> retCtor = V8Uint8ClampedArray::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + uscxml::Uint8ClampedArray* retVal = new uscxml::Uint8ClampedArray(privData->nativeObj->subarray(localStart, localEnd)); + v8::Handle<v8::Function> retCtor = V8Uint8ClampedArray::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate* retPrivData = new V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate* retPrivData = new V8Uint8ClampedArray::V8Uint8ClampedArrayPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8Uint8ClampedArray::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8Uint8ClampedArray::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling subarray"); + return v8::Undefined(); } - bool V8Uint8ClampedArray::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.h index 37f9482..8e130f4 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Uint8ClampedArray.h @@ -24,6 +24,7 @@ #include <string> #include "../../TypedArray.h" #include "DOM/Node.hpp" +#include "V8ArrayBufferView.h" #include "string" #include "uscxml/plugins/datamodel/ecmascript/v8/V8DOM.h" #include <v8.h> @@ -46,6 +47,18 @@ public: static v8::Handle<v8::Value> subarrayCallback(const v8::Arguments&); static v8::Handle<v8::Value> lengthAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info); + static v8::Handle<v8::Value> indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Handle<v8::Value> indexedPropertyCustomSetter(uint32_t, v8::Local<v8::Value>, const v8::AccessorInfo&); + + static v8::Handle<v8::Value> constructor(const v8::Arguments&); + static v8::Persistent<v8::FunctionTemplate> Constr; + static v8::Handle<v8::FunctionTemplate> getConstructor() { + if (Constr.IsEmpty()) { + v8::Handle<v8::FunctionTemplate> constr = v8::FunctionTemplate::New(constructor); + Constr = v8::Persistent<v8::FunctionTemplate>::New(constr); + } + return Constr; + } static v8::Persistent<v8::FunctionTemplate> Tmpl; static v8::Handle<v8::FunctionTemplate> getTmpl() { @@ -63,20 +76,18 @@ public: instance->SetAccessor(v8::String::NewSymbol("length"), V8Uint8ClampedArray::lengthAttrGetter, 0, v8::External::New(0), static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None)); + instance->SetIndexedPropertyHandler(V8Uint8ClampedArray::indexedPropertyCustomGetter, V8Uint8ClampedArray::indexedPropertyCustomSetter); prototype->Set(v8::String::NewSymbol("get"), v8::FunctionTemplate::New(V8Uint8ClampedArray::getCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("set"), v8::FunctionTemplate::New(V8Uint8ClampedArray::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint8ClampedArray::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("set"), - v8::FunctionTemplate::New(V8Uint8ClampedArray::setCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); prototype->Set(v8::String::NewSymbol("subarray"), v8::FunctionTemplate::New(V8Uint8ClampedArray::subarrayCallback, v8::Undefined()), static_cast<v8::PropertyAttribute>(v8::DontDelete)); tmpl->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); prototype->Set(v8::String::NewSymbol("BYTES_PER_ELEMENT"), v8::Integer::New(1), static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontEnum)); + tmpl->Inherit(V8ArrayBufferView::getTmpl()); Tmpl = v8::Persistent<v8::FunctionTemplate>::New(tmpl); } return Tmpl; diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp index 968e53d..265bcfe 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp @@ -6,7 +6,6 @@ namespace DOM { v8::Persistent<v8::FunctionTemplate> V8XPathResult::Tmpl; - v8::Handle<v8::Value> V8XPathResult::numberValueAttrGetter(v8::Local<v8::String> property, const v8::AccessorInfo& info) { v8::Local<v8::Object> self = info.Holder(); struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); @@ -27,56 +26,76 @@ v8::Handle<v8::Value> V8XPathResult::booleanValueAttrGetter(v8::Local<v8::String return v8::Boolean::New(privData->nativeObj->asBool()); } + v8::Handle<v8::Value> V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - Arabica::XPath::NodeSet<std::string>* retVal = new Arabica::XPath::NodeSet<std::string>(privData->nativeObj->asNodeSet()); - v8::Handle<v8::Function> retCtor = V8NodeSet::getTmpl()->GetFunction(); - v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); + Arabica::XPath::NodeSet<std::string>* retVal = new Arabica::XPath::NodeSet<std::string>(privData->nativeObj->asNodeSet()); + v8::Handle<v8::Function> retCtor = V8NodeSet::getTmpl()->GetFunction(); + v8::Persistent<v8::Object> retObj = v8::Persistent<v8::Object>::New(retCtor->NewInstance()); - struct V8NodeSet::V8NodeSetPrivate* retPrivData = new V8NodeSet::V8NodeSetPrivate(); - retPrivData->dom = privData->dom; - retPrivData->nativeObj = retVal; + struct V8NodeSet::V8NodeSetPrivate* retPrivData = new V8NodeSet::V8NodeSetPrivate(); + retPrivData->dom = privData->dom; + retPrivData->nativeObj = retVal; - retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); - retObj.MakeWeak(0, V8NodeSet::jsDestructor); - return retObj; + retObj.MakeWeak(0, V8NodeSet::jsDestructor); + return retObj; + } + throw V8Exception("Parameter mismatch while calling asNodeSet"); + return v8::Undefined(); } v8::Handle<v8::Value> V8XPathResult::asBoolCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - bool retVal = privData->nativeObj->asBool(); + bool retVal = privData->nativeObj->asBool(); - return v8::Boolean::New(retVal); + return v8::Boolean::New(retVal); + } + throw V8Exception("Parameter mismatch while calling asBool"); + return v8::Undefined(); } v8::Handle<v8::Value> V8XPathResult::asStringCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - std::string retVal = privData->nativeObj->asString(); + std::string retVal = privData->nativeObj->asString(); - return v8::String::New(retVal.c_str()); + return v8::String::New(retVal.c_str()); + } + throw V8Exception("Parameter mismatch while calling asString"); + return v8::Undefined(); } v8::Handle<v8::Value> V8XPathResult::asNumberCallback(const v8::Arguments& args) { v8::Local<v8::Object> self = args.Holder(); struct V8XPathResultPrivate* privData = V8DOM::toClassPtr<V8XPathResultPrivate >(self->GetInternalField(0)); + if (false) { + } else if (args.Length() == 0) { - double retVal = privData->nativeObj->asNumber(); + double retVal = privData->nativeObj->asNumber(); - return v8::Number::New(retVal); + return v8::Number::New(retVal); + } + throw V8Exception("Parameter mismatch while calling asNumber"); + return v8::Undefined(); } - bool V8XPathResult::hasInstance(v8::Handle<v8::Value> value) { return getTmpl()->HasInstance(value); } |