Index: src/runtime.cc |
diff --git a/src/runtime.cc b/src/runtime.cc |
index fbad080346e46bb8e1db5556871cb307d85872c2..116fe019bc0f41b9f78d2666e1c82148ff296bdb 100644 |
--- a/src/runtime.cc |
+++ b/src/runtime.cc |
@@ -1216,6 +1216,59 @@ DATA_VIEW_GETTER(Float64, double, NumberFromDouble) |
#undef DATA_VIEW_GETTER |
+ |
+template <typename T> |
+static T DataViewValueConverter(double value); |
titzer
2013/07/12 16:37:02
Can we name this function verb-ly, such as "Conver
Dmitry Lomov (no reviews)
2013/07/12 18:22:45
Done.
ConvertValueToDataView is not a good name -
|
+ |
+ |
+template <> |
+int8_t DataViewValueConverter<int8_t>(double value) { |
+ return static_cast<int8_t>(DoubleToInt32(value)); |
+} |
+ |
+ |
+template <> |
+int16_t DataViewValueConverter<int16_t>(double value) { |
+ return static_cast<int16_t>(DoubleToInt32(value)); |
+} |
+ |
+ |
+template <> |
+int32_t DataViewValueConverter<int32_t>(double value) { |
+ return DoubleToInt32(value); |
+} |
+ |
+ |
+template <> |
+uint8_t DataViewValueConverter<uint8_t>(double value) { |
+ return static_cast<uint8_t>(DoubleToUint32(value)); |
+} |
+ |
+ |
+template <> |
+uint16_t DataViewValueConverter<uint16_t>(double value) { |
+ return static_cast<uint16_t>(DoubleToUint32(value)); |
+} |
+ |
+ |
+template <> |
+uint32_t DataViewValueConverter<uint32_t>(double value) { |
+ return DoubleToUint32(value); |
+} |
+ |
+ |
+template <> |
+float DataViewValueConverter<float>(double value) { |
+ return static_cast<float>(value); |
+} |
+ |
+ |
+template <> |
+double DataViewValueConverter<double>(double value) { |
+ return value; |
+} |
+ |
+ |
#define DATA_VIEW_SETTER(TypeName, Type) \ |
RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewSet##TypeName) { \ |
HandleScope scope(isolate); \ |
@@ -1224,7 +1277,7 @@ DATA_VIEW_GETTER(Float64, double, NumberFromDouble) |
CONVERT_ARG_HANDLE_CHECKED(Object, offset, 1); \ |
CONVERT_ARG_HANDLE_CHECKED(Object, value, 2); \ |
CONVERT_BOOLEAN_ARG_CHECKED(is_little_endian, 3); \ |
- Type v = static_cast<Type>(value->Number()); \ |
+ Type v = DataViewValueConverter<Type>(value->Number()); \ |
if (DataViewSetValue( \ |
isolate, holder, offset, is_little_endian, v)) { \ |
return isolate->heap()->undefined_value(); \ |