Chromium Code Reviews| Index: Source/WebCore/bindings/dart/DartUtilities.cpp |
| diff --git a/Source/WebCore/bindings/dart/DartUtilities.cpp b/Source/WebCore/bindings/dart/DartUtilities.cpp |
| index 11f674e7facf3743e084478934eec29dab147eb9..a73a886f83df72d107fa886fe51d78df9b67a862 100644 |
| --- a/Source/WebCore/bindings/dart/DartUtilities.cpp |
| +++ b/Source/WebCore/bindings/dart/DartUtilities.cpp |
| @@ -126,6 +126,60 @@ struct IntegerTrait { |
| } |
| }; |
| +template <> |
| +double DartUtilities::toNative<double>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toDouble(object); |
|
antonm
2012/01/19 14:05:49
I am not sure you can use those helpers, what if I
Nikolay
2012/01/19 15:08:46
Done.
|
| +} |
| + |
| +template <> |
| +float DartUtilities::toNative<float>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toDouble(object); |
| +} |
| + |
| +template <> |
| +int8_t DartUtilities::toNative<int8_t>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toInteger(object); |
| +} |
| + |
| +template <> |
| +int16_t DartUtilities::toNative<int16_t>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toInteger(object); |
| +} |
| + |
| +template <> |
| +int32_t DartUtilities::toNative<int32_t>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toInteger(object); |
| +} |
| + |
| +template <> |
| +int64_t DartUtilities::toNative<int64_t>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toInteger(object); |
| +} |
| + |
| +template <> |
| +uint8_t DartUtilities::toNative<uint8_t>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toInteger(object); |
|
antonm
2012/01/19 14:05:49
What if I pass -1 into such a function?
Nikolay
2012/01/19 15:08:46
c cast will apply. I think this behavior is natura
antonm
2012/01/19 15:33:13
I don't think so, as in Dart numbers doesn't have
Nikolay
2012/01/20 11:38:37
According to simple test in JS console this is beh
antonm
2012/01/20 17:35:57
Thanks a lot for verifying how JS works.
However,
|
| +} |
| + |
| +template <> |
| +uint16_t DartUtilities::toNative<uint16_t>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toInteger(object); |
| +} |
| + |
| +template <> |
| +uint32_t DartUtilities::toNative<uint32_t>(Dart_Handle object) |
| +{ |
| + return DartUtilities::toInteger(object); |
| +} |
| + |
| int64_t DartUtilities::toInteger(Dart_Handle object, Dart_Handle& exception) |
| { |
| return convert<IntegerTrait>(object, exception); |
| @@ -146,9 +200,11 @@ struct DoubleTrait { |
| if (!Dart_IsNumber(object)) |
| return Dart_Error("the object !is Number"); |
| - object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0); |
| - if (Dart_IsError(object)) |
| - return object; |
| + if (!Dart_IsDouble(object)) { |
| + object = Dart_InvokeDynamic(object, Dart_NewString("toDouble"), 0, 0); |
| + if (Dart_IsError(object)) |
| + return object; |
| + } |
| return Dart_DoubleValue(object, value); |
| } |
| @@ -246,11 +302,8 @@ void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port |
| ASSERT(!Dart_IsError(dom)); |
| Dart_Handle asList = Dart_InvokeStatic(dom, Dart_NewString("Utils"), Dart_NewString("convertToList"), 1, &value); |
| - if (Dart_IsError(asList)) { |
| - DartUtilities::reportProblem(DartUtilities::scriptExecutionContext(), asList); |
| - exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STATE_ERR); |
| + if (!checkResult(asList, exception)) |
| return; |
| - } |
| ASSERT(Dart_IsList(asList)); |
| intptr_t length = 0; |
| @@ -258,16 +311,12 @@ void DartUtilities::toMessagePortArray(Dart_Handle value, MessagePortArray& port |
| portArray.resize(length); |
| for (int i = 0; i < length; i++) { |
| Dart_Handle element = Dart_ListGetAt(asList, i); |
| - if (Dart_IsError(element)) { |
| - exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STATE_ERR); |
| + if (!checkResult(element, exception)) |
| return; |
| - } |
| MessagePort* messagePort = DartMessagePort::toNative(element, exception).get(); |
| - if (exception) { |
| - exception = DartDOMWrapper::exceptionCodeToDartException(INVALID_STATE_ERR); |
| + if (exception) |
| return; |
| - } |
| ASSERT(messagePort); |
| portArray[i] = messagePort; |