}
else
{
- std::string error="Invalid property Set for "+name + "\n";
- DALI_SCRIPT_EXCEPTION( isolate, error );
+ // Trying to set the value for a property that is not registered yet.
+ std::stringstream msg;
+ msg << "Trying to set the value of an unregistered property: ";
+ msg << name;
+ DALI_SCRIPT_WARNING( msg.str().c_str() );
+
+ // Register the custom property automatically.
+ handle.RegisterProperty( name, PropertyValueWrapper::ExtractPropertyValue( isolate, javaScriptValue), Property::READ_WRITE );
}
}
return daliPropertyValue;
}
+Dali::Property::Value PropertyValueWrapper::ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value)
+{
+ v8::HandleScope handleScope( isolate);
+
+ Dali::Property::Value daliPropertyValue;
+
+ // Check if it's a javascript Array
+ Dali::Property::Value array = VectorOrMatrixFromV8Array( isolate, v8Value );
+
+ if( V8Utils::IsBooleanPrimitiveOrObject( v8Value ) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetBooleanValue( isolate, v8Value));
+ }
+ else if( V8Utils::IsNumberPrimitiveOrObject( v8Value ) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetNumberValue( isolate, v8Value) );
+ }
+ else if( v8Value->IsInt32() )
+ {
+ daliPropertyValue = Dali::Property::Value( v8Value->Int32Value() ) ;
+ }
+ else if( V8Utils::IsStringPrimitiveOrObject( v8Value) )
+ {
+ daliPropertyValue = Dali::Property::Value( V8Utils::GetStringValue( isolate, v8Value) );
+ }
+ else if( array.GetType() == Dali::Property::VECTOR2
+ || array.GetType() == Dali::Property::VECTOR3
+ || array.GetType() == Dali::Property::VECTOR4 )
+ {
+ daliPropertyValue = array;
+ }
+ else if( array.GetType() == Dali::Property::MATRIX )
+ {
+ Dali::Matrix mat = array.Get<Dali::Matrix>();
+ daliPropertyValue = mat;
+ }
+ else if( array.GetType() == Dali::Property::MATRIX3 )
+ {
+ Dali::Matrix3 mat = array.Get<Dali::Matrix3>();
+ daliPropertyValue = mat;
+ }
+ else if( array.GetType() == Dali::Property::ARRAY )
+ {
+ daliPropertyValue = ArrayFromV8Array( isolate, v8Value );
+ }
+ else if( v8Value->IsObject() )
+ {
+ // Assume this is a property map
+ v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast(v8Value);
+ Dali::Property::Map propertyMap = V8Utils::GetPropertyMapFromObject(isolate, object);
+ daliPropertyValue = Dali::Property::Value( propertyMap );
+ }
+
+ return daliPropertyValue;
+}
+
void PropertyValueWrapper::NewRotation( const v8::FunctionCallbackInfo< v8::Value >& args)
{
v8::Isolate* isolate = args.GetIsolate();
static Dali::Property::Value ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value, Dali::Property::Type type);
/**
+ * Extract a property value from a javascript object
+ * @return property value
+ */
+ static Dali::Property::Value ExtractPropertyValue( v8::Isolate* isolate, v8::Local< v8::Value> v8Value);
+
+ /**
* @brief Extract a vector or a matrix from a JavaScript array
* @return property value ( vector or matrix)
*/
return ret;
}
-
-
void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString )
{
v8::EscapableHandleScope scope( isolate);
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<v8::Value>& value )
{
return ( value->IsBoolean() || value->IsBooleanObject());
v8::Local<v8::Int32> v = value->ToInt32();
return Dali::Property::Value(static_cast<int>(v->Value()));
}
+ else if( value->IsString() )
+ {
+ found = true;
+ std::string valueString = V8Utils::v8StringToStdString( value );
+ return Dali::Property::Value(valueString);
+ }
+
return daliPropertyValue;
}
};
#define DALI_SCRIPT_EXCEPTION( isolate, message ) V8Utils::ScriptError( __FUNCTION__ , isolate, message );
+#define DALI_SCRIPT_WARNING( message ) V8Utils::ScriptWarning( __FUNCTION__ , message );
namespace V8Utils
{
void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString );
/**
+ * Script warning
+ */
+void ScriptWarning( const char* function, std::string warningString );
+
+/**
* @return in the value is a boolean primitive or a boolean object
*/
bool IsBooleanPrimitiveOrObject( const v8::Local<v8::Value>& value );