Changeset 99632 in webkit
- Timestamp:
- Nov 8, 2011 4:43:07 PM (12 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r99630 r99632 1 2011-11-08 Scott Graham <scottmg@chromium.org> 2 3 Add support for arrays of numbers to IDL bindings code generator 4 https://bugs.webkit.org/show_bug.cgi?id=71763 5 6 Adds support for float[] and double[] to IDL. Support for other types 7 appears to be more complicated (or at least more copy-paste) so not 8 doing that for now for lack of need. 9 10 Reviewed by Adam Barth. 11 12 Tests added to TestObj.idl. 13 14 * bindings/scripts/CodeGeneratorV8.pm: 15 (IsRefPtrType): 16 (GetNativeType): 17 (JSValueToNative): 18 (NativeToJSValue): 19 * bindings/scripts/test/TestObj.idl: 20 * bindings/scripts/test/V8/V8TestObj.cpp: 21 (WebCore::TestObjInternal::floatArrayAttrGetter): 22 (WebCore::TestObjInternal::floatArrayAttrSetter): 23 (WebCore::TestObjInternal::doubleArrayAttrGetter): 24 (WebCore::TestObjInternal::doubleArrayAttrSetter): 25 * bindings/v8/V8Binding.h: 26 (WebCore::v8NumberArray): 27 (WebCore::v8NumberArrayToVector): 28 1 29 2011-11-08 Dan Bernstein <mitz@apple.com> 2 30 -
trunk/Source/WebCore/bindings/scripts/CodeGeneratorV8.pm
r99507 r99632 3080 3080 return 0 if $type eq "unsigned long"; 3081 3081 return 0 if $type eq "unsigned short"; 3082 return 0 if $type eq "float[]"; 3083 return 0 if $type eq "double[]"; 3082 3084 3083 3085 return 1; … … 3135 3137 return "RefPtr<MediaQueryListListener>" if $type eq "MediaQueryListListener"; 3136 3138 3139 # FIXME: Support T[], T[]?, sequence<T> generically 3140 return "Vector<float>" if $type eq "float[]"; 3141 return "Vector<double>" if $type eq "double[]"; 3137 3142 return "RefPtr<DOMStringList>" if $type eq "DOMStringList"; 3138 # FIXME: Add proper support for T[], T[]?, sequence<T>.3139 3143 return "RefPtr<DOMStringList>" if $type eq "DOMString[]"; 3140 3144 … … 3193 3197 # FIXME: Add proper support for T[], T[]? and sequence<T>. 3194 3198 return "v8ValueToWebCoreDOMStringList($value)" if $type eq "DOMString[]"; 3199 if ($type eq "float[]") { 3200 AddToImplIncludes("wtf/Vector.h"); 3201 return "v8NumberArrayToVector<float>($value)"; 3202 } 3203 if ($type eq "double[]") { 3204 AddToImplIncludes("wtf/Vector.h"); 3205 return "v8NumberArrayToVector<double>($value)"; 3206 } 3195 3207 3196 3208 if ($type eq "DOMString" or $type eq "DOMUserData") { … … 3343 3355 'long long' => 1, 3344 3356 'unsigned long long' => 1, 3357 'float[]' => 1, 3358 'double[]' => 1, 3345 3359 'DOMString' => 1, 3346 3360 'CompareHow' => 1, … … 3433 3447 return "$value.v8Value()" if $nativeType eq "ScriptValue"; 3434 3448 3449 return "v8NumberArray($value)" if $type eq "float[]"; 3450 return "v8NumberArray($value)" if $type eq "double[]"; 3451 3435 3452 if ($codeGenerator->IsStringType($type)) { 3436 3453 my $conv = $signature->extendedAttributes->{"ConvertNullStringTo"}; -
trunk/Source/WebCore/bindings/scripts/test/TestObj.idl
r99244 r99632 173 173 #endif 174 174 175 176 #if defined(TESTING_V8) 177 attribute float[] floatArray; 178 attribute double[] doubleArray; 179 #endif 180 175 181 // ObjectiveC reserved words. 176 182 readonly attribute long description; -
trunk/Source/WebCore/bindings/scripts/test/V8/V8TestObj.cpp
r99244 r99632 47 47 #include <wtf/RefPtr.h> 48 48 #include <wtf/UnusedParam.h> 49 #include <wtf/Vector.h> 49 50 50 51 #if ENABLE(Condition1) … … 640 641 int v = toInt32(value); 641 642 imp->setEnabledAtRuntimeAttr2(v); 643 return; 644 } 645 646 static v8::Handle<v8::Value> floatArrayAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) 647 { 648 INC_STATS("DOM.TestObj.floatArray._get"); 649 TestObj* imp = V8TestObj::toNative(info.Holder()); 650 return v8NumberArray(imp->floatArray()); 651 } 652 653 static void floatArrayAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) 654 { 655 INC_STATS("DOM.TestObj.floatArray._set"); 656 TestObj* imp = V8TestObj::toNative(info.Holder()); 657 Vector<float> v = v8NumberArrayToVector<float>(value); 658 imp->setFloatArray(v); 659 return; 660 } 661 662 static v8::Handle<v8::Value> doubleArrayAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) 663 { 664 INC_STATS("DOM.TestObj.doubleArray._get"); 665 TestObj* imp = V8TestObj::toNative(info.Holder()); 666 return v8NumberArray(imp->doubleArray()); 667 } 668 669 static void doubleArrayAttrSetter(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::AccessorInfo& info) 670 { 671 INC_STATS("DOM.TestObj.doubleArray._set"); 672 TestObj* imp = V8TestObj::toNative(info.Holder()); 673 Vector<double> v = v8NumberArrayToVector<double>(value); 674 imp->setDoubleArray(v); 642 675 return; 643 676 } … … 1376 1409 // Attribute 'cachedAttribute2' (Type: 'readonly attribute' ExtAttr: 'CachedAttribute') 1377 1410 {"cachedAttribute2", TestObjInternal::cachedAttribute2AttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, 1411 // Attribute 'floatArray' (Type: 'attribute' ExtAttr: '') 1412 {"floatArray", TestObjInternal::floatArrayAttrGetter, TestObjInternal::floatArrayAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, 1413 // Attribute 'doubleArray' (Type: 'attribute' ExtAttr: '') 1414 {"doubleArray", TestObjInternal::doubleArrayAttrGetter, TestObjInternal::doubleArrayAttrSetter, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, 1378 1415 // Attribute 'description' (Type: 'readonly attribute' ExtAttr: '') 1379 1416 {"description", TestObjInternal::descriptionAttrGetter, 0, 0 /* no data */, static_cast<v8::AccessControl>(v8::DEFAULT), static_cast<v8::PropertyAttribute>(v8::None), 0 /* on instance */}, -
trunk/Source/WebCore/bindings/v8/V8Binding.h
r97839 r99632 350 350 v8::Handle<v8::Value> v8StringOrFalse(const String& str); 351 351 352 template <class T> v8::Handle<v8::Value> v8NumberArray(const Vector<T>& values) 353 { 354 size_t size = values.size(); 355 v8::Local<v8::Array> result = v8::Array::New(size); 356 for (size_t i = 0; i < size; ++i) 357 result->Set(i, v8::Number::New(values[i])); 358 return result; 359 } 360 352 361 double toWebCoreDate(v8::Handle<v8::Value> object); 353 362 … … 379 388 380 389 String int32ToWebCoreString(int value); 390 391 template <class T> Vector<T> v8NumberArrayToVector(v8::Handle<v8::Value> value) 392 { 393 v8::Local<v8::Value> v8Value(v8::Local<v8::Value>::New(value)); 394 if (!v8Value->IsArray()) 395 return Vector<T>(); 396 397 Vector<T> result; 398 v8::Local<v8::Array> v8Array = v8::Local<v8::Array>::Cast(v8Value); 399 size_t length = v8Array->Length(); 400 for (size_t i = 0; i < length; ++i) { 401 v8::Local<v8::Value> indexedValue = v8Array->Get(v8::Integer::New(i)); 402 result.append(static_cast<T>(indexedValue->NumberValue())); 403 } 404 return result; 405 } 381 406 382 407 PassRefPtr<DOMStringList> v8ValueToWebCoreDOMStringList(v8::Handle<v8::Value>);
Note: See TracChangeset
for help on using the changeset viewer.