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

Unified Diff: src/js/typedarray.js

Issue 2247073004: Reland of Amend DataView, ArrayBuffer, and TypedArray methods to use ToIndex. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Correct messages Created 4 years, 4 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/js/runtime.js ('k') | src/messages.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/js/typedarray.js
diff --git a/src/js/typedarray.js b/src/js/typedarray.js
index 46e238789d7b6dc2d78e71fcab1b1bc8f69e24fe..380f68be0538adf10dc319223033b37d279e8257 100644
--- a/src/js/typedarray.js
+++ b/src/js/typedarray.js
@@ -41,6 +41,7 @@ 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");
@@ -89,6 +90,7 @@ utils.Import(function(from) {
PackedArrayReverse = from.PackedArrayReverse;
SpeciesConstructor = from.SpeciesConstructor;
ToPositiveInteger = from.ToPositiveInteger;
+ ToIndex = from.ToIndex;
});
// --------------- Typed Arrays ---------------------
@@ -133,10 +135,15 @@ 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 = ToPositiveInteger(byteOffset, kInvalidTypedArrayLength);
+ byteOffset = ToIndex(byteOffset, kInvalidTypedArrayLength);
}
if (!IS_UNDEFINED(length)) {
- length = ToPositiveInteger(length, kInvalidTypedArrayLength);
+ 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 %make_range_error(kInvalidTypedArrayLength);
}
var bufferByteLength = %_ArrayBufferGetByteLength(buffer);
@@ -150,35 +157,34 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
throw %make_range_error(kInvalidTypedArrayAlignment,
"start offset", "NAME", ELEMENT_SIZE);
}
- if (offset > bufferByteLength) {
- throw %make_range_error(kInvalidTypedArrayOffset);
- }
}
var newByteLength;
- var newLength;
if (IS_UNDEFINED(length)) {
if (bufferByteLength % ELEMENT_SIZE !== 0) {
throw %make_range_error(kInvalidTypedArrayAlignment,
"byte length", "NAME", ELEMENT_SIZE);
}
newByteLength = bufferByteLength - offset;
- newLength = newByteLength / ELEMENT_SIZE;
+ if (newByteLength < 0) {
+ throw %make_range_error(kInvalidTypedArrayAlignment,
+ "byte length", "NAME", ELEMENT_SIZE);
+ }
} else {
- var newLength = length;
- newByteLength = newLength * ELEMENT_SIZE;
- }
- if ((offset + newByteLength > bufferByteLength)
- || (newLength > %_MaxSmi())) {
- throw %make_range_error(kInvalidTypedArrayLength);
+ newByteLength = length * ELEMENT_SIZE;
+ if (offset + newByteLength > bufferByteLength) {
+ throw %make_range_error(kInvalidTypedArrayLength);
+ }
}
%_TypedArrayInitialize(obj, ARRAY_ID, buffer, offset, newByteLength, true);
}
function NAMEConstructByLength(obj, length) {
var l = IS_UNDEFINED(length) ?
- 0 : ToPositiveInteger(length, kInvalidTypedArrayLength);
- if (l > %_MaxSmi()) {
+ 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).
throw %make_range_error(kInvalidTypedArrayLength);
}
var byteLength = l * ELEMENT_SIZE;
@@ -930,8 +936,7 @@ function DataViewGetTYPENAMEJS(offset, little_endian) {
throw %make_type_error(kIncompatibleMethodReceiver,
'DataView.getTYPENAME', this);
}
- if (arguments.length < 1) throw %make_type_error(kInvalidArgument);
- offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
+ offset = IS_UNDEFINED(offset) ? 0 : ToIndex(offset, kInvalidDataViewAccessorOffset);
return %DataViewGetTYPENAME(this, offset, !!little_endian);
}
%FunctionSetLength(DataViewGetTYPENAMEJS, 1);
@@ -941,8 +946,7 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) {
throw %make_type_error(kIncompatibleMethodReceiver,
'DataView.setTYPENAME', this);
}
- if (arguments.length < 2) throw %make_type_error(kInvalidArgument);
- offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
+ offset = IS_UNDEFINED(offset) ? 0 : ToIndex(offset, kInvalidDataViewAccessorOffset);
%DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian);
}
%FunctionSetLength(DataViewSetTYPENAMEJS, 2);
« no previous file with comments | « src/js/runtime.js ('k') | src/messages.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698