Changeset 121663 in webkit
- Timestamp:
- Jul 2, 2012 1:42:29 AM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r121661 r121663 1 2012-07-02 Vineet Chaudhary <rgf748@motorola.com> 2 3 [V8Binding] Merging v8NumberArray()/v8NumberArrayToVector() to v8Array()/toNativeArray() respectively. 4 https://bugs.webkit.org/show_bug.cgi?id=90338 5 6 Reviewed by Kentaro Hara. 7 8 We can remove v8NumberArray() and v8NumberArrayToVector() implementaion 9 merging them to current v8Array() and toNativeArray() traits. 10 11 Tests: TestObj.idl 12 Shouldn't cause any behavioural changes. 13 14 * bindings/scripts/CodeGeneratorV8.pm: Removed float[]/double[] specific binding code. 15 (IsRefPtrType): 16 (GetNativeType): 17 (JSValueToNative): 18 (NativeToJSValue): 19 * bindings/scripts/test/V8/V8TestObj.cpp: Rebased binding test. 20 (WebCore::TestObjV8Internal::floatArrayAttrGetter): 21 (WebCore::TestObjV8Internal::floatArrayAttrSetter): 22 (WebCore::TestObjV8Internal::doubleArrayAttrGetter): 23 (WebCore::TestObjV8Internal::doubleArrayAttrSetter): 24 * bindings/v8/V8Binding.h: Added templates for float and double. 25 (WebCore::v8Array): 26 (WebCore::toNativeArray): 27 1 28 2012-07-02 Konrad Piascik <kpiascik@rim.com> 2 29 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
r121615 r121663 3512 3512 return 0 if $type eq "unsigned long"; 3513 3513 return 0 if $type eq "unsigned short"; 3514 return 0 if $type eq "float[]";3515 return 0 if $type eq "double[]";3516 3514 3517 3515 return 1; … … 3574 3572 3575 3573 # FIXME: Support T[], T[]?, sequence<T> generically 3576 return "Vector<float>" if $type eq "float[]";3577 return "Vector<double>" if $type eq "double[]";3578 3574 return "RefPtr<DOMStringList>" if $type eq "DOMStringList"; 3579 3575 … … 3634 3630 # FIXME: Add proper support for T[], T[]? and sequence<T>. 3635 3631 return "v8ValueToWebCoreDOMStringList($value)" if $type eq "DOMString[]"; 3636 if ($type eq "float[]") {3637 AddToImplIncludes("wtf/Vector.h");3638 return "v8NumberArrayToVector<float>($value)";3639 }3640 if ($type eq "double[]") {3641 AddToImplIncludes("wtf/Vector.h");3642 return "v8NumberArrayToVector<double>($value)";3643 }3644 3632 3645 3633 if ($type eq "DOMString" or $type eq "DOMUserData") { … … 3821 3809 'boolean' => 1, 3822 3810 'double' => 1, 3823 'double[]' => 1,3824 3811 'float' => 1, 3825 'float[]' => 1,3826 3812 'int' => 1, 3827 3813 'long long' => 1, … … 3910 3896 return "$value.v8Value()" if $nativeType eq "ScriptValue"; 3911 3897 3912 return "v8NumberArray($value)" if $type eq "float[]";3913 return "v8NumberArray($value)" if $type eq "double[]";3914 3915 3898 if ($codeGenerator->IsStringType($type)) { 3916 3899 my $conv = $signature->extendedAttributes->{"TreatReturnedNullStringAs"}; -
trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp
r121421 r121663 61 61 #include <wtf/RefPtr.h> 62 62 #include <wtf/UnusedParam.h> 63 #include <wtf/Vector.h>64 63 65 64 #if ENABLE(Condition1) … … 880 879 INC_STATS("DOM.TestObj.floatArray._get"); 881 880 TestObj* imp = V8TestObj::toNative(info.Holder()); 882 return v8 NumberArray(imp->floatArray());881 return v8Array(imp->floatArray(), info.GetIsolate()); 883 882 } 884 883 … … 887 886 INC_STATS("DOM.TestObj.floatArray._set"); 888 887 TestObj* imp = V8TestObj::toNative(info.Holder()); 889 Vector<float> v = v8NumberArrayToVector<float>(value);888 Vector<float> v = toNativeArray<float>(value); 890 889 imp->setFloatArray(v); 891 890 return; … … 896 895 INC_STATS("DOM.TestObj.doubleArray._get"); 897 896 TestObj* imp = V8TestObj::toNative(info.Holder()); 898 return v8 NumberArray(imp->doubleArray());897 return v8Array(imp->doubleArray(), info.GetIsolate()); 899 898 } 900 899 … … 903 902 INC_STATS("DOM.TestObj.doubleArray._set"); 904 903 TestObj* imp = V8TestObj::toNative(info.Holder()); 905 Vector<double> v = v8NumberArrayToVector<double>(value);904 Vector<double> v = toNativeArray<double>(value); 906 905 imp->setDoubleArray(v); 907 906 return; -
trunk/Source/WebCore/bindings/v8/V8Binding.h
r121658 r121663 344 344 345 345 template <class T> 346 struct Traits {346 struct V8ValueTraits { 347 347 static inline v8::Handle<v8::Value> arrayV8Value(const T& value, v8::Isolate* isolate) 348 348 { … … 352 352 353 353 template<> 354 struct Traits<String> {354 struct V8ValueTraits<String> { 355 355 static inline v8::Handle<v8::Value> arrayV8Value(const String& value, v8::Isolate* isolate) 356 356 { … … 360 360 361 361 template<> 362 struct Traits<unsigned long> {362 struct V8ValueTraits<unsigned long> { 363 363 static inline v8::Handle<v8::Value> arrayV8Value(const unsigned long& value, v8::Isolate* isolate) 364 364 { 365 365 return v8UnsignedInteger(value, isolate); 366 } 367 }; 368 369 template<> 370 struct V8ValueTraits<float> { 371 static inline v8::Handle<v8::Value> arrayV8Value(const float& value, v8::Isolate*) 372 { 373 return v8::Number::New(value); 374 } 375 }; 376 377 template<> 378 struct V8ValueTraits<double> { 379 static inline v8::Handle<v8::Value> arrayV8Value(const double& value, v8::Isolate*) 380 { 381 return v8::Number::New(value); 366 382 } 367 383 }; … … 373 389 int index = 0; 374 390 typename Vector<T>::const_iterator end = iterator.end(); 375 typedef Traits<T> TraitsType;391 typedef V8ValueTraits<T> TraitsType; 376 392 for (typename Vector<T>::const_iterator iter = iterator.begin(); iter != end; ++iter) 377 393 result->Set(v8Integer(index++, isolate), TraitsType::arrayV8Value(*iter, isolate)); … … 381 397 v8::Handle<v8::Value> v8Array(PassRefPtr<DOMStringList>, v8::Isolate*); 382 398 399 template<class T> struct NativeValueTraits; 400 401 template<> 402 struct NativeValueTraits<String> { 403 static inline String arrayNativeValue(const v8::Local<v8::Array>& array, size_t i) 404 { 405 return v8ValueToWebCoreString(array->Get(i)); 406 } 407 }; 408 409 template<> 410 struct NativeValueTraits<float> { 411 static inline float arrayNativeValue(const v8::Local<v8::Array>& array, size_t i) 412 { 413 return static_cast<float>(array->Get(v8Integer(i))->NumberValue()); 414 } 415 }; 416 417 template<> 418 struct NativeValueTraits<double> { 419 static inline double arrayNativeValue(const v8::Local<v8::Array>& array, size_t i) 420 { 421 return static_cast<double>(array->Get(v8Integer(i))->NumberValue()); 422 } 423 }; 424 383 425 template <class T> 384 426 Vector<T> toNativeArray(v8::Handle<v8::Value> value) … … 388 430 389 431 Vector<T> result; 432 typedef NativeValueTraits<T> TraitsType; 390 433 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value)); 391 434 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(v8Value); 392 435 size_t length = array->Length(); 393 394 436 for (size_t i = 0; i < length; ++i) { 395 result.append( v8ValueToWebCoreString(array->Get(i)));437 result.append(TraitsType::arrayNativeValue(array, i)); 396 438 } 397 439 return result; … … 521 563 { 522 564 return str.isNull() ? v8::Handle<v8::Value>(v8Boolean(false)) : v8::Handle<v8::Value>(v8String(str, isolate)); 523 }524 525 template <class T> v8::Handle<v8::Value> v8NumberArray(const Vector<T>& values)526 {527 size_t size = values.size();528 v8::Local<v8::Array> result = v8::Array::New(size);529 for (size_t i = 0; i < size; ++i)530 result->Set(i, v8::Number::New(values[i]));531 return result;532 565 } 533 566 … … 560 593 561 594 String int32ToWebCoreString(int value); 562 563 template <class T> Vector<T> v8NumberArrayToVector(v8::Handle<v8::Value> value)564 {565 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value));566 if (!v8Value->IsArray())567 return Vector<T>();568 569 Vector<T> result;570 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);571 size_t length = v8Array->Length();572 for (size_t i = 0; i < length; ++i) {573 v8::Local<v8::Value> indexedValue = v8Array->Get(v8Integer(i));574 result.append(static_cast<T>(indexedValue->NumberValue()));575 }576 return result;577 }578 595 579 596 PassRefPtr<DOMStringList> v8ValueToWebCoreDOMStringList(v8::Handle<v8::Value>);
Note: See TracChangeset
for help on using the changeset viewer.