Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(136)

Unified Diff: src/runtime.cc

Issue 18703007: Use corerct conversions for DataView accessors. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: CR feedback Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | test/mjsunit/harmony/dataview-accessors.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index fbad080346e46bb8e1db5556871cb307d85872c2..a3b09665eadaea0d9576591da7f2ad45c9f6263a 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 DataViewConvertValue(double value);
+
+
+template <>
+int8_t DataViewConvertValue<int8_t>(double value) {
+ return static_cast<int8_t>(DoubleToInt32(value));
+}
+
+
+template <>
+int16_t DataViewConvertValue<int16_t>(double value) {
+ return static_cast<int16_t>(DoubleToInt32(value));
+}
+
+
+template <>
+int32_t DataViewConvertValue<int32_t>(double value) {
+ return DoubleToInt32(value);
+}
+
+
+template <>
+uint8_t DataViewConvertValue<uint8_t>(double value) {
+ return static_cast<uint8_t>(DoubleToUint32(value));
+}
+
+
+template <>
+uint16_t DataViewConvertValue<uint16_t>(double value) {
+ return static_cast<uint16_t>(DoubleToUint32(value));
+}
+
+
+template <>
+uint32_t DataViewConvertValue<uint32_t>(double value) {
+ return DoubleToUint32(value);
+}
+
+
+template <>
+float DataViewConvertValue<float>(double value) {
+ return static_cast<float>(value);
+}
+
+
+template <>
+double DataViewConvertValue<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 = DataViewConvertValue<Type>(value->Number()); \
if (DataViewSetValue( \
isolate, holder, offset, is_little_endian, v)) { \
return isolate->heap()->undefined_value(); \
« no previous file with comments | « no previous file | test/mjsunit/harmony/dataview-accessors.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698