Index: src/js/typedarray.js |
diff --git a/src/js/typedarray.js b/src/js/typedarray.js |
index 2fa21455040037b92c261b5a1b7236697e880727..ac4e842be2d81481f82a7a9be410a9ced4272566 100644 |
--- a/src/js/typedarray.js |
+++ b/src/js/typedarray.js |
@@ -46,7 +46,6 @@ var MinSimple; |
var PackedArrayReverse; |
var SpeciesConstructor; |
var ToPositiveInteger; |
-var ToIndex; |
var iteratorSymbol = utils.ImportNow("iterator_symbol"); |
var speciesSymbol = utils.ImportNow("species_symbol"); |
var toStringTagSymbol = utils.ImportNow("to_string_tag_symbol"); |
@@ -100,7 +99,6 @@ utils.Import(function(from) { |
PackedArrayReverse = from.PackedArrayReverse; |
SpeciesConstructor = from.SpeciesConstructor; |
ToPositiveInteger = from.ToPositiveInteger; |
- ToIndex = from.ToIndex; |
}); |
// --------------- Typed Arrays --------------------- |
@@ -145,15 +143,10 @@ function TypedArraySpeciesCreate(exemplar, arg0, arg1, arg2, conservative) { |
macro TYPED_ARRAY_CONSTRUCTOR(ARRAY_ID, NAME, ELEMENT_SIZE) |
function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
if (!IS_UNDEFINED(byteOffset)) { |
- byteOffset = ToIndex(byteOffset, kInvalidTypedArrayLength); |
+ byteOffset = ToPositiveInteger(byteOffset, kInvalidTypedArrayLength); |
} |
if (!IS_UNDEFINED(length)) { |
- length = ToIndex(length, kInvalidTypedArrayLength); |
- } |
- if (length > %_MaxSmi()) { |
- // Note: this is not per spec, but rather a constraint of our current |
- // representation (which uses smi's). |
- throw MakeRangeError(kInvalidTypedArrayLength); |
+ length = ToPositiveInteger(length, kInvalidTypedArrayLength); |
} |
var bufferByteLength = %_ArrayBufferGetByteLength(buffer); |
@@ -167,35 +160,35 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) { |
throw MakeRangeError(kInvalidTypedArrayAlignment, |
"start offset", "NAME", ELEMENT_SIZE); |
} |
+ if (offset > bufferByteLength) { |
+ throw MakeRangeError(kInvalidTypedArrayOffset); |
+ } |
} |
var newByteLength; |
+ var newLength; |
if (IS_UNDEFINED(length)) { |
if (bufferByteLength % ELEMENT_SIZE !== 0) { |
throw MakeRangeError(kInvalidTypedArrayAlignment, |
"byte length", "NAME", ELEMENT_SIZE); |
} |
newByteLength = bufferByteLength - offset; |
- if (newByteLength < 0) { |
- throw MakeRangeError(kInvalidTypedArrayAlignment, |
- "byte length", "NAME", ELEMENT_SIZE); |
- } |
+ newLength = newByteLength / ELEMENT_SIZE; |
} else { |
- newByteLength = length * ELEMENT_SIZE; |
- if (offset + newByteLength > bufferByteLength) { |
- throw MakeRangeError(kInvalidTypedArrayAlignment, |
- "byte length", "NAME", ELEMENT_SIZE); |
- } |
+ var newLength = length; |
+ newByteLength = newLength * ELEMENT_SIZE; |
+ } |
+ if ((offset + newByteLength > bufferByteLength) |
+ || (newLength > %_MaxSmi())) { |
+ throw MakeRangeError(kInvalidTypedArrayLength); |
} |
%_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength, true); |
} |
function NAMEConstructByLength(obj, length) { |
var l = IS_UNDEFINED(length) ? |
- 0 : ToIndex(length, kInvalidTypedArrayLength); |
- if (length > %_MaxSmi()) { |
- // Note: this is not per spec, but rather a constraint of our current |
- // representation (which uses smi's). |
+ 0 : ToPositiveInteger(length, kInvalidTypedArrayLength); |
+ if (l > %_MaxSmi()) { |
throw MakeRangeError(kInvalidTypedArrayLength); |
} |
var byteLength = l * ELEMENT_SIZE; |
@@ -872,7 +865,8 @@ function DataViewGetTYPENAMEJS(offset, little_endian) { |
throw MakeTypeError(kIncompatibleMethodReceiver, |
'DataView.getTYPENAME', this); |
} |
- offset = IS_UNDEFINED(offset) ? 0 : ToIndex(offset, kInvalidDataViewAccessorOffset); |
+ if (arguments.length < 1) throw MakeTypeError(kInvalidArgument); |
+ offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
return %DataViewGetTYPENAME(this, offset, !!little_endian); |
} |
%FunctionSetLength(DataViewGetTYPENAMEJS, 1); |
@@ -882,7 +876,8 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) { |
throw MakeTypeError(kIncompatibleMethodReceiver, |
'DataView.setTYPENAME', this); |
} |
- offset = IS_UNDEFINED(offset) ? 0 : ToIndex(offset, kInvalidDataViewAccessorOffset); |
+ if (arguments.length < 2) throw MakeTypeError(kInvalidArgument); |
+ offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); |
%DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); |
} |
%FunctionSetLength(DataViewSetTYPENAMEJS, 2); |