Commit 3f37c446 authored by littledan's avatar littledan Committed by Commit bot

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}
parent 953bb416
......@@ -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)
......
......@@ -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");
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment