+2012-07-02 Vineet Chaudhary <rgf748@motorola.com>
+
+ [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 <kpiascik@rim.com>
[EFL] [GTK] [QT] fast/viewport/viewport-91.html is failing after r121555
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;
}
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
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;
'SerializedScriptValue' => 1,
'boolean' => 1,
'double' => 1,
- 'double[]' => 1,
'float' => 1,
- 'float[]' => 1,
'int' => 1,
'long long' => 1,
'long' => 1,
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) {
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/UnusedParam.h>
-#include <wtf/Vector.h>
#if ENABLE(Condition1)
#include "V8TestObjectA.h"
{
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;
}
{
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;
}
}
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);
};
template<>
- struct Traits<String> {
+ struct V8ValueTraits<String> {
static inline v8::Handle<v8::Value> arrayV8Value(const String& value, v8::Isolate* isolate)
{
return v8String(value, isolate);
};
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;
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)
{
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;
}
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();
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 {