Reviewers: Benedikt Meurer, rossberg,

Message:
PTAL

Description:
Change DataView accessors behavior for insufficient args.

ES6 spec for DataView is not fully finished, but Blink, WebKit and
Firefox agree in that for DataView use of getters/setters with no
arguments should result in exceptions, while undefined offset argument
is the same as zero.

[email protected],[email protected]

Please review this at https://codereview.chromium.org/18313007/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/typedarray.js
  M test/mjsunit/harmony/dataview-accessors.js


Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index 57d0c60f9ba00dfd4a00e1649d872057d76269f8..3a1d8a70ad2b51e4572d7468eedf2716474af1a0 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -259,6 +259,9 @@ function DataViewGetInt8(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getInt8', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   return %DataViewGetInt8(this,
                           ToPositiveDataViewOffset(offset),
                           !!little_endian);
@@ -269,6 +272,9 @@ function DataViewSetInt8(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setInt8', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   %DataViewSetInt8(this,
                    ToPositiveDataViewOffset(offset),
                    TO_NUMBER_INLINE(value),
@@ -280,6 +286,9 @@ function DataViewGetUint8(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getUint8', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   return %DataViewGetUint8(this,
                            ToPositiveDataViewOffset(offset),
                            !!little_endian);
@@ -290,6 +299,9 @@ function DataViewSetUint8(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setUint8', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   %DataViewSetUint8(this,
                    ToPositiveDataViewOffset(offset),
                    TO_NUMBER_INLINE(value),
@@ -301,6 +313,9 @@ function DataViewGetInt16(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getInt16', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   return %DataViewGetInt16(this,
                            ToPositiveDataViewOffset(offset),
                            !!little_endian);
@@ -311,6 +326,9 @@ function DataViewSetInt16(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setInt16', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   %DataViewSetInt16(this,
                     ToPositiveDataViewOffset(offset),
                     TO_NUMBER_INLINE(value),
@@ -322,6 +340,9 @@ function DataViewGetUint16(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getUint16', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   return %DataViewGetUint16(this,
                             ToPositiveDataViewOffset(offset),
                             !!little_endian);
@@ -332,6 +353,9 @@ function DataViewSetUint16(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setUint16', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   %DataViewSetUint16(this,
                      ToPositiveDataViewOffset(offset),
                      TO_NUMBER_INLINE(value),
@@ -343,6 +367,9 @@ function DataViewGetInt32(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getInt32', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   return %DataViewGetInt32(this,
                            ToPositiveDataViewOffset(offset),
                            !!little_endian);
@@ -353,6 +380,9 @@ function DataViewSetInt32(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setInt32', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   %DataViewSetInt32(this,
                     ToPositiveDataViewOffset(offset),
                     TO_NUMBER_INLINE(value),
@@ -364,6 +394,9 @@ function DataViewGetUint32(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getUint32', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   return %DataViewGetUint32(this,
                             ToPositiveDataViewOffset(offset),
                             !!little_endian);
@@ -374,6 +407,9 @@ function DataViewSetUint32(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setUint32', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   %DataViewSetUint32(this,
                      ToPositiveDataViewOffset(offset),
                      TO_NUMBER_INLINE(value),
@@ -385,6 +421,9 @@ function DataViewGetFloat32(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getFloat32', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   return %DataViewGetFloat32(this,
                              ToPositiveDataViewOffset(offset),
                              !!little_endian);
@@ -395,6 +434,9 @@ function DataViewSetFloat32(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setFloat32', this]);
   }
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
+  }
   %DataViewSetFloat32(this,
                       ToPositiveDataViewOffset(offset),
                       TO_NUMBER_INLINE(value),
@@ -406,9 +448,8 @@ function DataViewGetFloat64(offset, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.getFloat64', this]);
   }
-  offset = TO_INTEGER(offset);
-  if (offset < 0) {
-    throw MakeRangeError("invalid_data_view_accessor_offset");
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
   }
   return %DataViewGetFloat64(this,
                              ToPositiveDataViewOffset(offset),
@@ -420,9 +461,8 @@ function DataViewSetFloat64(offset, value, little_endian) {
     throw MakeTypeError('incompatible_method_reciever',
                         ['DataView.setFloat64', this]);
   }
-  offset = TO_INTEGER(offset);
-  if (offset < 0) {
-    throw MakeRangeError("invalid_data_view_accessor_offset");
+  if (%_ArgumentsLength() < 2) {
+    throw MakeTypeError('invalid_argument');
   }
   %DataViewSetFloat64(this,
                       ToPositiveDataViewOffset(offset),
Index: test/mjsunit/harmony/dataview-accessors.js
diff --git a/test/mjsunit/harmony/dataview-accessors.js b/test/mjsunit/harmony/dataview-accessors.js index 9dd8fe35e046b87b08fcbabfc7c286380de87622..5b3627e45a4ba10e1788f98ddedacad2dc6bfa89 100644
--- a/test/mjsunit/harmony/dataview-accessors.js
+++ b/test/mjsunit/harmony/dataview-accessors.js
@@ -105,39 +105,46 @@ function runIntegerTestCases(isTestingGet, array, start, length) {
   createDataView(array, 0, true, start, length);

   test(isTestingGet, "Int8", 0, 0);
+  test(isTestingGet, "Int8", undefined, 0);
   test(isTestingGet, "Int8", 8, -128);
   test(isTestingGet, "Int8", 15, -1);

   test(isTestingGet, "Uint8", 0, 0);
+  test(isTestingGet, "Uint8", undefined, 0);
   test(isTestingGet, "Uint8", 8, 128);
   test(isTestingGet, "Uint8", 15, 255);

   // Little endian.
   test(isTestingGet, "Int16", 0, 256, true);
+  test(isTestingGet, "Int16", undefined, 256, true);
   test(isTestingGet, "Int16", 5, 26213, true);
   test(isTestingGet, "Int16", 9, -32127, true);
   test(isTestingGet, "Int16", 14, -2, true);

   // Big endian.
   test(isTestingGet, "Int16", 0, 1);
+  test(isTestingGet, "Int16", undefined, 1);
   test(isTestingGet, "Int16", 5, 25958);
   test(isTestingGet, "Int16", 9, -32382);
   test(isTestingGet, "Int16", 14, -257);

   // Little endian.
   test(isTestingGet, "Uint16", 0, 256, true);
+  test(isTestingGet, "Uint16", undefined, 256, true);
   test(isTestingGet, "Uint16", 5, 26213, true);
   test(isTestingGet, "Uint16", 9, 33409, true);
   test(isTestingGet, "Uint16", 14, 65534, true);

   // Big endian.
   test(isTestingGet, "Uint16", 0, 1);
+  test(isTestingGet, "Uint16", undefined, 1);
   test(isTestingGet, "Uint16", 5, 25958);
   test(isTestingGet, "Uint16", 9, 33154);
   test(isTestingGet, "Uint16", 14, 65279);

   // Little endian.
   test(isTestingGet, "Int32", 0, 50462976, true);
+  test(isTestingGet, "Int32", undefined, 50462976, true);
   test(isTestingGet, "Int32", 3, 1717920771, true);
   test(isTestingGet, "Int32", 6, -2122291354, true);
   test(isTestingGet, "Int32", 9, -58490239, true);
@@ -145,6 +152,7 @@ function runIntegerTestCases(isTestingGet, array, start, length) {

   // Big endian.
   test(isTestingGet, "Int32", 0, 66051);
+  test(isTestingGet, "Int32", undefined, 66051);
   test(isTestingGet, "Int32", 3, 56911206);
   test(isTestingGet, "Int32", 6, 1718059137);
   test(isTestingGet, "Int32", 9, -2122152964);
@@ -152,6 +160,7 @@ function runIntegerTestCases(isTestingGet, array, start, length) {

   // Little endian.
   test(isTestingGet, "Uint32", 0, 50462976, true);
+  test(isTestingGet, "Uint32", undefined, 50462976, true);
   test(isTestingGet, "Uint32", 3, 1717920771, true);
   test(isTestingGet, "Uint32", 6, 2172675942, true);
   test(isTestingGet, "Uint32", 9, 4236477057, true);
@@ -159,6 +168,7 @@ function runIntegerTestCases(isTestingGet, array, start, length) {

   // Big endian.
   test(isTestingGet, "Uint32", 0, 66051);
+  test(isTestingGet, "Uint32", undefined, 66051);
   test(isTestingGet, "Uint32", 3, 56911206);
   test(isTestingGet, "Uint32", 6, 1718059137);
   test(isTestingGet, "Uint32", 9, 2172814332);
@@ -169,6 +179,7 @@ function testFloat(isTestingGet, func, array, start, expected) {
   // Little endian.
   createDataView(array, 0, true, start);
   test(isTestingGet, func, 0, expected, true);
+  test(isTestingGet, func, undefined, expected, true);
   createDataView(array, 3, true, start);
   test(isTestingGet, func, 3, expected, true);
   createDataView(array, 7, true, start);
@@ -179,6 +190,7 @@ function testFloat(isTestingGet, func, array, start, expected) {
   // Big endian.
   createDataView(array, 0, false);
   test(isTestingGet, func, 0, expected, false);
+  test(isTestingGet, func, undefined, expected, false);
   createDataView(array, 3, false);
   test(isTestingGet, func, 3, expected, false);
   createDataView(array, 7, false);
@@ -286,8 +298,10 @@ function TestGeneralAccessors() {
   var a = new DataView(new ArrayBuffer(256));
   function CheckAccessor(name) {
     var f = a[name];
+    assertThrows(function() { f(); }, TypeError);
     f.call(a, 0, 0); // should not throw
     assertThrows(function() { f.call({}, 0, 0); }, TypeError);
+    assertThrows(function() { f.call(a); }, TypeError);
   }
   CheckAccessor("getUint8");
   CheckAccessor("setUint8");


--
--
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.


Reply via email to