2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
25 #include <dali/integration-api/debug.h>
28 #include <object/property-value-wrapper.h>
29 #include <actors/actor-wrapper.h>
30 #include <object/handle-wrapper.h>
31 #include <image/image-wrapper.h>
32 #include <render-tasks/render-task-wrapper.h>
33 #include <object/property-value-wrapper.h>
37 * Similar to DALI_LOG_ERROR except the PRETTY_FUNCTION
38 * is removed because it makes no sense for scripting errors.
40 #define DALI_LOG_SCRIPT_ERROR(format, args...) Dali::Integration::Log::LogMessage(Dali::Integration::Log::DebugError, format, ## args)
51 void Log(const v8::FunctionCallbackInfo< v8::Value >& args)
53 v8::HandleScope handleScope( args.GetIsolate());
56 for (int i = 0; i < args.Length(); i++)
66 v8::String::Utf8Value utf8_value( args[i] );
67 std::cout << *utf8_value << "\n";
71 void LogError(const v8::FunctionCallbackInfo< v8::Value >& args)
73 v8::HandleScope handleScope( args.GetIsolate());
76 for (int i = 0; i < args.Length(); i++)
86 v8::String::Utf8Value utf8_value( args[i] );
87 output += *utf8_value;
90 DALI_LOG_ERROR_NOFN( "JavaScript: %s",output.c_str() );
93 void GetFileContents(const std::string &fileName, std::string& contents)
95 std::ifstream t(fileName.c_str());
96 contents = std::string((std::istreambuf_iterator<char>(t)), std::istreambuf_iterator<char>());
99 void GetFileDirectory( const std::string& fileName, std::string& directory )
103 // get the position of the last slash
104 size_t pos = fileName.find_last_of("\\/");
106 // if it doesn't exist, return nothing
107 if( (std::string::npos == pos ) )
113 // check an edge case where the string ends in a forward slash "mydir/"
114 if( (pos+1) < fileName.length() )
116 directory = fileName.substr(0, pos+1);
122 void GetFileName( const std::string& fullPathName, std::string& fileName )
124 // look for last slash
125 size_t pos = fullPathName.find_last_of("\\/");
127 if( std::string::npos == pos )
129 fileName = fullPathName;
133 fileName = fullPathName.substr(pos,fileName.length());
137 void GetModuleName( const std::string& fileName, std::string& moduleName )
139 std::string fileNameNoPath;
140 GetFileName( fileName , fileNameNoPath );
141 size_t pos = fileNameNoPath.find_last_of(".");
142 if( std::string::npos == pos )
144 moduleName = fileNameNoPath;
148 moduleName = fileName.substr(0, pos );
152 bool IsPropertyMapIdentical(Property::Map map1, Property::Map map2)
156 // Compare number of properties
157 if ( map1.Count() != map2.Count() )
163 for ( unsigned int i = 0, count = map1.Count(); i < count; ++i )
165 // Compare the key first
166 if(map1.GetKey(i) != map2.GetKey(i))
172 Property::Value& value = map1.GetValue(i);
173 Property::Value& newValue = map2.GetValue(i);
175 // Compare the value type
176 if(value.GetType() != newValue.GetType())
183 switch( value.GetType() )
185 case Property::BOOLEAN:
187 dirty = ( value.Get<bool>() != newValue.Get<bool>() );
190 case Property::FLOAT:
192 dirty = ( value.Get<float>() != newValue.Get<float>() );
195 case Property::INTEGER:
197 dirty = ( value.Get<int>() != newValue.Get<int>() );
200 case Property::RECTANGLE:
202 dirty = ( value.Get< Rect<int> >() != newValue.Get< Rect<int> >() );
205 case Property::VECTOR2:
207 dirty = ( value.Get<Vector2>() != newValue.Get<Vector2>() );
210 case Property::VECTOR3:
212 dirty = ( value.Get<Vector3>() != newValue.Get<Vector3>() );
215 case Property::VECTOR4:
217 dirty = ( value.Get<Vector4>() != newValue.Get<Vector4>() );
220 case Property::MATRIX3:
222 dirty = ( value.Get<Matrix3>() != newValue.Get<Matrix3>() );
225 case Property::MATRIX:
227 dirty = ( value.Get<Matrix>() != newValue.Get<Matrix>() );
230 case Property::ROTATION:
232 dirty = ( value.Get<Quaternion>() != newValue.Get<Quaternion>() );
235 case Property::STRING:
237 dirty = ( value.Get<std::string>() != newValue.Get<std::string>() );
242 dirty = ( !IsPropertyMapIdentical( value.Get<Property::Map>(), newValue.Get<Property::Map>() ) );
255 // Different already, no need any further comparison
264 void ReportException( v8::Isolate* isolate, v8::TryCatch* tryCatch)
266 v8::HandleScope handleScope( isolate );
268 v8::String::Utf8Value exception(tryCatch->Exception());
269 v8::Handle<v8::Message> message = tryCatch->Message();
271 if (message.IsEmpty())
273 // V8 didn't provide any extra information about this error; just
274 // print the exception.
275 DALI_LOG_SCRIPT_ERROR("%s\n", *exception);
280 // Print (filename):(line number): (message).
281 v8::String::Utf8Value filename(message->GetScriptResourceName());
283 DALI_LOG_SCRIPT_ERROR("\n\n====== Error found in JavaScript: ========= \n");
286 int linenum = message->GetLineNumber();
287 DALI_LOG_SCRIPT_ERROR("File: %s\n", *filename, linenum, *exception);
289 DALI_LOG_SCRIPT_ERROR("Error: :%s\n", *exception );
290 DALI_LOG_SCRIPT_ERROR("Line: :%i\n", linenum );
292 // Print line of source code.
293 v8::String::Utf8Value sourceline(message->GetSourceLine());
295 DALI_LOG_SCRIPT_ERROR("Source: %s\n", *sourceline);
297 // Print wavy underline (GetUnderline is deprecated).
299 std::stringstream msg;
301 int start = message->GetStartColumn();
302 for (int i = 0; i < start; i++)
306 int end = message->GetEndColumn();
307 for (int i = start; i < end; i++)
312 DALI_LOG_SCRIPT_ERROR(" %s\n", msg.str().c_str());
314 v8::String::Utf8Value stack_trace(tryCatch->StackTrace());
315 if (stack_trace.length() > 0)
317 DALI_LOG_SCRIPT_ERROR("%s\n", *stack_trace);
319 DALI_LOG_SCRIPT_ERROR("\n=========================================== \n");
324 std::string GetJavaScriptFunctionName( const char* functionName )
326 // @todo if we are 100% decided on lower case, go through
327 // every api and manually change the function names to lower case first character
328 std::string name( functionName );
329 name[0]=tolower( functionName[0] );
333 void Version(const v8::FunctionCallbackInfo< v8::Value >& args)
335 v8::HandleScope handleScope( args.GetIsolate());
337 v8::Handle<v8::String> ver = v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion());
339 args.GetReturnValue().Set(ver);
343 std::string v8StringToStdString( const v8::Handle<v8::Value>& value )
345 v8::String::Utf8Value utf8(value);
346 return std::string(*utf8);
350 std::string PropertyNameToJavaScriptName(const std::string& hyphenatedName)
354 ret.reserve(hyphenatedName.size());
356 bool capitlizeNext = false ;
357 for(unsigned int i = 0; i < hyphenatedName.size(); ++i)
359 char c = hyphenatedName[i];
362 capitlizeNext = true;
368 ret.push_back(std::toupper(c));
369 capitlizeNext = false;
381 void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString )
383 v8::EscapableHandleScope scope( isolate);
384 std::string errorMsg = std::string(function) + std::string("(), ") + errorString;
386 // log out to DALI_LOG_ERROR first, so we know something has gone wrong
387 DALI_LOG_ERROR("%s \n", errorMsg.c_str() );
389 // throw a V8 exception, DALi will keep running but we will get a print out
390 // of where the error occured in the JavaScript source
391 isolate->ThrowException( v8::String::NewFromUtf8( isolate, errorMsg.c_str()) );
394 void ScriptWarning( const char* function, std::string warningString )
396 std::string warningMsg = std::string(function) + std::string("(), ") + warningString;
397 DALI_LOG_WARNING("%s \n", warningMsg.c_str() );
400 bool IsBooleanPrimitiveOrObject( const v8::Local<v8::Value>& value )
402 return ( value->IsBoolean() || value->IsBooleanObject());
405 bool GetBooleanValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
407 v8::EscapableHandleScope scope( isolate); // may not be required.
409 if( value->IsBoolean() )
411 return value->ToBoolean()->Value();
413 else if (value->IsBooleanObject() )
415 const v8::Local<v8::BooleanObject> object = v8::Local<v8::BooleanObject>::Cast(value);
416 return object->BooleanValue();
418 DALI_SCRIPT_EXCEPTION(isolate, "no bool found");
422 bool IsNumberPrimitiveOrObject( const v8::Local<v8::Value>& value )
424 return ( value->IsNumber() || value->IsNumberObject());
427 float GetNumberValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
429 v8::EscapableHandleScope scope( isolate); // may not be required.
431 if( value->IsNumber() )
433 return value->ToNumber()->Value();
435 else if (value->IsNumberObject() )
437 const v8::Local<v8::NumberObject> object = v8::Local<v8::NumberObject>::Cast(value);
438 return object->ValueOf();
441 DALI_SCRIPT_EXCEPTION(isolate, "no number found?");
445 bool IsStringPrimitiveOrObject( const v8::Local<v8::Value>& value )
447 return ( value->IsString() || value->IsStringObject());
450 std::string GetStringValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
452 v8::EscapableHandleScope scope( isolate); // may not be required.
454 if( value->IsString() )
456 return V8Utils::v8StringToStdString(value);
458 else if (value->IsStringObject() )
460 const v8::Local<v8::StringObject> object = v8::Local<v8::StringObject>::Cast(value);
461 return V8Utils::v8StringToStdString( object->ValueOf() );
464 DALI_SCRIPT_EXCEPTION(isolate, "no string found?");
469 Property::Value GetPropertyValueFromObject( bool& found, v8::Isolate* isolate, const v8::Local<v8::Value >& value )
471 v8::HandleScope handleScope( isolate);
473 Property::Value daliPropertyValue;// creates a property with Property::NONE
477 if( value->IsObject() )
479 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast( value );
481 if( BaseWrappedObject::IsWrappedTypeAPropertyValue( object ) )
484 PropertyValueWrapper* propertyWrapper = PropertyValueWrapper::Unwrap( isolate, object );
485 return propertyWrapper->GetValue();
487 else if( value->IsArray() )
490 return PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, object);//todo check for V8 array / map?
493 else if( value->IsBoolean() )
496 v8::Local<v8::Boolean> v = value->ToBoolean();
497 return Dali::Property::Value(v->Value());
499 else if( value->IsNumber() )
502 v8::Local<v8::Number> v = value->ToNumber();
503 return Dali::Property::Value(static_cast<float>(v->Value()));
505 else if( value->IsInt32() || value->IsUint32() )
508 v8::Local<v8::Int32> v = value->ToInt32();
509 return Dali::Property::Value(static_cast<int>(v->Value()));
511 else if( value->IsString() )
514 std::string valueString = V8Utils::v8StringToStdString( value );
515 return Dali::Property::Value(valueString);
518 return daliPropertyValue;
522 Property::Map GetPropertyMapFromObject( v8::Isolate* isolate, const v8::Local<v8::Object>& object)
524 v8::Local<v8::Array> properties = object->GetPropertyNames();
525 Property::Map propertyMap; // empty map
527 for( unsigned int i = 0; i < properties->Length(); ++i)
530 v8::Local<v8::Value> key = properties->Get( i );
531 std::string keyString = v8StringToStdString( key );
534 v8::Local<v8::Value> value = object->Get( key );
536 if( value->IsBoolean() )
538 v8::Local<v8::Boolean> v = value->ToBoolean();
539 propertyMap[ keyString ] = v->Value();
541 else if( value->IsNumber() )
543 v8::Local<v8::Number> v = value->ToNumber();
544 propertyMap[ keyString ] = static_cast<float>(v->Value());
546 else if( value->IsInt32() || value->IsUint32() )
548 v8::Local<v8::Int32> v = value->ToInt32();
549 propertyMap[ keyString ] = static_cast<int>(v->Value());
551 else if( value->IsString() )
553 std::string valueString = V8Utils::v8StringToStdString( value );
554 propertyMap[ keyString ] = valueString.c_str();
556 else if( value->IsArray() )
558 propertyMap[ keyString ] = PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, value);
560 else if( value->IsObject() )
562 Dali::Property::Map map = V8Utils::GetPropertyMapFromObject(isolate, value->ToObject());
565 propertyMap[ keyString ] = Dali::Property::Value( map );
573 Actor GetActorFromObject( v8::Isolate* isolate, bool& found, v8::Local<v8::Object>& object)
575 v8::HandleScope handleScope( isolate);
578 if( BaseWrappedObject::IsWrappedType ( isolate, object, BaseWrappedObject::ACTOR ))
580 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, object );
581 return Actor::DownCast( handleWrapper->mHandle );
587 int GetIntegerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
590 unsigned int length = args.Length();
591 if( index >= length )
595 if( args[ index ]->IsInt32() )
598 return args[ index ]->Int32Value();
606 float GetFloatParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
609 unsigned int length = args.Length();
610 if( index >= length )
614 if( args[ index ]->IsNumber() )
617 return args[ index ]->NumberValue();
625 std::string GetStringParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
628 unsigned int length = args.Length();
630 if( index >= length )
632 return std::string();
634 if( args[ index ]->IsString() )
637 return v8StringToStdString( args[ index ]);
641 return std::string();
645 bool GetBooleanParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
647 v8::HandleScope handleScope( isolate);
650 unsigned int length = args.Length();
651 if( index >= length )
655 if( args[ index ]->IsBoolean() )
658 v8::Local<v8::Boolean> v = args[ index ]->ToBoolean();
667 void* GetArrayBufferViewParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
670 unsigned int length = args.Length();
671 if( index < length && args[index]->IsArrayBufferView() )
674 v8::ArrayBufferView* bufferView = v8::ArrayBufferView::Cast(*(args[index]));
675 v8::Handle<v8::ArrayBuffer> buffer = bufferView->Buffer();
676 v8::ArrayBuffer::Contents contents = buffer->Externalize();
677 return contents.Data();
685 Handle GetHandleParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
687 v8::HandleScope handleScope( isolate);
690 unsigned int length = args.Length();
691 if( index >= length )
696 if( args[ index ]->IsObject() )
698 v8::Local<v8::Object> object = args[ index ]->ToObject();
699 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
700 void* ptr = field->Value();
704 HandleWrapper* wrapper = static_cast< HandleWrapper *>(ptr);
705 return wrapper->GetHandle();
711 Vector2 GetVector2Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
713 v8::HandleScope handleScope( isolate);
714 unsigned int length = args.Length();
720 if( args[ index ]->IsObject() )
722 Dali::Property::Value value;
723 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR2 );
724 if( value.GetType() == Dali::Property::VECTOR2)
731 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
737 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
743 Vector2 GetVector2ParameterFrom2Float( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
745 Vector2 ret(0.0f,0.0f);
747 unsigned int argCount( args.Length() );
749 if( index+2 >= argCount )
751 DALI_SCRIPT_EXCEPTION(isolate, "Missing parameter");
755 ret.x = V8Utils::GetFloatParameter( index, bFound, isolate, args, 0.0f );
756 found = found && bFound;
757 ret.y = V8Utils::GetFloatParameter( index+1, bFound, isolate, args, 0.0f );
758 found = found && bFound;
763 Vector3 GetVector3Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
765 v8::HandleScope handleScope( isolate);
766 unsigned int argCount( args.Length() );
769 if( index < argCount )
771 if( args[ index ]->IsObject() )
773 Dali::Property::Value value;
774 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR3 );
775 if( value.GetType() == Dali::Property::VECTOR3)
782 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
788 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
795 Vector4 GetVector4Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
797 v8::HandleScope handleScope( isolate);
798 unsigned int argCount( args.Length() );
802 if( index < argCount )
804 if( args[ index ]->IsObject() )
806 Dali::Property::Value value;
807 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR4 );
808 if( value.GetType() == Dali::Property::VECTOR4)
815 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
821 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
828 Rect<int> GetRectIntParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
830 v8::HandleScope handleScope( isolate);
833 int length = args.Length() - index;
835 // if it's an array read the 2 numbers into a vector2
838 if( args[ 0 + index ]->IsInt32() &&
839 args[ 1 + index ]->IsInt32() &&
840 args[ 2 + index ]->IsInt32() &&
841 args[ 3 + index ]->IsInt32() )
844 Rect<int> rect( args[ 0 + index ]->Int32Value(),
845 args[ 1 + index ]->Int32Value(),
846 args[ 2 + index ]->Int32Value(),
847 args[ 3 + index ]->Int32Value() );
851 // this will extract a Vector4, if it is a Vector4 or a Javascript array object
852 if( args[ index ]->IsObject() )
854 Dali::Property::Value value;
855 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::RECTANGLE );
856 if( value.GetType() == Dali::Property::RECTANGLE)
864 // @todo support vector4 as well?
869 Actor GetActorParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
871 BaseWrappedObject* wrapper = GetWrappedDaliObjectParameter( index, BaseWrappedObject::ACTOR, isolate, args);
872 ActorWrapper* actorWrapper = static_cast< ActorWrapper*>( wrapper );
876 return actorWrapper->GetActor();
884 Layer GetLayerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
886 Actor actor = GetActorParameter( index, found, isolate, args );
887 return Layer::DownCast( actor );
890 Image GetImageParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
892 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( index, BaseWrappedObject::IMAGE, isolate, args );
896 ImageWrapper* wrapper = static_cast< ImageWrapper *>(wrappedObject);
897 return wrapper->GetImage();
906 RenderTask GetRenderTaskParameter( unsigned int paramIndex, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
909 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::RENDER_TASK, isolate, args );
913 RenderTaskWrapper* wrapper = static_cast< RenderTaskWrapper *>(wrappedObject);
914 return wrapper->GetRenderTask();
918 return RenderTask(); // empty handle
922 BaseWrappedObject* GetWrappedDaliObjectParameter( unsigned int index, BaseWrappedObject::Type type, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
924 v8::HandleScope handleScope( isolate);
925 unsigned int length = args.Length();
927 if( index >= length )
932 if( !args[ index ]->IsObject() )
937 v8::Local<v8::Object> object = args[ index ]->ToObject();
939 if( BaseWrappedObject::IsWrappedType ( isolate, object, type ))
941 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
942 void* ptr = field->Value();
943 BaseWrappedObject* wrapper = static_cast< BaseWrappedObject *>(ptr);
950 Property::Value GetPropertyValueParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
952 v8::HandleScope handleScope( isolate);
954 Property::Value daliPropertyValue;// creates a property with Property::INVALID
957 unsigned int length = args.Length();
959 if( index >= length )
961 return daliPropertyValue;
963 v8::Local<v8::Value > value = args[ index ];
965 return GetPropertyValueFromObject( found, isolate, value);
968 Property::Map GetPropertyMapParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
970 v8::HandleScope handleScope( isolate);
972 Property::Map propertyMap; // empty map
975 unsigned int length = args.Length();
977 if( index >= length )
982 if( !args[ index ]->IsObject() )
988 // go through each key value pair
989 v8::Local<v8::Object> obj = args[ index ]->ToObject();
991 return GetPropertyMapFromObject( isolate, obj );
995 void CreatePropertyMap( v8::Isolate* isolate, const Property::Map& map, v8::Local<v8::Object>& object )
997 v8::HandleScope handleScope( isolate);
999 // we're converting a dali property map in to a JavaScript property map
1000 if( map.Count() == 0 )
1005 for( unsigned int index = 0; index < map.Count(); ++index )
1007 const std::string& key = map.GetKey( index );
1008 Property::Value& value = map.GetValue( index );
1009 v8::Local<v8::Value> v8Value;
1011 switch( value.GetType() )
1013 case Dali::Property::FLOAT:
1015 v8Value = v8::Number::New( isolate, value.Get<float>() );
1018 case Dali::Property::BOOLEAN:
1020 v8Value = v8::Boolean::New( isolate, value.Get<bool>());
1023 case Dali::Property::INTEGER:
1025 v8Value = v8::Integer::New( isolate, value.Get<int>());
1028 case Dali::Property::STRING:
1030 std::string string = value.Get< std::string >();
1031 v8Value = v8::String::NewFromUtf8( isolate, string.c_str());
1034 case Dali::Property::VECTOR2:
1037 Vector2 vec = value.Get<Vector2>();
1038 v8::Local<v8::Array> array= v8::Array::New( isolate, 2 );
1039 array->Set( 0 , v8::Number::New(isolate, vec.x));
1040 array->Set( 1 , v8::Number::New(isolate, vec.y));
1044 case Dali::Property::VECTOR3:
1046 // create a vector 3
1047 Vector3 vec = value.Get<Vector3>();
1048 v8::Local<v8::Array> array= v8::Array::New( isolate, 3 );
1049 array->Set( 0 , v8::Number::New(isolate, vec.x));
1050 array->Set( 1 , v8::Number::New(isolate, vec.y));
1051 array->Set( 2 , v8::Number::New(isolate, vec.z));
1055 case Dali::Property::VECTOR4:
1057 // create a vector 4
1058 Vector4 vec = value.Get<Vector4>();
1059 v8::Local<v8::Array> array= v8::Array::New( isolate, 4 );
1060 array->Set( 0 , v8::Number::New(isolate, vec.x));
1061 array->Set( 1 , v8::Number::New(isolate, vec.y));
1062 array->Set( 2 , v8::Number::New(isolate, vec.z));
1063 array->Set( 3 , v8::Number::New(isolate, vec.w));
1070 DALI_SCRIPT_EXCEPTION( isolate, "Primitive mismatch \n");
1074 object->Set( v8::String::NewFromUtf8( isolate, key.c_str() ), v8Value );
1078 void ReadFloatArguments( bool& foundAllArguments, float* data, unsigned int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
1080 foundAllArguments = true;
1081 unsigned int length = args.Length();
1083 if( length < dataSize )
1085 foundAllArguments = false;
1088 for( unsigned int i = 0; i< dataSize ;i++ )
1092 if( args[ i ]->IsNumber() )
1094 data[i] = args[i]->NumberValue();
1098 data[i] = defaultValue;
1099 foundAllArguments = false; // bad argument
1104 data[i] = defaultValue; // not enough arguments
1110 void ReadIntegerArguments( bool& foundAllArguments, int* data, int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
1112 foundAllArguments = true;
1113 int length = args.Length();
1114 if( length < dataSize )
1116 foundAllArguments = false;
1119 for( int i = 0; i< dataSize ;i++ )
1123 if( args[ i ]->IsInt32() )
1125 data[i] = args[i]->Int32Value();
1129 data[i] = defaultValue;
1130 foundAllArguments = false; // bad argument
1135 data[i] = defaultValue; // not enough arguments
1140 } // namespace V8Utils
1142 } // namespace V8Plugin