- Revision
- 121663
- Author
- [email protected]
- Date
- 2012-07-02 01:42:29 -0700 (Mon, 02 Jul 2012)
Log Message
[V8Binding] Merging v8NumberArray()/v8NumberArrayToVector() to v8Array()/toNativeArray() respectively.
https://bugs.webkit.org/show_bug.cgi?id=90338
Patch by Vineet Chaudhary <[email protected]> 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):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (121662 => 121663)
--- trunk/Source/WebCore/ChangeLog 2012-07-02 07:50:43 UTC (rev 121662)
+++ trunk/Source/WebCore/ChangeLog 2012-07-02 08:42:29 UTC (rev 121663)
@@ -1,3 +1,30 @@
+2012-07-02 Vineet Chaudhary <[email protected]>
+
+ [V8Binding] Merging v8NumberArray()/v8NumberArrayToVector() to v8Array()/toNativeArray() respectively.
+ https://bugs.webkit.org/show_bug.cgi?id=90338
+
+ 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):
+
2012-07-02 Konrad Piascik <[email protected]>
[EFL] [GTK] [QT] fast/viewport/viewport-91.html is failing after r121555
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (121662 => 121663)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2012-07-02 07:50:43 UTC (rev 121662)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2012-07-02 08:42:29 UTC (rev 121663)
@@ -3511,8 +3511,6 @@
return 0 if $type eq "unsigned";
return 0 if $type eq "unsigned long";
return 0 if $type eq "unsigned short";
- return 0 if $type eq "float[]";
- return 0 if $type eq "double[]";
return 1;
}
@@ -3573,8 +3571,6 @@
return "RefPtr<MediaQueryListListener>" if $type eq "MediaQueryListListener";
# FIXME: Support T[], T[]?, sequence<T> generically
- return "Vector<float>" if $type eq "float[]";
- return "Vector<double>" if $type eq "double[]";
return "RefPtr<DOMStringList>" if $type eq "DOMStringList";
# Default, assume native type is a pointer with same type name as idl type
@@ -3633,14 +3629,6 @@
return "v8ValueToWebCoreDOMStringList($value)" if $type eq "DOMStringList";
# FIXME: Add proper support for T[], T[]? and sequence<T>.
return "v8ValueToWebCoreDOMStringList($value)" if $type eq "DOMString[]";
- if ($type eq "float[]") {
- AddToImplIncludes("wtf/Vector.h");
- return "v8NumberArrayToVector<float>($value)";
- }
- if ($type eq "double[]") {
- AddToImplIncludes("wtf/Vector.h");
- return "v8NumberArrayToVector<double>($value)";
- }
if ($type eq "DOMString" or $type eq "DOMUserData") {
return $value;
@@ -3820,9 +3808,7 @@
'SerializedScriptValue' => 1,
'boolean' => 1,
'double' => 1,
- 'double[]' => 1,
'float' => 1,
- 'float[]' => 1,
'int' => 1,
'long long' => 1,
'long' => 1,
@@ -3909,9 +3895,6 @@
return "v8::Number::New($value)" if $codeGenerator->IsPrimitiveType($type);
return "$value.v8Value()" if $nativeType eq "ScriptValue";
- return "v8NumberArray($value)" if $type eq "float[]";
- return "v8NumberArray($value)" if $type eq "double[]";
-
if ($codeGenerator->IsStringType($type)) {
my $conv = $signature->extendedAttributes->{"TreatReturnedNullStringAs"};
if (defined $conv) {
Modified: trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp (121662 => 121663)
--- trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp 2012-07-02 07:50:43 UTC (rev 121662)
+++ trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp 2012-07-02 08:42:29 UTC (rev 121663)
@@ -60,7 +60,6 @@
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/UnusedParam.h>
-#include <wtf/Vector.h>
#if ENABLE(Condition1)
#include "V8TestObjectA.h"
@@ -879,14 +878,14 @@
{
INC_STATS("DOM.TestObj.floatArray._get");
TestObj* imp = V8TestObj::toNative(info.Holder());
- return v8NumberArray(imp->floatArray());
+ return v8Array(imp->floatArray(), info.GetIsolate());
}
static void floatArrayAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
INC_STATS("DOM.TestObj.floatArray._set");
TestObj* imp = V8TestObj::toNative(info.Holder());
- Vector<float> v = v8NumberArrayToVector<float>(value);
+ Vector<float> v = toNativeArray<float>(value);
imp->setFloatArray(v);
return;
}
@@ -895,14 +894,14 @@
{
INC_STATS("DOM.TestObj.doubleArray._get");
TestObj* imp = V8TestObj::toNative(info.Holder());
- return v8NumberArray(imp->doubleArray());
+ return v8Array(imp->doubleArray(), info.GetIsolate());
}
static void doubleArrayAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info)
{
INC_STATS("DOM.TestObj.doubleArray._set");
TestObj* imp = V8TestObj::toNative(info.Holder());
- Vector<double> v = v8NumberArrayToVector<double>(value);
+ Vector<double> v = toNativeArray<double>(value);
imp->setDoubleArray(v);
return;
}
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (121662 => 121663)
--- trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-07-02 07:50:43 UTC (rev 121662)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-07-02 08:42:29 UTC (rev 121663)
@@ -343,7 +343,7 @@
}
template <class T>
- struct Traits {
+ struct V8ValueTraits {
static inline v8::Handle<v8::Value> arrayV8Value(const T& value, v8::Isolate* isolate)
{
return toV8(WTF::getPtr(value), isolate);
@@ -351,7 +351,7 @@
};
template<>
- struct Traits<String> {
+ struct V8ValueTraits<String> {
static inline v8::Handle<v8::Value> arrayV8Value(const String& value, v8::Isolate* isolate)
{
return v8String(value, isolate);
@@ -359,20 +359,36 @@
};
template<>
- struct Traits<unsigned long> {
+ struct V8ValueTraits<unsigned long> {
static inline v8::Handle<v8::Value> arrayV8Value(const unsigned long& value, v8::Isolate* isolate)
{
return v8UnsignedInteger(value, isolate);
}
};
+ template<>
+ struct V8ValueTraits<float> {
+ static inline v8::Handle<v8::Value> arrayV8Value(const float& value, v8::Isolate*)
+ {
+ return v8::Number::New(value);
+ }
+ };
+
+ template<>
+ struct V8ValueTraits<double> {
+ static inline v8::Handle<v8::Value> arrayV8Value(const double& value, v8::Isolate*)
+ {
+ return v8::Number::New(value);
+ }
+ };
+
template<typename T>
v8::Handle<v8::Value> v8Array(const Vector<T>& iterator, v8::Isolate* isolate)
{
v8::Local<v8::Array> result = v8::Array::New(iterator.size());
int index = 0;
typename Vector<T>::const_iterator end = iterator.end();
- typedef Traits<T> TraitsType;
+ typedef V8ValueTraits<T> TraitsType;
for (typename Vector<T>::const_iterator iter = iterator.begin(); iter != end; ++iter)
result->Set(v8Integer(index++, isolate), TraitsType::arrayV8Value(*iter, isolate));
return result;
@@ -380,6 +396,32 @@
v8::Handle<v8::Value> v8Array(PassRefPtr<DOMStringList>, v8::Isolate*);
+ template<class T> struct NativeValueTraits;
+
+ template<>
+ struct NativeValueTraits<String> {
+ static inline String arrayNativeValue(const v8::Local<v8::Array>& array, size_t i)
+ {
+ return v8ValueToWebCoreString(array->Get(i));
+ }
+ };
+
+ template<>
+ struct NativeValueTraits<float> {
+ static inline float arrayNativeValue(const v8::Local<v8::Array>& array, size_t i)
+ {
+ return static_cast<float>(array->Get(v8Integer(i))->NumberValue());
+ }
+ };
+
+ template<>
+ struct NativeValueTraits<double> {
+ static inline double arrayNativeValue(const v8::Local<v8::Array>& array, size_t i)
+ {
+ return static_cast<double>(array->Get(v8Integer(i))->NumberValue());
+ }
+ };
+
template <class T>
Vector<T> toNativeArray(v8::Handle<v8::Value> value)
{
@@ -387,12 +429,12 @@
return Vector<T>();
Vector<T> result;
+ typedef NativeValueTraits<T> TraitsType;
v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value));
v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast(v8Value);
size_t length = array->Length();
-
for (size_t i = 0; i < length; ++i) {
- result.append(v8ValueToWebCoreString(array->Get(i)));
+ result.append(TraitsType::arrayNativeValue(array, i));
}
return result;
}
@@ -522,15 +564,6 @@
return str.isNull() ? v8::Handle<v8::Value>(v8Boolean(false)) : v8::Handle<v8::Value>(v8String(str, isolate));
}
- template <class T> v8::Handle<v8::Value> v8NumberArray(const Vector<T>& values)
- {
- size_t size = values.size();
- v8::Local<v8::Array> result = v8::Array::New(size);
- for (size_t i = 0; i < size; ++i)
- result->Set(i, v8::Number::New(values[i]));
- return result;
- }
-
inline double toWebCoreDate(v8::Handle<v8::Value> object)
{
return (object->IsDate() || object->IsNumber()) ? object->NumberValue() : std::numeric_limits<double>::quiet_NaN();
@@ -560,22 +593,6 @@
String int32ToWebCoreString(int value);
- template <class T> Vector<T> v8NumberArrayToVector(v8::Handle<v8::Value> value)
- {
- v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value));
- if (!v8Value->IsArray())
- return Vector<T>();
-
- Vector<T> result;
- v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value);
- size_t length = v8Array->Length();
- for (size_t i = 0; i < length; ++i) {
- v8::Local<v8::Value> indexedValue = v8Array->Get(v8Integer(i));
- result.append(static_cast<T>(indexedValue->NumberValue()));
- }
- return result;
- }
-
PassRefPtr<DOMStringList> v8ValueToWebCoreDOMStringList(v8::Handle<v8::Value>);
class V8ParameterBase {