X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=plugins%2Fdali-script-v8%2Fsrc%2Futils%2Fv8-utils.cpp;h=ce656c0a39bfdb5de8629bc17c79a8094494163e;hp=f843d1d8e8910e67a71ef7c45e68dbecdef932bf;hb=b0d0b451bd3414c8f502810f45fcacba2882d717;hpb=ed5adaff4b716c46bb0166a37ce7ffd86a879b02 diff --git a/plugins/dali-script-v8/src/utils/v8-utils.cpp b/plugins/dali-script-v8/src/utils/v8-utils.cpp index f843d1d..ce656c0 100644 --- a/plugins/dali-script-v8/src/utils/v8-utils.cpp +++ b/plugins/dali-script-v8/src/utils/v8-utils.cpp @@ -87,7 +87,7 @@ void LogError(const v8::FunctionCallbackInfo< v8::Value >& args) output += *utf8_value; output +="\n"; } - DALI_LOG_ERROR_NOFN( "JavaScript: %s",output.c_str() ); + DALI_LOG_ERROR_NOFN( "JavaScript: %s\n",output.c_str() ); } void GetFileContents(const std::string &fileName, std::string& contents) @@ -149,6 +149,118 @@ void GetModuleName( const std::string& fileName, std::string& moduleName ) } } +bool IsPropertyMapIdentical(Property::Map map1, Property::Map map2) +{ + bool dirty = false; + + // Compare number of properties + if ( map1.Count() != map2.Count() ) + { + dirty = true; + } + else + { + for ( unsigned int i = 0, count = map1.Count(); i < count; ++i ) + { + // Compare the key first + if(map1.GetKey(i) != map2.GetKey(i)) + { + dirty = true; + } + else + { + Property::Value& value = map1.GetValue(i); + Property::Value& newValue = map2.GetValue(i); + + // Compare the value type + if(value.GetType() != newValue.GetType()) + { + dirty = true; + } + else + { + // Compare the value + switch( value.GetType() ) + { + case Property::BOOLEAN: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::FLOAT: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::INTEGER: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::RECTANGLE: + { + dirty = ( value.Get< Rect >() != newValue.Get< Rect >() ); + break; + } + case Property::VECTOR2: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::VECTOR3: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::VECTOR4: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::MATRIX3: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::MATRIX: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::ROTATION: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::STRING: + { + dirty = ( value.Get() != newValue.Get() ); + break; + } + case Property::MAP: + { + dirty = ( !IsPropertyMapIdentical( value.Get(), newValue.Get() ) ); + break; + } + default: + { + break; + } + } + } + } + + if(dirty) + { + // Different already, no need any further comparison + break; + } + } + } + + return !dirty; +} + void ReportException( v8::Isolate* isolate, v8::TryCatch* tryCatch) { v8::HandleScope handleScope( isolate ); @@ -266,44 +378,6 @@ std::string PropertyNameToJavaScriptName(const std::string& hyphenatedName) return ret; } - - -std::string JavaScriptNameToPropertyName(const std::string& camelCase) -{ - std::string ret; - - int countUpper = 0; - for(unsigned int i = 0; i < camelCase.size(); ++i) - { - if(std::isupper(camelCase[i])) - { - countUpper++; - } - } - - if(countUpper) - { - ret.reserve(camelCase.size() + countUpper); - - for(unsigned int i = 0; i < camelCase.size(); ++i) - { - char c = camelCase[i]; - if(std::isupper(c)) - { - ret.push_back('-'); - } - - ret.push_back(std::tolower(c)); - } - } - else - { - return camelCase ; - } - - return ret; -} - void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString ) { v8::EscapableHandleScope scope( isolate); @@ -317,6 +391,12 @@ void ScriptError( const char* function, v8::Isolate* isolate, std::string errorS isolate->ThrowException( v8::String::NewFromUtf8( isolate, errorMsg.c_str()) ); } +void ScriptWarning( const char* function, std::string warningString ) +{ + std::string warningMsg = std::string(function) + std::string("(), ") + warningString; + DALI_LOG_WARNING("%s \n", warningMsg.c_str() ); +} + bool IsBooleanPrimitiveOrObject( const v8::Local& value ) { return ( value->IsBoolean() || value->IsBooleanObject()); @@ -428,6 +508,13 @@ Property::Value GetPropertyValueFromObject( bool& found, v8::Isolate* isolate, c v8::Local v = value->ToInt32(); return Dali::Property::Value(static_cast(v->Value())); } + else if( value->IsString() ) + { + found = true; + std::string valueString = V8Utils::v8StringToStdString( value ); + return Dali::Property::Value(valueString); + } + return daliPropertyValue; } @@ -470,6 +557,14 @@ Property::Map GetPropertyMapFromObject( v8::Isolate* isolate, const v8::LocalIsObject() ) + { + Dali::Property::Map map = V8Utils::GetPropertyMapFromObject(isolate, value->ToObject()); + if( !map.Empty() ) + { + propertyMap[ keyString ] = Dali::Property::Value( map ); + } + } } return propertyMap; @@ -907,7 +1002,7 @@ void CreatePropertyMap( v8::Isolate* isolate, const Property::Map& map, v8::Loca return; } - for( unsigned int index = 0; index < map.Count() - 1; ++index ) + for( unsigned int index = 0; index < map.Count(); ++index ) { const std::string& key = map.GetKey( index ); Property::Value& value = map.GetValue( index );