Changeset 121663 in webkit


Ignore:
Timestamp:
Jul 2, 2012 1:42:29 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

[V8Binding] Merging v8NumberArray()/v8NumberArrayToVector() to v8Array()/toNativeArray() respectively.
https://bugs.webkit.org/show_bug.cgi?id=90338

Patch by Vineet Chaudhary <Vineet> on 2012-07-02
Reviewed by Kentaro Hara.

We can remove v8NumberArray() and v8NumberArrayToVector() implementaion
merging them to current v8Array() and toNativeArray() traits.

Tests: TestObj.idl
Shouldn't cause any behavioural changes.

  • bindings/scripts/CodeGeneratorV8.pm: Removed float[]/double[] specific binding code.

(IsRefPtrType):
(GetNativeType):
(JSValueToNative):
(NativeToJSValue):

  • bindings/scripts/test/V8/V8TestObj.cpp: Rebased binding test.

(WebCore::TestObjV8Internal::floatArrayAttrGetter):
(WebCore::TestObjV8Internal::floatArrayAttrSetter):
(WebCore::TestObjV8Internal::doubleArrayAttrGetter):
(WebCore::TestObjV8Internal::doubleArrayAttrSetter):

  • bindings/v8/V8Binding.h: Added templates for float and double.

(WebCore::v8Array):
(WebCore::toNativeArray):

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r121661 r121663  
     12012-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
    1282012-07-02  Konrad Piascik  <kpiascik@rim.com>
    229
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm

    r121615 r121663  
    35123512    return 0 if $type eq "unsigned long";
    35133513    return 0 if $type eq "unsigned short";
    3514     return 0 if $type eq "float[]";
    3515     return 0 if $type eq "double[]";
    35163514
    35173515    return 1;
     
    35743572
    35753573    # FIXME: Support T[], T[]?, sequence<T> generically
    3576     return "Vector<float>" if $type eq "float[]";
    3577     return "Vector<double>" if $type eq "double[]";
    35783574    return "RefPtr<DOMStringList>" if $type eq "DOMStringList";
    35793575
     
    36343630    # FIXME: Add proper support for T[], T[]? and sequence<T>.
    36353631    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     }
    36443632
    36453633    if ($type eq "DOMString" or $type eq "DOMUserData") {
     
    38213809    'boolean' => 1,
    38223810    'double' => 1,
    3823     'double[]' => 1,
    38243811    'float' => 1,
    3825     'float[]' => 1,
    38263812    'int' => 1,
    38273813    'long long' => 1,
     
    39103896    return "$value.v8Value()" if $nativeType eq "ScriptValue";
    39113897
    3912     return "v8NumberArray($value)" if $type eq "float[]";
    3913     return "v8NumberArray($value)" if $type eq "double[]";
    3914 
    39153898    if ($codeGenerator->IsStringType($type)) {
    39163899        my $conv = $signature->extendedAttributes->{"TreatReturnedNullStringAs"};
  • trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp

    r121421 r121663  
    6161#include <wtf/RefPtr.h>
    6262#include <wtf/UnusedParam.h>
    63 #include <wtf/Vector.h>
    6463
    6564#if ENABLE(Condition1)
     
    880879    INC_STATS("DOM.TestObj.floatArray._get");
    881880    TestObj* imp = V8TestObj::toNative(info.Holder());
    882     return v8NumberArray(imp->floatArray());
     881    return v8Array(imp->floatArray(), info.GetIsolate());
    883882}
    884883
     
    887886    INC_STATS("DOM.TestObj.floatArray._set");
    888887    TestObj* imp = V8TestObj::toNative(info.Holder());
    889     Vector<float> v = v8NumberArrayToVector<float>(value);
     888    Vector<float> v = toNativeArray<float>(value);
    890889    imp->setFloatArray(v);
    891890    return;
     
    896895    INC_STATS("DOM.TestObj.doubleArray._get");
    897896    TestObj* imp = V8TestObj::toNative(info.Holder());
    898     return v8NumberArray(imp->doubleArray());
     897    return v8Array(imp->doubleArray(), info.GetIsolate());
    899898}
    900899
     
    903902    INC_STATS("DOM.TestObj.doubleArray._set");
    904903    TestObj* imp = V8TestObj::toNative(info.Holder());
    905     Vector<double> v = v8NumberArrayToVector<double>(value);
     904    Vector<double> v = toNativeArray<double>(value);
    906905    imp->setDoubleArray(v);
    907906    return;
  • trunk/Source/WebCore/bindings/v8/V8Binding.h

    r121658 r121663  
    344344
    345345    template <class T>
    346     struct Traits {
     346    struct V8ValueTraits {
    347347        static inline v8::Handle<v8::Value> arrayV8Value(const T& value, v8::Isolate* isolate)
    348348        {
     
    352352
    353353    template<>
    354     struct Traits<String> {
     354    struct V8ValueTraits<String> {
    355355        static inline v8::Handle<v8::Value> arrayV8Value(const String& value, v8::Isolate* isolate)
    356356        {
     
    360360
    361361    template<>
    362     struct Traits<unsigned long> {
     362    struct V8ValueTraits<unsigned long> {
    363363        static inline v8::Handle<v8::Value> arrayV8Value(const unsigned long& value, v8::Isolate* isolate)
    364364        {
    365365            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);
    366382        }
    367383    };
     
    373389        int index = 0;
    374390        typename Vector<T>::const_iterator end = iterator.end();
    375         typedef Traits<T> TraitsType;
     391        typedef V8ValueTraits<T> TraitsType;
    376392        for (typename Vector<T>::const_iterator iter = iterator.begin(); iter != end; ++iter)
    377393            result->Set(v8Integer(index++, isolate), TraitsType::arrayV8Value(*iter, isolate));
     
    381397    v8::Handle<v8::Value> v8Array(PassRefPtr<DOMStringList>, v8::Isolate*);
    382398
     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
    383425    template <class T>
    384426    Vector<T> toNativeArray(v8::Handle<v8::Value> value)
     
    388430
    389431        Vector<T> result;
     432        typedef NativeValueTraits<T> TraitsType;
    390433        v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value));
    391434        v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(v8Value);
    392435        size_t length = array->Length();
    393 
    394436        for (size_t i = 0; i < length; ++i) {
    395             result.append(v8ValueToWebCoreString(array->Get(i)));
     437            result.append(TraitsType::arrayNativeValue(array, i));
    396438        }
    397439        return result;
     
    521563    {
    522564        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;
    532565    }
    533566
     
    560593
    561594    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     }
    578595
    579596    PassRefPtr<DOMStringList> v8ValueToWebCoreDOMStringList(v8::Handle<v8::Value>);
Note: See TracChangeset for help on using the changeset viewer.