diff options
author | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-09-01 19:18:36 (GMT) |
---|---|---|
committer | Stefan Radomski <radomski@tk.informatik.tu-darmstadt.de> | 2013-09-01 19:18:36 (GMT) |
commit | fd0778237785840ec754f98e847a524590cbf61c (patch) | |
tree | ebf4609be11843f9657810515d47faa3873c2db8 /src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp | |
parent | 99d2c52f1068b2dd4bd16b8c1c8231beeb94a649 (diff) | |
download | uscxml-fd0778237785840ec754f98e847a524590cbf61c.zip uscxml-fd0778237785840ec754f98e847a524590cbf61c.tar.gz uscxml-fd0778237785840ec754f98e847a524590cbf61c.tar.bz2 |
More work on TypedArrays
Diffstat (limited to 'src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp')
-rw-r--r-- | src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCStorage.cpp | 181 |
1 files changed, 97 insertions, 84 deletions
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); +} } } |