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;
383 void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString )
385 v8::EscapableHandleScope scope( isolate);
386 std::string errorMsg = std::string(function) + std::string("(), ") + errorString;
388 // log out to DALI_LOG_ERROR first, so we know something has gone wrong
389 DALI_LOG_ERROR("%s \n", errorMsg.c_str() );
391 // throw a V8 exception, DALi will keep running but we will get a print out
392 // of where the error occured in the JavaScript source
393 isolate->ThrowException( v8::String::NewFromUtf8( isolate, errorMsg.c_str()) );
396 bool IsBooleanPrimitiveOrObject( const v8::Local<v8::Value>& value )
398 return ( value->IsBoolean() || value->IsBooleanObject());
401 bool GetBooleanValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
403 v8::EscapableHandleScope scope( isolate); // may not be required.
405 if( value->IsBoolean() )
407 return value->ToBoolean()->Value();
409 else if (value->IsBooleanObject() )
411 const v8::Local<v8::BooleanObject> object = v8::Local<v8::BooleanObject>::Cast(value);
412 return object->BooleanValue();
414 DALI_SCRIPT_EXCEPTION(isolate, "no bool found");
418 bool IsNumberPrimitiveOrObject( const v8::Local<v8::Value>& value )
420 return ( value->IsNumber() || value->IsNumberObject());
423 float GetNumberValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
425 v8::EscapableHandleScope scope( isolate); // may not be required.
427 if( value->IsNumber() )
429 return value->ToNumber()->Value();
431 else if (value->IsNumberObject() )
433 const v8::Local<v8::NumberObject> object = v8::Local<v8::NumberObject>::Cast(value);
434 return object->ValueOf();
437 DALI_SCRIPT_EXCEPTION(isolate, "no number found?");
441 bool IsStringPrimitiveOrObject( const v8::Local<v8::Value>& value )
443 return ( value->IsString() || value->IsStringObject());
446 std::string GetStringValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
448 v8::EscapableHandleScope scope( isolate); // may not be required.
450 if( value->IsString() )
452 return V8Utils::v8StringToStdString(value);
454 else if (value->IsStringObject() )
456 const v8::Local<v8::StringObject> object = v8::Local<v8::StringObject>::Cast(value);
457 return V8Utils::v8StringToStdString( object->ValueOf() );
460 DALI_SCRIPT_EXCEPTION(isolate, "no string found?");
465 Property::Value GetPropertyValueFromObject( bool& found, v8::Isolate* isolate, const v8::Local<v8::Value >& value )
467 v8::HandleScope handleScope( isolate);
469 Property::Value daliPropertyValue;// creates a property with Property::NONE
473 if( value->IsObject() )
475 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast( value );
477 if( BaseWrappedObject::IsWrappedTypeAPropertyValue( object ) )
480 PropertyValueWrapper* propertyWrapper = PropertyValueWrapper::Unwrap( isolate, object );
481 return propertyWrapper->GetValue();
483 else if( value->IsArray() )
486 return PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, object);//todo check for V8 array / map?
489 else if( value->IsBoolean() )
492 v8::Local<v8::Boolean> v = value->ToBoolean();
493 return Dali::Property::Value(v->Value());
495 else if( value->IsNumber() )
498 v8::Local<v8::Number> v = value->ToNumber();
499 return Dali::Property::Value(static_cast<float>(v->Value()));
501 else if( value->IsInt32() || value->IsUint32() )
504 v8::Local<v8::Int32> v = value->ToInt32();
505 return Dali::Property::Value(static_cast<int>(v->Value()));
507 return daliPropertyValue;
511 Property::Map GetPropertyMapFromObject( v8::Isolate* isolate, const v8::Local<v8::Object>& object)
513 v8::Local<v8::Array> properties = object->GetPropertyNames();
514 Property::Map propertyMap; // empty map
516 for( unsigned int i = 0; i < properties->Length(); ++i)
519 v8::Local<v8::Value> key = properties->Get( i );
520 std::string keyString = v8StringToStdString( key );
523 v8::Local<v8::Value> value = object->Get( key );
525 if( value->IsBoolean() )
527 v8::Local<v8::Boolean> v = value->ToBoolean();
528 propertyMap[ keyString ] = v->Value();
530 else if( value->IsNumber() )
532 v8::Local<v8::Number> v = value->ToNumber();
533 propertyMap[ keyString ] = static_cast<float>(v->Value());
535 else if( value->IsInt32() || value->IsUint32() )
537 v8::Local<v8::Int32> v = value->ToInt32();
538 propertyMap[ keyString ] = static_cast<int>(v->Value());
540 else if( value->IsString() )
542 std::string valueString = V8Utils::v8StringToStdString( value );
543 propertyMap[ keyString ] = valueString.c_str();
545 else if( value->IsArray() )
547 propertyMap[ keyString ] = PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, value);
549 else if( value->IsObject() )
551 Dali::Property::Map map = V8Utils::GetPropertyMapFromObject(isolate, value->ToObject());
554 propertyMap[ keyString ] = Dali::Property::Value( map );
562 Actor GetActorFromObject( v8::Isolate* isolate, bool& found, v8::Local<v8::Object>& object)
564 v8::HandleScope handleScope( isolate);
567 if( BaseWrappedObject::IsWrappedType ( isolate, object, BaseWrappedObject::ACTOR ))
569 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, object );
570 return Actor::DownCast( handleWrapper->mHandle );
576 int GetIntegerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
579 unsigned int length = args.Length();
580 if( index >= length )
584 if( args[ index ]->IsInt32() )
587 return args[ index ]->Int32Value();
595 float GetFloatParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
598 unsigned int length = args.Length();
599 if( index >= length )
603 if( args[ index ]->IsNumber() )
606 return args[ index ]->NumberValue();
614 std::string GetStringParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
617 unsigned int length = args.Length();
619 if( index >= length )
621 return std::string();
623 if( args[ index ]->IsString() )
626 return v8StringToStdString( args[ index ]);
630 return std::string();
634 bool GetBooleanParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
636 v8::HandleScope handleScope( isolate);
639 unsigned int length = args.Length();
640 if( index >= length )
644 if( args[ index ]->IsBoolean() )
647 v8::Local<v8::Boolean> v = args[ index ]->ToBoolean();
656 void* GetArrayBufferViewParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
659 unsigned int length = args.Length();
660 if( index < length && args[index]->IsArrayBufferView() )
663 v8::ArrayBufferView* bufferView = v8::ArrayBufferView::Cast(*(args[index]));
664 v8::Handle<v8::ArrayBuffer> buffer = bufferView->Buffer();
665 v8::ArrayBuffer::Contents contents = buffer->Externalize();
666 return contents.Data();
674 Handle GetHandleParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
676 v8::HandleScope handleScope( isolate);
679 unsigned int length = args.Length();
680 if( index >= length )
685 if( args[ index ]->IsObject() )
687 v8::Local<v8::Object> object = args[ index ]->ToObject();
688 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
689 void* ptr = field->Value();
693 HandleWrapper* wrapper = static_cast< HandleWrapper *>(ptr);
694 return wrapper->GetHandle();
700 Vector2 GetVector2Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
702 v8::HandleScope handleScope( isolate);
703 unsigned int length = args.Length();
709 if( args[ index ]->IsObject() )
711 Dali::Property::Value value;
712 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR2 );
713 if( value.GetType() == Dali::Property::VECTOR2)
720 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
726 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
732 Vector2 GetVector2ParameterFrom2Float( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
734 Vector2 ret(0.0f,0.0f);
736 unsigned int argCount( args.Length() );
738 if( index+2 >= argCount )
740 DALI_SCRIPT_EXCEPTION(isolate, "Missing parameter");
744 ret.x = V8Utils::GetFloatParameter( index, bFound, isolate, args, 0.0f );
745 found = found && bFound;
746 ret.y = V8Utils::GetFloatParameter( index+1, bFound, isolate, args, 0.0f );
747 found = found && bFound;
752 Vector3 GetVector3Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
754 v8::HandleScope handleScope( isolate);
755 unsigned int argCount( args.Length() );
758 if( index < argCount )
760 if( args[ index ]->IsObject() )
762 Dali::Property::Value value;
763 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR3 );
764 if( value.GetType() == Dali::Property::VECTOR3)
771 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
777 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
784 Vector4 GetVector4Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
786 v8::HandleScope handleScope( isolate);
787 unsigned int argCount( args.Length() );
791 if( index < argCount )
793 if( args[ index ]->IsObject() )
795 Dali::Property::Value value;
796 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR4 );
797 if( value.GetType() == Dali::Property::VECTOR4)
804 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
810 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
817 Rect<int> GetRectIntParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
819 v8::HandleScope handleScope( isolate);
822 int length = args.Length() - index;
824 // if it's an array read the 2 numbers into a vector2
827 if( args[ 0 + index ]->IsInt32() &&
828 args[ 1 + index ]->IsInt32() &&
829 args[ 2 + index ]->IsInt32() &&
830 args[ 3 + index ]->IsInt32() )
833 Rect<int> rect( args[ 0 + index ]->Int32Value(),
834 args[ 1 + index ]->Int32Value(),
835 args[ 2 + index ]->Int32Value(),
836 args[ 3 + index ]->Int32Value() );
840 // this will extract a Vector4, if it is a Vector4 or a Javascript array object
841 if( args[ index ]->IsObject() )
843 Dali::Property::Value value;
844 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::RECTANGLE );
845 if( value.GetType() == Dali::Property::RECTANGLE)
853 // @todo support vector4 as well?
858 Actor GetActorParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
860 BaseWrappedObject* wrapper = GetWrappedDaliObjectParameter( index, BaseWrappedObject::ACTOR, isolate, args);
861 ActorWrapper* actorWrapper = static_cast< ActorWrapper*>( wrapper );
865 return actorWrapper->GetActor();
873 Layer GetLayerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
875 Actor actor = GetActorParameter( index, found, isolate, args );
876 return Layer::DownCast( actor );
879 Image GetImageParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
881 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( index, BaseWrappedObject::IMAGE, isolate, args );
885 ImageWrapper* wrapper = static_cast< ImageWrapper *>(wrappedObject);
886 return wrapper->GetImage();
895 RenderTask GetRenderTaskParameter( unsigned int paramIndex, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
898 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::RENDER_TASK, isolate, args );
902 RenderTaskWrapper* wrapper = static_cast< RenderTaskWrapper *>(wrappedObject);
903 return wrapper->GetRenderTask();
907 return RenderTask(); // empty handle
911 BaseWrappedObject* GetWrappedDaliObjectParameter( unsigned int index, BaseWrappedObject::Type type, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
913 v8::HandleScope handleScope( isolate);
914 unsigned int length = args.Length();
916 if( index >= length )
921 if( !args[ index ]->IsObject() )
926 v8::Local<v8::Object> object = args[ index ]->ToObject();
928 if( BaseWrappedObject::IsWrappedType ( isolate, object, type ))
930 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
931 void* ptr = field->Value();
932 BaseWrappedObject* wrapper = static_cast< BaseWrappedObject *>(ptr);
939 Property::Value GetPropertyValueParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
941 v8::HandleScope handleScope( isolate);
943 Property::Value daliPropertyValue;// creates a property with Property::INVALID
946 unsigned int length = args.Length();
948 if( index >= length )
950 return daliPropertyValue;
952 v8::Local<v8::Value > value = args[ index ];
954 return GetPropertyValueFromObject( found, isolate, value);
957 Property::Map GetPropertyMapParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
959 v8::HandleScope handleScope( isolate);
961 Property::Map propertyMap; // empty map
964 unsigned int length = args.Length();
966 if( index >= length )
971 if( !args[ index ]->IsObject() )
977 // go through each key value pair
978 v8::Local<v8::Object> obj = args[ index ]->ToObject();
980 return GetPropertyMapFromObject( isolate, obj );
984 void CreatePropertyMap( v8::Isolate* isolate, const Property::Map& map, v8::Local<v8::Object>& object )
986 v8::HandleScope handleScope( isolate);
988 // we're converting a dali property map in to a JavaScript property map
989 if( map.Count() == 0 )
994 for( unsigned int index = 0; index < map.Count(); ++index )
996 const std::string& key = map.GetKey( index );
997 Property::Value& value = map.GetValue( index );
998 v8::Local<v8::Value> v8Value;
1000 switch( value.GetType() )
1002 case Dali::Property::FLOAT:
1004 v8Value = v8::Number::New( isolate, value.Get<float>() );
1007 case Dali::Property::BOOLEAN:
1009 v8Value = v8::Boolean::New( isolate, value.Get<bool>());
1012 case Dali::Property::INTEGER:
1014 v8Value = v8::Integer::New( isolate, value.Get<int>());
1017 case Dali::Property::STRING:
1019 std::string string = value.Get< std::string >();
1020 v8Value = v8::String::NewFromUtf8( isolate, string.c_str());
1023 case Dali::Property::VECTOR2:
1026 Vector2 vec = value.Get<Vector2>();
1027 v8::Local<v8::Array> array= v8::Array::New( isolate, 2 );
1028 array->Set( 0 , v8::Number::New(isolate, vec.x));
1029 array->Set( 1 , v8::Number::New(isolate, vec.y));
1033 case Dali::Property::VECTOR3:
1035 // create a vector 3
1036 Vector3 vec = value.Get<Vector3>();
1037 v8::Local<v8::Array> array= v8::Array::New( isolate, 3 );
1038 array->Set( 0 , v8::Number::New(isolate, vec.x));
1039 array->Set( 1 , v8::Number::New(isolate, vec.y));
1040 array->Set( 2 , v8::Number::New(isolate, vec.z));
1044 case Dali::Property::VECTOR4:
1046 // create a vector 4
1047 Vector4 vec = value.Get<Vector4>();
1048 v8::Local<v8::Array> array= v8::Array::New( isolate, 4 );
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));
1052 array->Set( 3 , v8::Number::New(isolate, vec.w));
1059 DALI_SCRIPT_EXCEPTION( isolate, "Primitive mismatch \n");
1063 object->Set( v8::String::NewFromUtf8( isolate, key.c_str() ), v8Value );
1067 void ReadFloatArguments( bool& foundAllArguments, float* data, unsigned int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
1069 foundAllArguments = true;
1070 unsigned int length = args.Length();
1072 if( length < dataSize )
1074 foundAllArguments = false;
1077 for( unsigned int i = 0; i< dataSize ;i++ )
1081 if( args[ i ]->IsNumber() )
1083 data[i] = args[i]->NumberValue();
1087 data[i] = defaultValue;
1088 foundAllArguments = false; // bad argument
1093 data[i] = defaultValue; // not enough arguments
1099 void ReadIntegerArguments( bool& foundAllArguments, int* data, int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
1101 foundAllArguments = true;
1102 int length = args.Length();
1103 if( length < dataSize )
1105 foundAllArguments = false;
1108 for( int i = 0; i< dataSize ;i++ )
1112 if( args[ i ]->IsInt32() )
1114 data[i] = args[i]->Int32Value();
1118 data[i] = defaultValue;
1119 foundAllArguments = false; // bad argument
1124 data[i] = defaultValue; // not enough arguments
1129 } // namespace V8Utils
1131 } // namespace V8Plugin