Commit 2160429f authored by bmeurer's avatar bmeurer Committed by Commit bot

[builtins] Remove bunch of uses of %_Arguments and %_ArgumentsLength.

There are a bunch of places in our builtins where we use %_Arguments and
%_ArgumentsLength for no good reason, as arguments object and/or rest
parameter is as good and performant in these cases. Now the only uses
of %_Arguments and %_ArgumentsLength left are in string.js, which
requires dedicated investigation.

R=yangguo@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33834}
parent 00f7d1f5
...@@ -515,12 +515,12 @@ function ArrayPop() { ...@@ -515,12 +515,12 @@ function ArrayPop() {
function ObservedArrayPush() { function ObservedArrayPush() {
var n = TO_LENGTH(this.length); var n = TO_LENGTH(this.length);
var m = %_ArgumentsLength(); var m = arguments.length;
try { try {
ObserveBeginPerformSplice(this); ObserveBeginPerformSplice(this);
for (var i = 0; i < m; i++) { for (var i = 0; i < m; i++) {
this[i+n] = %_Arguments(i); this[i+n] = arguments[i];
} }
var new_length = n + m; var new_length = n + m;
this.length = new_length; this.length = new_length;
...@@ -543,7 +543,7 @@ function ArrayPush() { ...@@ -543,7 +543,7 @@ function ArrayPush() {
var array = TO_OBJECT(this); var array = TO_OBJECT(this);
var n = TO_LENGTH(array.length); var n = TO_LENGTH(array.length);
var m = %_ArgumentsLength(); var m = arguments.length;
// It appears that there is no enforced, absolute limit on the number of // It appears that there is no enforced, absolute limit on the number of
// arguments, but it would surely blow the stack to use 2**30 or more. // arguments, but it would surely blow the stack to use 2**30 or more.
...@@ -555,7 +555,7 @@ function ArrayPush() { ...@@ -555,7 +555,7 @@ function ArrayPush() {
} }
for (var i = 0; i < m; i++) { for (var i = 0; i < m; i++) {
array[i+n] = %_Arguments(i); array[i+n] = arguments[i];
} }
var new_length = n + m; var new_length = n + m;
...@@ -711,13 +711,13 @@ function ArrayShift() { ...@@ -711,13 +711,13 @@ function ArrayShift() {
function ObservedArrayUnshift() { function ObservedArrayUnshift() {
var len = TO_LENGTH(this.length); var len = TO_LENGTH(this.length);
var num_arguments = %_ArgumentsLength(); var num_arguments = arguments.length;
try { try {
ObserveBeginPerformSplice(this); ObserveBeginPerformSplice(this);
SimpleMove(this, 0, 0, len, num_arguments); SimpleMove(this, 0, 0, len, num_arguments);
for (var i = 0; i < num_arguments; i++) { for (var i = 0; i < num_arguments; i++) {
this[i] = %_Arguments(i); this[i] = arguments[i];
} }
var new_length = len + num_arguments; var new_length = len + num_arguments;
this.length = new_length; this.length = new_length;
...@@ -738,7 +738,7 @@ function ArrayUnshift(arg1) { // length == 1 ...@@ -738,7 +738,7 @@ function ArrayUnshift(arg1) { // length == 1
var array = TO_OBJECT(this); var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length); var len = TO_LENGTH(array.length);
var num_arguments = %_ArgumentsLength(); var num_arguments = arguments.length;
if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) && if (len > 0 && UseSparseVariant(array, len, IS_ARRAY(array), len) &&
!%object_is_sealed(array)) { !%object_is_sealed(array)) {
...@@ -748,7 +748,7 @@ function ArrayUnshift(arg1) { // length == 1 ...@@ -748,7 +748,7 @@ function ArrayUnshift(arg1) { // length == 1
} }
for (var i = 0; i < num_arguments; i++) { for (var i = 0; i < num_arguments; i++) {
array[i] = %_Arguments(i); array[i] = arguments[i];
} }
var new_length = len + num_arguments; var new_length = len + num_arguments;
...@@ -831,7 +831,7 @@ function ComputeSpliceDeleteCount(delete_count, num_arguments, len, start_i) { ...@@ -831,7 +831,7 @@ function ComputeSpliceDeleteCount(delete_count, num_arguments, len, start_i) {
function ObservedArraySplice(start, delete_count) { function ObservedArraySplice(start, delete_count) {
var num_arguments = %_ArgumentsLength(); var num_arguments = arguments.length;
var len = TO_LENGTH(this.length); var len = TO_LENGTH(this.length);
var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len, var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
...@@ -850,9 +850,9 @@ function ObservedArraySplice(start, delete_count) { ...@@ -850,9 +850,9 @@ function ObservedArraySplice(start, delete_count) {
// place of the deleted elements. // place of the deleted elements.
var i = start_i; var i = start_i;
var arguments_index = 2; var arguments_index = 2;
var arguments_length = %_ArgumentsLength(); var arguments_length = arguments.length;
while (arguments_index < arguments_length) { while (arguments_index < arguments_length) {
this[i++] = %_Arguments(arguments_index++); this[i++] = arguments[arguments_index++];
} }
this.length = len - del_count + num_elements_to_add; this.length = len - del_count + num_elements_to_add;
...@@ -877,7 +877,7 @@ function ArraySplice(start, delete_count) { ...@@ -877,7 +877,7 @@ function ArraySplice(start, delete_count) {
if (%IsObserved(this)) if (%IsObserved(this))
return ObservedArraySplice.apply(this, arguments); return ObservedArraySplice.apply(this, arguments);
var num_arguments = %_ArgumentsLength(); var num_arguments = arguments.length;
var array = TO_OBJECT(this); var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length); var len = TO_LENGTH(array.length);
var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len); var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
...@@ -913,9 +913,9 @@ function ArraySplice(start, delete_count) { ...@@ -913,9 +913,9 @@ function ArraySplice(start, delete_count) {
// place of the deleted elements. // place of the deleted elements.
var i = start_i; var i = start_i;
var arguments_index = 2; var arguments_index = 2;
var arguments_length = %_ArgumentsLength(); var arguments_length = arguments.length;
while (arguments_index < arguments_length) { while (arguments_index < arguments_length) {
array[i++] = %_Arguments(arguments_index++); array[i++] = arguments[arguments_index++];
} }
array.length = len - del_count + num_elements_to_add; array.length = len - del_count + num_elements_to_add;
...@@ -1469,7 +1469,7 @@ function ArrayLastIndexOf(element, index) { ...@@ -1469,7 +1469,7 @@ function ArrayLastIndexOf(element, index) {
var length = TO_LENGTH(this.length); var length = TO_LENGTH(this.length);
return InnerArrayLastIndexOf(this, element, index, length, return InnerArrayLastIndexOf(this, element, index, length,
%_ArgumentsLength()); arguments.length);
} }
...@@ -1508,7 +1508,7 @@ function ArrayReduce(callback, current) { ...@@ -1508,7 +1508,7 @@ function ArrayReduce(callback, current) {
var array = TO_OBJECT(this); var array = TO_OBJECT(this);
var length = TO_LENGTH(array.length); var length = TO_LENGTH(array.length);
return InnerArrayReduce(callback, current, array, length, return InnerArrayReduce(callback, current, array, length,
%_ArgumentsLength()); arguments.length);
} }
...@@ -1548,7 +1548,7 @@ function ArrayReduceRight(callback, current) { ...@@ -1548,7 +1548,7 @@ function ArrayReduceRight(callback, current) {
var array = TO_OBJECT(this); var array = TO_OBJECT(this);
var length = TO_LENGTH(array.length); var length = TO_LENGTH(array.length);
return InnerArrayReduceRight(callback, current, array, length, return InnerArrayReduceRight(callback, current, array, length,
%_ArgumentsLength()); arguments.length);
} }
...@@ -1822,13 +1822,13 @@ function ArrayFrom(arrayLike, mapfn, receiver) { ...@@ -1822,13 +1822,13 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
// ES6, draft 05-22-14, section 22.1.2.3 // ES6, draft 05-22-14, section 22.1.2.3
function ArrayOf() { function ArrayOf(...args) {
var length = %_ArgumentsLength(); var length = args.length;
var constructor = this; var constructor = this;
// TODO: Implement IsConstructor (ES6 section 7.2.5) // TODO: Implement IsConstructor (ES6 section 7.2.5)
var array = %IsConstructor(constructor) ? new constructor(length) : []; var array = %IsConstructor(constructor) ? new constructor(length) : [];
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
AddArrayElement(constructor, array, i, %_Arguments(i)); AddArrayElement(constructor, array, i, args[i]);
} }
array.length = length; array.length = length;
return array; return array;
......
...@@ -187,7 +187,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) { ...@@ -187,7 +187,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
function JSONStringify(value, replacer, space) { function JSONStringify(value, replacer, space) {
if (%_ArgumentsLength() == 1 && !IS_PROXY(value)) { if (arguments.length === 1 && !IS_PROXY(value)) {
return %BasicJSONStringify(value); return %BasicJSONStringify(value);
} }
if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) { if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) {
......
...@@ -18,11 +18,11 @@ utils.Import(function(from) { ...@@ -18,11 +18,11 @@ utils.Import(function(from) {
// ------------------------------------------------------------------- // -------------------------------------------------------------------
function SpreadArguments() { function SpreadArguments() {
var count = %_ArgumentsLength(); var count = arguments.length;
var args = new InternalArray(); var args = new InternalArray();
for (var i = 0; i < count; ++i) { for (var i = 0; i < count; ++i) {
var array = %_Arguments(i); var array = arguments[i];
var length = array.length; var length = array.length;
for (var j = 0; j < length; ++j) { for (var j = 0; j < length; ++j) {
args.push(array[j]); args.push(array[j]);
......
...@@ -615,7 +615,7 @@ function TypedArrayLastIndexOf(element, index) { ...@@ -615,7 +615,7 @@ function TypedArrayLastIndexOf(element, index) {
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
return InnerArrayLastIndexOf(this, element, index, length, return InnerArrayLastIndexOf(this, element, index, length,
%_ArgumentsLength()); arguments.length);
} }
%FunctionSetLength(TypedArrayLastIndexOf, 1); %FunctionSetLength(TypedArrayLastIndexOf, 1);
...@@ -679,7 +679,7 @@ function TypedArrayReduce(callback, current) { ...@@ -679,7 +679,7 @@ function TypedArrayReduce(callback, current) {
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
return InnerArrayReduce(callback, current, this, length, return InnerArrayReduce(callback, current, this, length,
%_ArgumentsLength()); arguments.length);
} }
%FunctionSetLength(TypedArrayReduce, 1); %FunctionSetLength(TypedArrayReduce, 1);
...@@ -690,7 +690,7 @@ function TypedArrayReduceRight(callback, current) { ...@@ -690,7 +690,7 @@ function TypedArrayReduceRight(callback, current) {
var length = %_TypedArrayGetLength(this); var length = %_TypedArrayGetLength(this);
return InnerArrayReduceRight(callback, current, this, length, return InnerArrayReduceRight(callback, current, this, length,
%_ArgumentsLength()); arguments.length);
} }
%FunctionSetLength(TypedArrayReduceRight, 1); %FunctionSetLength(TypedArrayReduceRight, 1);
...@@ -751,10 +751,10 @@ function TypedArrayIncludes(searchElement, fromIndex) { ...@@ -751,10 +751,10 @@ function TypedArrayIncludes(searchElement, fromIndex) {
// ES6 draft 08-24-14, section 22.2.2.2 // ES6 draft 08-24-14, section 22.2.2.2
function TypedArrayOf() { function TypedArrayOf() {
var length = %_ArgumentsLength(); var length = arguments.length;
var array = TypedArrayCreate(this, length); var array = TypedArrayCreate(this, length);
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
array[i] = %_Arguments(i); array[i] = arguments[i];
} }
return array; return array;
} }
...@@ -918,9 +918,10 @@ function DataViewGetTYPENAMEJS(offset, little_endian) { ...@@ -918,9 +918,10 @@ function DataViewGetTYPENAMEJS(offset, little_endian) {
throw MakeTypeError(kIncompatibleMethodReceiver, throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.getTYPENAME', this); 'DataView.getTYPENAME', this);
} }
if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument); if (arguments.length < 1) throw MakeTypeError(kInvalidArgument);
offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
return %DataViewGetTYPENAME(this, offset, !!little_endian); little_endian = TO_BOOLEAN(little_endian);
return %DataViewGetTYPENAME(this, offset, little_endian);
} }
%FunctionSetLength(DataViewGetTYPENAMEJS, 1); %FunctionSetLength(DataViewGetTYPENAMEJS, 1);
...@@ -929,9 +930,10 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) { ...@@ -929,9 +930,10 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) {
throw MakeTypeError(kIncompatibleMethodReceiver, throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.setTYPENAME', this); 'DataView.setTYPENAME', this);
} }
if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument); if (arguments.length < 2) throw MakeTypeError(kInvalidArgument);
offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset); offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
%DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian); little_endian = TO_BOOLEAN(little_endian);
%DataViewSetTYPENAME(this, offset, TO_NUMBER(value), little_endian);
} }
%FunctionSetLength(DataViewSetTYPENAMEJS, 2); %FunctionSetLength(DataViewSetTYPENAMEJS, 2);
endmacro endmacro
......
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