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

Unified Diff: src/typedarray.js

Issue 17572009: Update typed arrays behavior to match ES6 rev 15. Remove TO_POSITIVE_INTEGER and throw on negative … (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 6 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
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index 0e0b7fec63187c14edee2d32310f51f2cbd99df4..eb2d2d196c039c28d05cfec827f5edb2f21a427d 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -37,7 +37,10 @@
function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) {
function ConstructByArrayBuffer(obj, buffer, byteOffset, length) {
- var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_POSITIVE_INTEGER(byteOffset);
+ var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_INTEGER(byteOffset);
rossberg 2013/06/24 12:36:03 Same here
+ if (offset < 0) {
+ throw MakeRangeError("invalid_typed_array_length");
+ }
if (offset % elementSize !== 0) {
throw MakeRangeError("invalid_typed_array_alignment",
@@ -58,7 +61,10 @@ function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) {
newByteLength = bufferByteLength - offset;
newLength = newByteLength / elementSize;
} else {
- var newLength = TO_POSITIVE_INTEGER(length);
+ var newLength = TO_INTEGER(length);
+ if (newLength < 0) {
+ throw MakeRangeError("invalid_typed_array_length");
+ }
newByteLength = newLength * elementSize;
}
if (offset + newByteLength > bufferByteLength) {
@@ -68,7 +74,10 @@ function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) {
}
function ConstructByLength(obj, length) {
- var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length);
+ var l = TO_INTEGER(length);
+ if (l < 0) {
+ throw MakeRangeError("invalid_typed_array_length");
+ }
var byteLength = l * elementSize;
var buffer = new global.ArrayBuffer(byteLength);
%TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength);
@@ -76,7 +85,10 @@ function CreateTypedArrayConstructor(name, elementSize, arrayId, constructor) {
function ConstructByArrayLike(obj, arrayLike) {
var length = arrayLike.length;
- var l = IS_UNDEFINED(length) ? 0 : TO_POSITIVE_INTEGER(length);
+ var l = TO_INTEGER(length);
+ if (l < 0) {
+ throw MakeRangeError("invalid_typed_array_length");
+ }
var byteLength = l * elementSize;
var buffer = new $ArrayBuffer(byteLength);
%TypedArrayInitialize(obj, arrayId, buffer, 0, byteLength);
@@ -146,7 +158,10 @@ function CreateSubArray(elementSize, constructor) {
}
function TypedArraySet(obj, offset) {
rossberg 2013/06/24 12:36:03 and here
- var intOffset = IS_UNDEFINED(offset) ? 0 : TO_POSITIVE_INTEGER(offset);
+ var intOffset = IS_UNDEFINED(offset) ? 0 : TO_INTEGER(offset);
+ if (intOffset < 0) {
+ throw MakeTypeError("typed_array_set_negative_offset");
+ }
if (%TypedArraySetFastCases(this, obj, intOffset))
return;
@@ -209,13 +224,13 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
throw MakeTypeError('data_view_not_array_buffer', []);
}
var bufferByteLength = %ArrayBufferGetByteLength(buffer);
- var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_POSITIVE_INTEGER(byteOffset);
- if (offset > bufferByteLength) {
+ var offset = IS_UNDEFINED(byteOffset) ? 0 : TO_INTEGER(byteOffset);
rossberg 2013/06/24 12:36:03 and here
+ if (offset < 0 || offset > bufferByteLength) {
throw MakeRangeError('invalid_data_view_offset', []);
}
var length = IS_UNDEFINED(byteLength) ?
- bufferByteLength - offset : TO_POSITIVE_INTEGER(byteLength);
- if (offset + length > bufferByteLength) {
+ bufferByteLength - offset : TO_INTEGER(byteLength);
+ if (length < 0 || offset + length > bufferByteLength) {
throw new MakeRangeError('invalid_data_view_length');
}
%DataViewInitialize(this, buffer, offset, length);
@@ -253,7 +268,11 @@ function DataViewGetInt8(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getInt8', this]);
}
- return %DataViewGetInt8(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetInt8(this, offset, !!little_endian);
}
function DataViewSetInt8(offset, value, little_endian) {
@@ -261,8 +280,12 @@ function DataViewSetInt8(offset, value, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.setInt8', this]);
}
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
%DataViewSetInt8(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}
@@ -272,7 +295,11 @@ function DataViewGetUint8(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getUint8', this]);
}
- return %DataViewGetUint8(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetUint8(this, offset, !!little_endian);
}
function DataViewSetUint8(offset, value, little_endian) {
@@ -280,8 +307,12 @@ function DataViewSetUint8(offset, value, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.setUint8', this]);
}
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
%DataViewSetUint8(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}
@@ -291,7 +322,11 @@ function DataViewGetInt16(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getInt16', this]);
}
- return %DataViewGetInt16(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetInt16(this, offset, !!little_endian);
}
function DataViewSetInt16(offset, value, little_endian) {
@@ -299,8 +334,12 @@ function DataViewSetInt16(offset, value, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.setInt16', this]);
}
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
%DataViewSetInt16(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}
@@ -310,7 +349,11 @@ function DataViewGetUint16(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getUint16', this]);
}
- return %DataViewGetUint16(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetUint16(this, offset, !!little_endian);
}
function DataViewSetUint16(offset, value, little_endian) {
@@ -318,8 +361,12 @@ function DataViewSetUint16(offset, value, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.setUint16', this]);
}
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
%DataViewSetUint16(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}
@@ -329,7 +376,11 @@ function DataViewGetInt32(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getInt32', this]);
}
- return %DataViewGetInt32(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetInt32(this, offset, !!little_endian);
}
function DataViewSetInt32(offset, value, little_endian) {
@@ -337,8 +388,12 @@ function DataViewSetInt32(offset, value, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.setInt32', this]);
}
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
%DataViewSetInt32(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}
@@ -348,7 +403,11 @@ function DataViewGetUint32(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getUint32', this]);
}
- return %DataViewGetUint32(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetUint32(this, offset, !!little_endian);
}
function DataViewSetUint32(offset, value, little_endian) {
@@ -356,8 +415,12 @@ function DataViewSetUint32(offset, value, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.setUint32', this]);
}
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
%DataViewSetUint32(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}
@@ -367,7 +430,11 @@ function DataViewGetFloat32(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getFloat32', this]);
}
- return %DataViewGetFloat32(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetFloat32(this, offset, !!little_endian);
}
function DataViewSetFloat32(offset, value, little_endian) {
@@ -375,8 +442,12 @@ function DataViewSetFloat32(offset, value, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.setFloat32', this]);
}
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
%DataViewSetFloat32(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}
@@ -386,7 +457,11 @@ function DataViewGetFloat64(offset, little_endian) {
throw MakeTypeError('incompatible_method_reciever',
['DataView.getFloat64', this]);
}
- return %DataViewGetFloat64(this, TO_POSITIVE_INTEGER(offset), !!little_endian);
+ offset = TO_INTEGER(offset);
+ if (offset < 0) {
+ throw MakeRangeError("invalid_data_view_accessor_offset");
+ }
+ return %DataViewGetFloat64(this, offset, !!little_endian);
}
function DataViewSetFloat64(offset, value, little_endian) {
@@ -394,8 +469,12 @@ 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");
+ }
%DataViewSetFloat64(this,
- TO_POSITIVE_INTEGER(offset),
+ offset,
TO_NUMBER_INLINE(value),
!!little_endian);
}

Powered by Google App Engine
This is Rietveld 408576698