Reviewers: titzer, rossberg,
Message:
PTAL
Description:
Use corerct conversions for DataView accessors.
We now use DoubleTo(U)Int32 that follows ES specification.
[email protected],[email protected]
Please review this at https://codereview.chromium.org/18703007/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M src/runtime.cc
M test/mjsunit/harmony/dataview-accessors.js
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);
+
+
+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(); \
Index: test/mjsunit/harmony/dataview-accessors.js
diff --git a/test/mjsunit/harmony/dataview-accessors.js
b/test/mjsunit/harmony/dataview-accessors.js
index
b655a4164a14d338a12a02a94ed5b59e22e0aed4..8cbff3d3c83de295e34f79509a27ddbbb276915d
100644
--- a/test/mjsunit/harmony/dataview-accessors.js
+++ b/test/mjsunit/harmony/dataview-accessors.js
@@ -294,12 +294,53 @@ function TestSetters() {
runFloatTestCases(false, 7);
runNegativeIndexTests(false);
-
}
TestGetters();
TestSetters();
+function CheckOutOfRange(typename, value, expected) {
+ var view = new DataView(new ArrayBuffer(100));
+ assertSame(undefined, view["set" + typename](0, value));
+ assertSame(expected, view["get" + typename](0));
+ assertSame(undefined, view["set" + typename](0, value, true));
+ assertSame(expected, view["get" + typename](0, true));
+}
+
+function TestOutOfRange() {
+ CheckOutOfRange("Int8", 0x80, -0x80);
+ CheckOutOfRange("Int8", 0x1000, 0);
+ CheckOutOfRange("Int8", -0x81, 0x7F);
+
+ CheckOutOfRange("Uint8", 0x100, 0);
+ CheckOutOfRange("Uint8", 0x1000, 0);
+ CheckOutOfRange("Uint8", -0x80, 0x80);
+ CheckOutOfRange("Uint8", -1, 0xFF);
+ CheckOutOfRange("Uint8", -0xFF, 1);
+
+ CheckOutOfRange("Int16", 0x8000, -0x8000);
+ CheckOutOfRange("Int16", 0x10000, 0);
+ CheckOutOfRange("Int16", -0x8001, 0x7FFF);
+
+ CheckOutOfRange("Uint16", 0x10000, 0);
+ CheckOutOfRange("Uint16", 0x100000, 0);
+ CheckOutOfRange("Uint16", -0x8000, 0x8000);
+ CheckOutOfRange("Uint16", -1, 0xFFFF);
+ CheckOutOfRange("Uint16", -0xFFFF, 1);
+
+ CheckOutOfRange("Int32", 0x80000000, -0x80000000);
+ CheckOutOfRange("Int32", 0x100000000, 0);
+ CheckOutOfRange("Int32", -0x80000001, 0x7FFFFFFF);
+
+ CheckOutOfRange("Uint32", 0x100000000, 0);
+ CheckOutOfRange("Uint32", 0x1000000000, 0);
+ CheckOutOfRange("Uint32", -0x80000000, 0x80000000);
+ CheckOutOfRange("Uint32", -1, 0xFFFFFFFF);
+ CheckOutOfRange("Uint32", -0xFFFFFFFF, 1);
+}
+
+TestOutOfRange();
+
function TestGeneralAccessors() {
var a = new DataView(new ArrayBuffer(256));
function CheckAccessor(name) {
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.