Modified: trunk/Source/WebCore/ChangeLog (99631 => 99632)
--- trunk/Source/WebCore/ChangeLog 2011-11-09 00:27:58 UTC (rev 99631)
+++ trunk/Source/WebCore/ChangeLog 2011-11-09 00:43:07 UTC (rev 99632)
@@ -1,3 +1,31 @@
+2011-11-08 Scott Graham <[email protected]>
+
+ Add support for arrays of numbers to IDL bindings code generator
+ https://bugs.webkit.org/show_bug.cgi?id=71763
+
+ Adds support for float[] and double[] to IDL. Support for other types
+ appears to be more complicated (or at least more copy-paste) so not
+ doing that for now for lack of need.
+
+ Reviewed by Adam Barth.
+
+ Tests added to TestObj.idl.
+
+ * bindings/scripts/CodeGeneratorV8.pm:
+ (IsRefPtrType):
+ (GetNativeType):
+ (JSValueToNative):
+ (NativeToJSValue):
+ * bindings/scripts/test/TestObj.idl:
+ * bindings/scripts/test/V8/V8TestObj.cpp:
+ (WebCore::TestObjInternal::floatArrayAttrGetter):
+ (WebCore::TestObjInternal::floatArrayAttrSetter):
+ (WebCore::TestObjInternal::doubleArrayAttrGetter):
+ (WebCore::TestObjInternal::doubleArrayAttrSetter):
+ * bindings/v8/V8Binding.h:
+ (WebCore::v8NumberArray):
+ (WebCore::v8NumberArrayToVector):
+
2011-11-08 Dan Bernstein <[email protected]>
REGRESSION (r99613): Incomplete painting of the root element background in flipped blocks writing mode
Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm (99631 => 99632)
--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2011-11-09 00:27:58 UTC (rev 99631)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm 2011-11-09 00:43:07 UTC (rev 99632)
@@ -3079,6 +3079,8 @@
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;
}
@@ -3134,8 +3136,10 @@
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";
- # FIXME: Add proper support for T[], T[]?, sequence<T>.
return "RefPtr<DOMStringList>" if $type eq "DOMString[]";
# Default, assume native type is a pointer with same type name as idl type
@@ -3192,6 +3196,14 @@
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;
@@ -3342,6 +3354,8 @@
'boolean' => 1,
'long long' => 1,
'unsigned long long' => 1,
+ 'float[]' => 1,
+ 'double[]' => 1,
'DOMString' => 1,
'CompareHow' => 1,
'SerializedScriptValue' => 1,
@@ -3432,6 +3446,9 @@
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->{"ConvertNullStringTo"};
if (defined $conv) {
Modified: trunk/Source/WebCore/bindings/scripts/test/TestObj.idl (99631 => 99632)
--- trunk/Source/WebCore/bindings/scripts/test/TestObj.idl 2011-11-09 00:27:58 UTC (rev 99631)
+++ trunk/Source/WebCore/bindings/scripts/test/TestObj.idl 2011-11-09 00:43:07 UTC (rev 99632)
@@ -172,6 +172,12 @@
attribute [EnabledAtRuntime=FeatureName] long enabledAtRuntimeAttr2;
#endif
+
+#if defined(TESTING_V8)
+ attribute float[] floatArray;
+ attribute double[] doubleArray;
+#endif
+
// ObjectiveC reserved words.
readonly attribute long description;
attribute long id;
Modified: trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp (99631 => 99632)
--- trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp 2011-11-09 00:27:58 UTC (rev 99631)
+++ trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp 2011-11-09 00:43:07 UTC (rev 99632)
@@ -46,6 +46,7 @@
#include <wtf/RefCounted.h>
#include <wtf/RefPtr.h>
#include <wtf/UnusedParam.h>
+#include <wtf/Vector.h>
#if ENABLE(Condition1)
#include "V8TestObjectA.h"
@@ -642,6 +643,38 @@
return;
}
+static v8::Handle<v8::Value> floatArrayAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+ INC_STATS("DOM.TestObj.floatArray._get");
+ TestObj* imp = V8TestObj::toNative(info.Holder());
+ return v8NumberArray(imp->floatArray());
+}
+
+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);
+ imp->setFloatArray(v);
+ return;
+}
+
+static v8::Handle<v8::Value> doubleArrayAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
+{
+ INC_STATS("DOM.TestObj.doubleArray._get");
+ TestObj* imp = V8TestObj::toNative(info.Holder());
+ return v8NumberArray(imp->doubleArray());
+}
+
+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);
+ imp->setDoubleArray(v);
+ return;
+}
+
static v8::Handle<v8::Value> descriptionAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
{
INC_STATS("DOM.TestObj.description._get");
@@ -1375,6 +1408,10 @@
{"cachedAttribute1", TestObjInternal::cachedAttribute1AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
// Attribute 'cachedAttribute2' (Type: 'readonly attribute' ExtAttr: 'CachedAttribute')
{"cachedAttribute2", TestObjInternal::cachedAttribute2AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+ // Attribute 'floatArray' (Type: 'attribute' ExtAttr: '')
+ {"floatArray", TestObjInternal::floatArrayAttrGetter, TestObjInternal::floatArrayAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
+ // Attribute 'doubleArray' (Type: 'attribute' ExtAttr: '')
+ {"doubleArray", TestObjInternal::doubleArrayAttrGetter, TestObjInternal::doubleArrayAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
// Attribute 'description' (Type: 'readonly attribute' ExtAttr: '')
{"description", TestObjInternal::descriptionAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */},
// Attribute 'id' (Type: 'attribute' ExtAttr: '')
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (99631 => 99632)
--- trunk/Source/WebCore/bindings/v8/V8Binding.h 2011-11-09 00:27:58 UTC (rev 99631)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h 2011-11-09 00:43:07 UTC (rev 99632)
@@ -349,6 +349,15 @@
v8::Handle<v8::Value> v8StringOrFalse(const String& str);
+ 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;
+ }
+
double toWebCoreDate(v8::Handle<v8::Value> object);
v8::Handle<v8::Value> v8DateOrNull(double value);
@@ -379,6 +388,22 @@
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(v8::Integer::New(i));
+ result.append(static_cast<T>(indexedValue->NumberValue()));
+ }
+ return result;
+ }
+
PassRefPtr<DOMStringList> v8ValueToWebCoreDOMStringList(v8::Handle<v8::Value>);
class V8ParameterBase {