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 void ReportException( v8::Isolate* isolate, v8::TryCatch* tryCatch)
154 v8::HandleScope handleScope( isolate );
156 v8::String::Utf8Value exception(tryCatch->Exception());
157 v8::Handle<v8::Message> message = tryCatch->Message();
159 if (message.IsEmpty())
161 // V8 didn't provide any extra information about this error; just
162 // print the exception.
163 DALI_LOG_SCRIPT_ERROR("%s\n", *exception);
168 // Print (filename):(line number): (message).
169 v8::String::Utf8Value filename(message->GetScriptResourceName());
171 DALI_LOG_SCRIPT_ERROR("\n\n====== Error found in JavaScript: ========= \n");
174 int linenum = message->GetLineNumber();
175 DALI_LOG_SCRIPT_ERROR("File: %s\n", *filename, linenum, *exception);
177 DALI_LOG_SCRIPT_ERROR("Error: :%s\n", *exception );
178 DALI_LOG_SCRIPT_ERROR("Line: :%i\n", linenum );
180 // Print line of source code.
181 v8::String::Utf8Value sourceline(message->GetSourceLine());
183 DALI_LOG_SCRIPT_ERROR("Source: %s\n", *sourceline);
185 // Print wavy underline (GetUnderline is deprecated).
187 std::stringstream msg;
189 int start = message->GetStartColumn();
190 for (int i = 0; i < start; i++)
194 int end = message->GetEndColumn();
195 for (int i = start; i < end; i++)
200 DALI_LOG_SCRIPT_ERROR(" %s\n", msg.str().c_str());
202 v8::String::Utf8Value stack_trace(tryCatch->StackTrace());
203 if (stack_trace.length() > 0)
205 DALI_LOG_SCRIPT_ERROR("%s\n", *stack_trace);
207 DALI_LOG_SCRIPT_ERROR("\n=========================================== \n");
212 std::string GetJavaScriptFunctionName( const char* functionName )
214 // @todo if we are 100% decided on lower case, go through
215 // every api and manually change the function names to lower case first character
216 std::string name( functionName );
217 name[0]=tolower( functionName[0] );
221 void Version(const v8::FunctionCallbackInfo< v8::Value >& args)
223 v8::HandleScope handleScope( args.GetIsolate());
225 v8::Handle<v8::String> ver = v8::String::NewFromUtf8(args.GetIsolate(), v8::V8::GetVersion());
227 args.GetReturnValue().Set(ver);
231 std::string v8StringToStdString( const v8::Handle<v8::Value>& value )
233 v8::String::Utf8Value utf8(value);
234 return std::string(*utf8);
238 std::string PropertyNameToJavaScriptName(const std::string& hyphenatedName)
242 ret.reserve(hyphenatedName.size());
244 bool capitlizeNext = false ;
245 for(unsigned int i = 0; i < hyphenatedName.size(); ++i)
247 char c = hyphenatedName[i];
250 capitlizeNext = true;
256 ret.push_back(std::toupper(c));
257 capitlizeNext = false;
271 std::string JavaScriptNameToPropertyName(const std::string& camelCase)
276 for(unsigned int i = 0; i < camelCase.size(); ++i)
278 if(std::isupper(camelCase[i]))
286 ret.reserve(camelCase.size() + countUpper);
288 for(unsigned int i = 0; i < camelCase.size(); ++i)
290 char c = camelCase[i];
296 ret.push_back(std::tolower(c));
307 void ScriptError( const char* function, v8::Isolate* isolate, std::string errorString )
309 v8::EscapableHandleScope scope( isolate);
310 std::string errorMsg = std::string(function) + std::string("(), ") + errorString;
312 // log out to DALI_LOG_ERROR first, so we know something has gone wrong
313 DALI_LOG_ERROR("%s \n", errorMsg.c_str() );
315 // throw a V8 exception, DALi will keep running but we will get a print out
316 // of where the error occured in the JavaScript source
317 isolate->ThrowException( v8::String::NewFromUtf8( isolate, errorMsg.c_str()) );
320 bool IsBooleanPrimitiveOrObject( const v8::Local<v8::Value>& value )
322 return ( value->IsBoolean() || value->IsBooleanObject());
325 bool GetBooleanValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
327 v8::EscapableHandleScope scope( isolate); // may not be required.
329 if( value->IsBoolean() )
331 return value->ToBoolean()->Value();
333 else if (value->IsBooleanObject() )
335 const v8::Local<v8::BooleanObject> object = v8::Local<v8::BooleanObject>::Cast(value);
336 return object->BooleanValue();
338 DALI_SCRIPT_EXCEPTION(isolate, "no bool found");
342 bool IsNumberPrimitiveOrObject( const v8::Local<v8::Value>& value )
344 return ( value->IsNumber() || value->IsNumberObject());
347 float GetNumberValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
349 v8::EscapableHandleScope scope( isolate); // may not be required.
351 if( value->IsNumber() )
353 return value->ToNumber()->Value();
355 else if (value->IsNumberObject() )
357 const v8::Local<v8::NumberObject> object = v8::Local<v8::NumberObject>::Cast(value);
358 return object->ValueOf();
361 DALI_SCRIPT_EXCEPTION(isolate, "no number found?");
365 bool IsStringPrimitiveOrObject( const v8::Local<v8::Value>& value )
367 return ( value->IsString() || value->IsStringObject());
370 std::string GetStringValue( v8::Isolate* isolate, const v8::Local<v8::Value>& value )
372 v8::EscapableHandleScope scope( isolate); // may not be required.
374 if( value->IsString() )
376 return V8Utils::v8StringToStdString(value);
378 else if (value->IsStringObject() )
380 const v8::Local<v8::StringObject> object = v8::Local<v8::StringObject>::Cast(value);
381 return V8Utils::v8StringToStdString( object->ValueOf() );
384 DALI_SCRIPT_EXCEPTION(isolate, "no string found?");
389 Property::Value GetPropertyValueFromObject( bool& found, v8::Isolate* isolate, const v8::Local<v8::Value >& value )
391 v8::HandleScope handleScope( isolate);
393 Property::Value daliPropertyValue;// creates a property with Property::NONE
397 if( value->IsObject() )
399 v8::Local<v8::Object> object = v8::Handle<v8::Object>::Cast( value );
401 if( BaseWrappedObject::IsWrappedTypeAPropertyValue( object ) )
404 PropertyValueWrapper* propertyWrapper = PropertyValueWrapper::Unwrap( isolate, object );
405 return propertyWrapper->GetValue();
407 else if( value->IsArray() )
410 return PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, object);//todo check for V8 array / map?
413 else if( value->IsBoolean() )
416 v8::Local<v8::Boolean> v = value->ToBoolean();
417 return Dali::Property::Value(v->Value());
419 else if( value->IsNumber() )
422 v8::Local<v8::Number> v = value->ToNumber();
423 return Dali::Property::Value(static_cast<float>(v->Value()));
425 else if( value->IsInt32() || value->IsUint32() )
428 v8::Local<v8::Int32> v = value->ToInt32();
429 return Dali::Property::Value(static_cast<int>(v->Value()));
431 return daliPropertyValue;
435 Property::Map GetPropertyMapFromObject( v8::Isolate* isolate, const v8::Local<v8::Object>& object)
437 v8::Local<v8::Array> properties = object->GetPropertyNames();
438 Property::Map propertyMap; // empty map
440 for( unsigned int i = 0; i < properties->Length(); ++i)
443 v8::Local<v8::Value> key = properties->Get( i );
444 std::string keyString = v8StringToStdString( key );
447 v8::Local<v8::Value> value = object->Get( key );
449 if( value->IsBoolean() )
451 v8::Local<v8::Boolean> v = value->ToBoolean();
452 propertyMap[ keyString ] = v->Value();
454 else if( value->IsNumber() )
456 v8::Local<v8::Number> v = value->ToNumber();
457 propertyMap[ keyString ] = static_cast<float>(v->Value());
459 else if( value->IsInt32() || value->IsUint32() )
461 v8::Local<v8::Int32> v = value->ToInt32();
462 propertyMap[ keyString ] = static_cast<int>(v->Value());
464 else if( value->IsString() )
466 std::string valueString = V8Utils::v8StringToStdString( value );
467 propertyMap[ keyString ] = valueString.c_str();
469 else if( value->IsArray() )
471 propertyMap[ keyString ] = PropertyValueWrapper::VectorOrMatrixFromV8Array( isolate, value);
478 Actor GetActorFromObject( v8::Isolate* isolate, bool& found, v8::Local<v8::Object>& object)
480 v8::HandleScope handleScope( isolate);
483 if( BaseWrappedObject::IsWrappedType ( isolate, object, BaseWrappedObject::ACTOR ))
485 HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, object );
486 return Actor::DownCast( handleWrapper->mHandle );
492 int GetIntegerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
495 unsigned int length = args.Length();
496 if( index >= length )
500 if( args[ index ]->IsInt32() )
503 return args[ index ]->Int32Value();
511 float GetFloatParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
514 unsigned int length = args.Length();
515 if( index >= length )
519 if( args[ index ]->IsNumber() )
522 return args[ index ]->NumberValue();
530 std::string GetStringParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
533 unsigned int length = args.Length();
535 if( index >= length )
537 return std::string();
539 if( args[ index ]->IsString() )
542 return v8StringToStdString( args[ index ]);
546 return std::string();
550 bool GetBooleanParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
552 v8::HandleScope handleScope( isolate);
555 unsigned int length = args.Length();
556 if( index >= length )
560 if( args[ index ]->IsBoolean() )
563 v8::Local<v8::Boolean> v = args[ index ]->ToBoolean();
572 void* GetArrayBufferViewParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
575 unsigned int length = args.Length();
576 if( index < length && args[index]->IsArrayBufferView() )
579 v8::ArrayBufferView* bufferView = v8::ArrayBufferView::Cast(*(args[index]));
580 v8::Handle<v8::ArrayBuffer> buffer = bufferView->Buffer();
581 v8::ArrayBuffer::Contents contents = buffer->Externalize();
582 return contents.Data();
590 Handle GetHandleParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
592 v8::HandleScope handleScope( isolate);
595 unsigned int length = args.Length();
596 if( index >= length )
601 if( args[ index ]->IsObject() )
603 v8::Local<v8::Object> object = args[ index ]->ToObject();
604 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
605 void* ptr = field->Value();
609 HandleWrapper* wrapper = static_cast< HandleWrapper *>(ptr);
610 return wrapper->GetHandle();
616 Vector2 GetVector2Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
618 v8::HandleScope handleScope( isolate);
619 unsigned int length = args.Length();
625 if( args[ index ]->IsObject() )
627 Dali::Property::Value value;
628 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR2 );
629 if( value.GetType() == Dali::Property::VECTOR2)
636 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
642 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector2 parameter");
648 Vector2 GetVector2ParameterFrom2Float( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
650 Vector2 ret(0.0f,0.0f);
652 unsigned int argCount( args.Length() );
654 if( index+2 >= argCount )
656 DALI_SCRIPT_EXCEPTION(isolate, "Missing parameter");
660 ret.x = V8Utils::GetFloatParameter( index, bFound, isolate, args, 0.0f );
661 found = found && bFound;
662 ret.y = V8Utils::GetFloatParameter( index+1, bFound, isolate, args, 0.0f );
663 found = found && bFound;
668 Vector3 GetVector3Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
670 v8::HandleScope handleScope( isolate);
671 unsigned int argCount( args.Length() );
674 if( index < argCount )
676 if( args[ index ]->IsObject() )
678 Dali::Property::Value value;
679 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR3 );
680 if( value.GetType() == Dali::Property::VECTOR3)
687 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
693 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector3 parameter");
700 Vector4 GetVector4Parameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args)
702 v8::HandleScope handleScope( isolate);
703 unsigned int argCount( args.Length() );
707 if( index < argCount )
709 if( args[ index ]->IsObject() )
711 Dali::Property::Value value;
712 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::VECTOR4 );
713 if( value.GetType() == Dali::Property::VECTOR4)
720 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
726 DALI_SCRIPT_EXCEPTION(isolate, "Missing Vector4 parameter");
733 Rect<int> GetRectIntParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
735 v8::HandleScope handleScope( isolate);
738 int length = args.Length() - index;
740 // if it's an array read the 2 numbers into a vector2
743 if( args[ 0 + index ]->IsInt32() &&
744 args[ 1 + index ]->IsInt32() &&
745 args[ 2 + index ]->IsInt32() &&
746 args[ 3 + index ]->IsInt32() )
749 Rect<int> rect( args[ 0 + index ]->Int32Value(),
750 args[ 1 + index ]->Int32Value(),
751 args[ 2 + index ]->Int32Value(),
752 args[ 3 + index ]->Int32Value() );
756 // this will extract a Vector4, if it is a Vector4 or a Javascript array object
757 if( args[ index ]->IsObject() )
759 Dali::Property::Value value;
760 value = PropertyValueWrapper::ExtractPropertyValue( isolate, args[index], Dali::Property::RECTANGLE );
761 if( value.GetType() == Dali::Property::RECTANGLE)
769 // @todo support vector4 as well?
774 Actor GetActorParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
776 BaseWrappedObject* wrapper = GetWrappedDaliObjectParameter( index, BaseWrappedObject::ACTOR, isolate, args);
777 ActorWrapper* actorWrapper = static_cast< ActorWrapper*>( wrapper );
781 return actorWrapper->GetActor();
789 Layer GetLayerParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
791 Actor actor = GetActorParameter( index, found, isolate, args );
792 return Layer::DownCast( actor );
795 Image GetImageParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
797 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( index, BaseWrappedObject::IMAGE, isolate, args );
801 ImageWrapper* wrapper = static_cast< ImageWrapper *>(wrappedObject);
802 return wrapper->GetImage();
811 RenderTask GetRenderTaskParameter( unsigned int paramIndex, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
814 BaseWrappedObject* wrappedObject = V8Utils::GetWrappedDaliObjectParameter( paramIndex, BaseWrappedObject::RENDER_TASK, isolate, args );
818 RenderTaskWrapper* wrapper = static_cast< RenderTaskWrapper *>(wrappedObject);
819 return wrapper->GetRenderTask();
823 return RenderTask(); // empty handle
827 BaseWrappedObject* GetWrappedDaliObjectParameter( unsigned int index, BaseWrappedObject::Type type, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
829 v8::HandleScope handleScope( isolate);
830 unsigned int length = args.Length();
832 if( index >= length )
837 if( !args[ index ]->IsObject() )
842 v8::Local<v8::Object> object = args[ index ]->ToObject();
844 if( BaseWrappedObject::IsWrappedType ( isolate, object, type ))
846 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField(0) );
847 void* ptr = field->Value();
848 BaseWrappedObject* wrapper = static_cast< BaseWrappedObject *>(ptr);
855 Property::Value GetPropertyValueParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
857 v8::HandleScope handleScope( isolate);
859 Property::Value daliPropertyValue;// creates a property with Property::INVALID
862 unsigned int length = args.Length();
864 if( index >= length )
866 return daliPropertyValue;
868 v8::Local<v8::Value > value = args[ index ];
870 return GetPropertyValueFromObject( found, isolate, value);
873 Property::Map GetPropertyMapParameter( unsigned int index, bool& found, v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
875 v8::HandleScope handleScope( isolate);
877 Property::Map propertyMap; // empty map
880 unsigned int length = args.Length();
882 if( index >= length )
887 if( !args[ index ]->IsObject() )
893 // go through each key value pair
894 v8::Local<v8::Object> obj = args[ index ]->ToObject();
896 return GetPropertyMapFromObject( isolate, obj );
900 void CreatePropertyMap( v8::Isolate* isolate, const Property::Map& map, v8::Local<v8::Object>& object )
902 v8::HandleScope handleScope( isolate);
904 // we're converting a dali property map in to a JavaScript property map
905 if( map.Count() == 0 )
910 for( unsigned int index = 0; index < map.Count() - 1; ++index )
912 const std::string& key = map.GetKey( index );
913 Property::Value& value = map.GetValue( index );
914 v8::Local<v8::Value> v8Value;
916 switch( value.GetType() )
918 case Dali::Property::FLOAT:
920 v8Value = v8::Number::New( isolate, value.Get<float>() );
923 case Dali::Property::BOOLEAN:
925 v8Value = v8::Boolean::New( isolate, value.Get<bool>());
928 case Dali::Property::INTEGER:
930 v8Value = v8::Integer::New( isolate, value.Get<int>());
933 case Dali::Property::STRING:
935 std::string string = value.Get< std::string >();
936 v8Value = v8::String::NewFromUtf8( isolate, string.c_str());
939 case Dali::Property::VECTOR2:
942 Vector2 vec = value.Get<Vector2>();
943 v8::Local<v8::Array> array= v8::Array::New( isolate, 2 );
944 array->Set( 0 , v8::Number::New(isolate, vec.x));
945 array->Set( 1 , v8::Number::New(isolate, vec.y));
949 case Dali::Property::VECTOR3:
952 Vector3 vec = value.Get<Vector3>();
953 v8::Local<v8::Array> array= v8::Array::New( isolate, 3 );
954 array->Set( 0 , v8::Number::New(isolate, vec.x));
955 array->Set( 1 , v8::Number::New(isolate, vec.y));
956 array->Set( 2 , v8::Number::New(isolate, vec.z));
960 case Dali::Property::VECTOR4:
963 Vector4 vec = value.Get<Vector4>();
964 v8::Local<v8::Array> array= v8::Array::New( isolate, 4 );
965 array->Set( 0 , v8::Number::New(isolate, vec.x));
966 array->Set( 1 , v8::Number::New(isolate, vec.y));
967 array->Set( 2 , v8::Number::New(isolate, vec.z));
968 array->Set( 3 , v8::Number::New(isolate, vec.w));
975 DALI_SCRIPT_EXCEPTION( isolate, "Primitive mismatch \n");
979 object->Set( v8::String::NewFromUtf8( isolate, key.c_str() ), v8Value );
983 void ReadFloatArguments( bool& foundAllArguments, float* data, unsigned int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, float defaultValue )
985 foundAllArguments = true;
986 unsigned int length = args.Length();
988 if( length < dataSize )
990 foundAllArguments = false;
993 for( unsigned int i = 0; i< dataSize ;i++ )
997 if( args[ i ]->IsNumber() )
999 data[i] = args[i]->NumberValue();
1003 data[i] = defaultValue;
1004 foundAllArguments = false; // bad argument
1009 data[i] = defaultValue; // not enough arguments
1015 void ReadIntegerArguments( bool& foundAllArguments, int* data, int dataSize, const v8::FunctionCallbackInfo< v8::Value >& args, int defaultValue )
1017 foundAllArguments = true;
1018 int length = args.Length();
1019 if( length < dataSize )
1021 foundAllArguments = false;
1024 for( int i = 0; i< dataSize ;i++ )
1028 if( args[ i ]->IsInt32() )
1030 data[i] = args[i]->Int32Value();
1034 data[i] = defaultValue;
1035 foundAllArguments = false; // bad argument
1040 data[i] = defaultValue; // not enough arguments
1045 } // namespace V8Utils
1047 } // namespace V8Plugin