Fix length of DataView and TypedArray get/set functions

Functions like DataView.prototype.getUint8 should have length 1,
and DataView.prototype.setUint8 should have length 2, as their
endianness arguments are optional. Additionally,
TypedArray.prototype.set.length should be 2. This follows the ES2015
specification, and a new test262 test tests for it. This patch
fixes the functions' lengths.

R=adamk

Review URL: https://codereview.chromium.org/1636953003

Cr-Commit-Position: refs/heads/master@{#33531}
This commit is contained in:
littledan 2016-01-26 15:55:55 -08:00 committed by Commit bot
parent 953bb416a3
commit 3f37c4462b
2 changed files with 18 additions and 0 deletions

View File

@ -460,6 +460,7 @@ function TypedArraySet(obj, offset) {
return;
}
}
%FunctionSetLength(TypedArraySet, 1);
function TypedArrayGetToStringTag() {
if (!%_IsTypedArray(this)) return;
@ -921,6 +922,7 @@ function DataViewGetTYPENAMEJS(offset, little_endian) {
offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
return %DataViewGetTYPENAME(this, offset, !!little_endian);
}
%FunctionSetLength(DataViewGetTYPENAMEJS, 1);
function DataViewSetTYPENAMEJS(offset, value, little_endian) {
if (!IS_DATAVIEW(this)) {
@ -931,6 +933,7 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) {
offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
%DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian);
}
%FunctionSetLength(DataViewSetTYPENAMEJS, 2);
endmacro
DATA_VIEW_TYPES(DATA_VIEW_GETTER_SETTER)

View File

@ -529,6 +529,8 @@ function TestTypedArraySet() {
assertThrows(function() { a.set(0); }, TypeError);
assertThrows(function() { a.set(0, 1); }, TypeError);
assertEquals(1, a.set.length);
}
TestTypedArraySet();
@ -693,6 +695,19 @@ function TestDataViewPropertyTypeChecks() {
CheckProperty("buffer");
CheckProperty("byteOffset");
CheckProperty("byteLength");
function CheckGetSetLength(name) {
assertEquals(1, DataView.prototype["get" + name].length);
assertEquals(2, DataView.prototype["set" + name].length);
}
CheckGetSetLength("Int8");
CheckGetSetLength("Uint8");
CheckGetSetLength("Int16");
CheckGetSetLength("Uint16");
CheckGetSetLength("Int32");
CheckGetSetLength("Uint32");
CheckGetSetLength("Float32");
CheckGetSetLength("Float64");
}