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

Unified Diff: src/typedarray.js

Issue 199523006: Revert "Apply numeric casts correctly in typed arrays and related code." (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 9 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 | « src/runtime.cc ('k') | test/mjsunit/regress/regress-353004.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/typedarray.js
diff --git a/src/typedarray.js b/src/typedarray.js
index cba8993c236227cb81bbc66eeb27c5c70aeaa005..88fbb34245f3223001897c1108b68b926fd7f761 100644
--- a/src/typedarray.js
+++ b/src/typedarray.js
@@ -49,20 +49,12 @@ endmacro
macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
- if (!IS_UNDEFINED(byteOffset)) {
- byteOffset =
- ToPositiveInteger(byteOffset, "invalid_typed_array_length");
- }
- if (!IS_UNDEFINED(length)) {
- length = ToPositiveInteger(length, "invalid_typed_array_length");
- }
-
var bufferByteLength = %ArrayBufferGetByteLength(buffer);
var offset;
if (IS_UNDEFINED(byteOffset)) {
offset = 0;
} else {
- offset = byteOffset;
+ offset = ToPositiveInteger(byteOffset, "invalid_typed_array_length");
if (offset % ELEMENT_SIZE !== 0) {
throw MakeRangeError("invalid_typed_array_alignment",
@@ -83,7 +75,7 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
newByteLength = bufferByteLength - offset;
newLength = newByteLength / ELEMENT_SIZE;
} else {
- var newLength = length;
+ var newLength = ToPositiveInteger(length, "invalid_typed_array_length");
newByteLength = newLength * ELEMENT_SIZE;
}
if ((offset + newByteLength > bufferByteLength)
@@ -107,7 +99,6 @@ macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE)
function NAMEConstructByArrayLike(obj, arrayLike) {
var length = arrayLike.length;
var l = ToPositiveInteger(length, "invalid_typed_array_length");
-
if (l > %MaxSmi()) {
throw MakeRangeError("invalid_typed_array_length");
}
@@ -157,19 +148,15 @@ function TypedArrayGetLength() {
function CreateSubArray(elementSize, constructor) {
return function(begin, end) {
- var beginInt = TO_INTEGER(begin);
- if (!IS_UNDEFINED(end)) {
- end = TO_INTEGER(end);
- }
-
var srcLength = %TypedArrayGetLength(this);
+ var beginInt = TO_INTEGER(begin);
if (beginInt < 0) {
beginInt = MathMax(0, srcLength + beginInt);
} else {
beginInt = MathMin(srcLength, beginInt);
}
- var endInt = IS_UNDEFINED(end) ? srcLength : end;
+ var endInt = IS_UNDEFINED(end) ? srcLength : TO_INTEGER(end);
if (endInt < 0) {
endInt = MathMax(0, srcLength + endInt);
} else {
@@ -330,23 +317,14 @@ function DataViewConstructor(buffer, byteOffset, byteLength) { // length = 3
if (!IS_ARRAYBUFFER(buffer)) {
throw MakeTypeError('data_view_not_array_buffer', []);
}
- if (!IS_UNDEFINED(byteOffset)) {
- byteOffset = ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
- }
- if (!IS_UNDEFINED(byteLength)) {
- byteLength = TO_INTEGER(byteLength);
- }
-
var bufferByteLength = %ArrayBufferGetByteLength(buffer);
-
- var offset = IS_UNDEFINED(byteOffset) ? 0 : byteOffset;
+ var offset = IS_UNDEFINED(byteOffset) ?
+ 0 : ToPositiveInteger(byteOffset, 'invalid_data_view_offset');
if (offset > bufferByteLength) {
throw MakeRangeError('invalid_data_view_offset');
}
-
- var length = IS_UNDEFINED(byteLength)
- ? bufferByteLength - offset
- : byteLength;
+ var length = IS_UNDEFINED(byteLength) ?
+ bufferByteLength - offset : TO_INTEGER(byteLength);
if (length < 0 || offset + length > bufferByteLength) {
throw new MakeRangeError('invalid_data_view_length');
}
« no previous file with comments | « src/runtime.cc ('k') | test/mjsunit/regress/regress-353004.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698