JSObjectSetProperty(ctx, metaobject , key , valueRef ,kJSPropertyAttributeReadOnly, NULL );
JSStringRelease(key);
JSStringRelease(value);
- }
+ }
return metaobject;
}
else if(JSStringIsEqualToUTF8CString(propertyName, "attribution")) {
delete []supportedOptionValues;
return supportedOptionArray;
}
- else if(JSStringIsEqualToUTF8CString(propertyName, "connectivity")) {
+ else if(JSStringIsEqualToUTF8CString(propertyName, "connectivity")) {
JSStringRef conn = JSStringCreateWithUTF8CString(priv->getConnectivity().c_str());
JSValueRef jsv = JSValueMakeString(ctx, conn);
JSStringRelease(conn);
return Commons::JSTizenExceptionFactory::postException(ctx,exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The object is not LocationServiceProvider instance");
}
- JSValueRef convertedArguments[3];
- JSObjectRef convertedArgumentObjects[3];
- for( unsigned int i = 0 ; i < 3; i++ ){
- if( i < argumentCount ){
- convertedArguments[i] = arguments[i];
- if( JSValueIsObject(ctx, arguments[i]) )
- convertedArgumentObjects[i] = JSValueToObject(ctx, arguments[i] , NULL );
- else
- convertedArgumentObjects[i] = NULL;
- }else{
- convertedArguments[i] = JSValueMakeUndefined(ctx);
- convertedArgumentObjects[i] = NULL;
+ JSValueRef convertedArg[3];
+ JSObjectRef convertedArgObjects[3];
+ for( unsigned int i = 0 ; i < 3; i++ )
+ {
+ if(i<argumentCount)
+ {
+ convertedArg[i] = arguments[i];
+ convertedArgObjects[i] = JSValueToObject(ctx, arguments[i] , NULL );
+ }
+ else
+ {
+ convertedArg[i] = JSValueMakeUndefined(ctx);
+ convertedArgObjects[i] = NULL;
}
}
+ //Check the first argument
+ if(JSValueIsNull(ctx, convertedArg[0]) || JSValueIsUndefined(ctx, convertedArg[0]) || !JSValueIsObject(ctx, convertedArg[0]))
+ {
+ return Commons::JSTizenExceptionFactory::postException(ctx,exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The first argument is invalid (null, undefined or not an object)");
+ }
+
+ JSObjectRef onsuccess;
+ JSObjectRef onfail;
+
// The second argument is null or undefined or function object
- if( !JSValueIsNull(ctx, convertedArguments[1]) &&
- !JSValueIsUndefined(ctx, convertedArguments[1]) &&
- ( convertedArgumentObjects[1] == NULL || !JSObjectIsFunction(ctx, convertedArgumentObjects[1]) )
- )
- return Commons::JSTizenExceptionFactory::postException(ctx,exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The first argument must be function or null");
+ bool isFunctionOnSuccess = false;
+ if(JSValueIsNull(ctx, convertedArg[1]) || JSValueIsUndefined(ctx, convertedArg[1]))
+ {
+ isFunctionOnSuccess = false;
+ LOGD("%s - 2rd argument is OK (Either null or undefined) ", __func__);
+ }
+ else if (JSObjectIsFunction(ctx, convertedArgObjects[1]))
+ {
+ isFunctionOnSuccess = true;
+ onsuccess = convertedArgObjects[1];
+ LOGD("%s - 2rd argument is OK (function) ", __func__);
+ }
+ else
+ {
+ return Commons::JSTizenExceptionFactory::postException(ctx,exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The second argument must be a function");
+ }
// The third argument is null or undefined or function object
- if( !JSValueIsNull(ctx, convertedArguments[2]) &&
- !JSValueIsUndefined(ctx, convertedArguments[2]) &&
- ( convertedArgumentObjects[2] == NULL || !JSObjectIsFunction(ctx, convertedArgumentObjects[2]))
- )
- return Commons::JSTizenExceptionFactory::postException(ctx,exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The first argument must be function or null");
-
- // The first argument is option object
- JSObjectRef jsOptions = convertedArgumentObjects[0];
- if( jsOptions == NULL ){
- return Commons::JSTizenExceptionFactory::postException(ctx, exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The option arguments is not Object");
+ bool isFunctionOnFail = false;
+ if(JSValueIsNull(ctx, convertedArg[2]) || JSValueIsUndefined(ctx, convertedArg[2]))
+ {
+ isFunctionOnFail = false;
+ LOGD("%s - 3rd argument is OK (Either null or undefined) ", __func__);
+ }
+ else if (JSObjectIsFunction(ctx, convertedArgObjects[2]))
+ {
+ isFunctionOnFail = true;
+ onfail = convertedArgObjects[2];
+ LOGD("%s - 3rd argument is OK (function) ", __func__);
+ }
+ else
+ {
+ return Commons::JSTizenExceptionFactory::postException(ctx,exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The third argument must be a function");
}
// Initialize a CallbackData
CallbackData * userdata = NULL;
+ userdata = new CallbackData();
- JSObjectRef onsuccess = convertedArgumentObjects[1];
- JSObjectRef onfail = convertedArgumentObjects[2];
- if( onsuccess != NULL || onfail != NULL ){
- userdata = new CallbackData();
+ //set the success callback
+ if(isFunctionOnSuccess)
+ {
+ userdata->onSuccess = onsuccess;
+ JSValueProtect(ctx, onsuccess);
+ }
+ else
+ {
userdata->onSuccess = NULL;
+ }
+
+ //set the error callback
+ if(isFunctionOnFail)
+ {
+ userdata->onFail = onfail;
+ JSValueProtect(ctx, onfail);
+ }
+ else
+ {
userdata->onFail = NULL;
+ }
- if( onsuccess ){
- userdata->onSuccess = onsuccess;
- JSValueProtect(ctx, onsuccess);
- }
- if( onfail ){
- userdata->onFail = onfail;
- JSValueProtect(ctx, onfail);
- }
+ // The first argument is option object
+ JSObjectRef jsOptions = convertedArgObjects[0];
+ if( jsOptions == NULL ){
+ return Commons::JSTizenExceptionFactory::postException(ctx, exception, Commons::JSTizenException::TYPE_MISMATCH_ERROR, "The option arguments is not Object");
}
// Convert Object to vector
- std::vector<std::pair<std::string, std::string>> options = LBSUtil::convertObject(ctx, jsOptions);
+ std::vector<std::pair<std::string, std::string>> options = LBSUtil::convertObject(ctx, jsOptions);
// Call native setOption function
int ret = priv->setOption(options , _setOptionCb , userdata, NULL);
+ LOGD("ret : %d ", ret);
// Invalid options values
if( ret != 0 ){
+ JSObjectRef error = Commons::JSTizenExceptionFactory::makeErrorObject(JSLBS::getGlobalContext(), Commons::JSTizenException::INVALID_VALUES_ERROR , "invalid option value");
+ JSValueRef args[1] = {error};
+ if( userdata->onFail )
+ JSObjectCallAsFunction(JSLBS::getGlobalContext(), userdata->onFail , NULL, 1, args, NULL);
+
//remove callback values
if( userdata != NULL ){
if( userdata->onSuccess )
JSValueUnprotect(ctx, userdata->onFail);
delete userdata;
}
-
- JSObjectRef error = Commons::JSTizenExceptionFactory::makeErrorObject(JSLBS::getGlobalContext(), Commons::JSTizenException::INVALID_VALUES_ERROR , "invalid option value");
- JSValueRef args[1] = {error};
- JSObjectCallAsFunction(JSLBS::getGlobalContext(), onfail , NULL, 1, args, NULL);
}
return JSValueMakeUndefined(ctx);