Commit f6db0566 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.

CQ_INCLUDE_TRYBOTS=tryserver.v8:v8_linux_nosnap_dbg
R=yangguo@chromium.org

Committed: https://crrev.com/2160429fd458e3c095475e718c97f77ac90d906f
Cr-Commit-Position: refs/heads/master@{#33834}

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

Cr-Commit-Position: refs/heads/master@{#33881}
parent 4ff159bd
......@@ -944,10 +944,10 @@ static int FindFunctionInFrame(JavaScriptFrame* frame,
}
namespace {
Handle<Object> GetFunctionArguments(Isolate* isolate,
Handle<JSFunction> function) {
if (function->shared()->native()) return isolate->factory()->null_value();
// Find the top invocation of the function by traversing frames.
for (JavaScriptFrameIterator it(isolate); !it.done(); it.Advance()) {
JavaScriptFrame* frame = it.frame();
......@@ -986,9 +986,14 @@ Handle<Object> GetFunctionArguments(Isolate* isolate,
return isolate->factory()->null_value();
}
} // namespace
Handle<Object> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
return GetFunctionArguments(function->GetIsolate(), function);
Handle<JSObject> Accessors::FunctionGetArguments(Handle<JSFunction> function) {
Handle<Object> arguments =
GetFunctionArguments(function->GetIsolate(), function);
CHECK(arguments->IsJSObject());
return Handle<JSObject>::cast(arguments);
}
......@@ -999,7 +1004,10 @@ void Accessors::FunctionArgumentsGetter(
HandleScope scope(isolate);
Handle<JSFunction> function =
Handle<JSFunction>::cast(Utils::OpenHandle(*info.Holder()));
Handle<Object> result = GetFunctionArguments(isolate, function);
Handle<Object> result =
function->shared()->native()
? Handle<Object>::cast(isolate->factory()->null_value())
: GetFunctionArguments(isolate, function);
info.GetReturnValue().Set(Utils::ToLocal(result));
}
......
......@@ -83,7 +83,7 @@ class Accessors : public AllStatic {
// Accessor functions called directly from the runtime system.
MUST_USE_RESULT static MaybeHandle<Object> FunctionSetPrototype(
Handle<JSFunction> object, Handle<Object> value);
static Handle<Object> FunctionGetArguments(Handle<JSFunction> object);
static Handle<JSObject> FunctionGetArguments(Handle<JSFunction> object);
// Accessor infos.
static Handle<AccessorInfo> MakeModuleExport(
......
......@@ -302,8 +302,7 @@ void DebugEvaluate::ContextBuilder::MaterializeArgumentsObject(
if (maybe.FromJust()) return;
// FunctionGetArguments can't throw an exception.
Handle<JSObject> arguments =
Handle<JSObject>::cast(Accessors::FunctionGetArguments(function));
Handle<JSObject> arguments = Accessors::FunctionGetArguments(function);
Handle<String> arguments_str = isolate_->factory()->arguments_string();
JSObject::SetOwnPropertyIgnoreAttributes(target, arguments_str, arguments,
NONE)
......
......@@ -3585,7 +3585,7 @@ bool TranslatedState::GetAdaptedArguments(Handle<JSObject>* result,
// recursive functions!)
Handle<JSFunction> function =
Handle<JSFunction>::cast(frames_[frame_index].front().GetValue());
*result = Handle<JSObject>::cast(Accessors::FunctionGetArguments(function));
*result = Accessors::FunctionGetArguments(function);
return true;
} else {
TranslatedFrame* previous_frame = &(frames_[frame_index]);
......
......@@ -515,12 +515,12 @@ function ArrayPop() {
function ObservedArrayPush() {
var n = TO_LENGTH(this.length);
var m = %_ArgumentsLength();
var m = arguments.length;
try {
ObserveBeginPerformSplice(this);
for (var i = 0; i < m; i++) {
this[i+n] = %_Arguments(i);
this[i+n] = arguments[i];
}
var new_length = n + m;
this.length = new_length;
......@@ -543,7 +543,7 @@ function ArrayPush() {
var array = TO_OBJECT(this);
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
// arguments, but it would surely blow the stack to use 2**30 or more.
......@@ -555,7 +555,7 @@ function ArrayPush() {
}
for (var i = 0; i < m; i++) {
array[i+n] = %_Arguments(i);
array[i+n] = arguments[i];
}
var new_length = n + m;
......@@ -711,13 +711,13 @@ function ArrayShift() {
function ObservedArrayUnshift() {
var len = TO_LENGTH(this.length);
var num_arguments = %_ArgumentsLength();
var num_arguments = arguments.length;
try {
ObserveBeginPerformSplice(this);
SimpleMove(this, 0, 0, len, num_arguments);
for (var i = 0; i < num_arguments; i++) {
this[i] = %_Arguments(i);
this[i] = arguments[i];
}
var new_length = len + num_arguments;
this.length = new_length;
......@@ -738,7 +738,7 @@ function ArrayUnshift(arg1) { // length == 1
var array = TO_OBJECT(this);
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) &&
!%object_is_sealed(array)) {
......@@ -748,7 +748,7 @@ function ArrayUnshift(arg1) { // length == 1
}
for (var i = 0; i < num_arguments; i++) {
array[i] = %_Arguments(i);
array[i] = arguments[i];
}
var new_length = len + num_arguments;
......@@ -831,7 +831,7 @@ function ComputeSpliceDeleteCount(delete_count, num_arguments, len, start_i) {
function ObservedArraySplice(start, delete_count) {
var num_arguments = %_ArgumentsLength();
var num_arguments = arguments.length;
var len = TO_LENGTH(this.length);
var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
var del_count = ComputeSpliceDeleteCount(delete_count, num_arguments, len,
......@@ -850,9 +850,9 @@ function ObservedArraySplice(start, delete_count) {
// place of the deleted elements.
var i = start_i;
var arguments_index = 2;
var arguments_length = %_ArgumentsLength();
var arguments_length = 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;
......@@ -877,7 +877,7 @@ function ArraySplice(start, delete_count) {
if (%IsObserved(this))
return ObservedArraySplice.apply(this, arguments);
var num_arguments = %_ArgumentsLength();
var num_arguments = arguments.length;
var array = TO_OBJECT(this);
var len = TO_LENGTH(array.length);
var start_i = ComputeSpliceStartIndex(TO_INTEGER(start), len);
......@@ -913,9 +913,9 @@ function ArraySplice(start, delete_count) {
// place of the deleted elements.
var i = start_i;
var arguments_index = 2;
var arguments_length = %_ArgumentsLength();
var arguments_length = 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;
......@@ -1469,7 +1469,7 @@ function ArrayLastIndexOf(element, index) {
var length = TO_LENGTH(this.length);
return InnerArrayLastIndexOf(this, element, index, length,
%_ArgumentsLength());
arguments.length);
}
......@@ -1508,7 +1508,7 @@ function ArrayReduce(callback, current) {
var array = TO_OBJECT(this);
var length = TO_LENGTH(array.length);
return InnerArrayReduce(callback, current, array, length,
%_ArgumentsLength());
arguments.length);
}
......@@ -1548,7 +1548,7 @@ function ArrayReduceRight(callback, current) {
var array = TO_OBJECT(this);
var length = TO_LENGTH(array.length);
return InnerArrayReduceRight(callback, current, array, length,
%_ArgumentsLength());
arguments.length);
}
......@@ -1811,13 +1811,13 @@ function ArrayFrom(arrayLike, mapfn, receiver) {
// ES6, draft 05-22-14, section 22.1.2.3
function ArrayOf() {
var length = %_ArgumentsLength();
function ArrayOf(...args) {
var length = args.length;
var constructor = this;
// TODO: Implement IsConstructor (ES6 section 7.2.5)
var array = %IsConstructor(constructor) ? new constructor(length) : [];
for (var i = 0; i < length; i++) {
AddArrayElement(constructor, array, i, %_Arguments(i));
AddArrayElement(constructor, array, i, args[i]);
}
array.length = length;
return array;
......
......@@ -187,7 +187,7 @@ function JSONSerialize(key, holder, replacer, stack, indent, gap) {
function JSONStringify(value, replacer, space) {
if (%_ArgumentsLength() == 1 && !IS_PROXY(value)) {
if (arguments.length === 1 && !IS_PROXY(value)) {
return %BasicJSONStringify(value);
}
if (!IS_CALLABLE(replacer) && %is_arraylike(replacer)) {
......
......@@ -18,11 +18,11 @@ utils.Import(function(from) {
// -------------------------------------------------------------------
function SpreadArguments() {
var count = %_ArgumentsLength();
var count = arguments.length;
var args = new InternalArray();
for (var i = 0; i < count; ++i) {
var array = %_Arguments(i);
var array = arguments[i];
var length = array.length;
for (var j = 0; j < length; ++j) {
args.push(array[j]);
......
......@@ -615,7 +615,7 @@ function TypedArrayLastIndexOf(element, index) {
var length = %_TypedArrayGetLength(this);
return InnerArrayLastIndexOf(this, element, index, length,
%_ArgumentsLength());
arguments.length);
}
%FunctionSetLength(TypedArrayLastIndexOf, 1);
......@@ -679,7 +679,7 @@ function TypedArrayReduce(callback, current) {
var length = %_TypedArrayGetLength(this);
return InnerArrayReduce(callback, current, this, length,
%_ArgumentsLength());
arguments.length);
}
%FunctionSetLength(TypedArrayReduce, 1);
......@@ -690,7 +690,7 @@ function TypedArrayReduceRight(callback, current) {
var length = %_TypedArrayGetLength(this);
return InnerArrayReduceRight(callback, current, this, length,
%_ArgumentsLength());
arguments.length);
}
%FunctionSetLength(TypedArrayReduceRight, 1);
......@@ -751,10 +751,10 @@ function TypedArrayIncludes(searchElement, fromIndex) {
// ES6 draft 08-24-14, section 22.2.2.2
function TypedArrayOf() {
var length = %_ArgumentsLength();
var length = arguments.length;
var array = TypedArrayCreate(this, length);
for (var i = 0; i < length; i++) {
array[i] = %_Arguments(i);
array[i] = arguments[i];
}
return array;
}
......@@ -918,7 +918,7 @@ function DataViewGetTYPENAMEJS(offset, little_endian) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.getTYPENAME', this);
}
if (%_ArgumentsLength() < 1) throw MakeTypeError(kInvalidArgument);
if (arguments.length < 1) throw MakeTypeError(kInvalidArgument);
offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
return %DataViewGetTYPENAME(this, offset, !!little_endian);
}
......@@ -929,7 +929,7 @@ function DataViewSetTYPENAMEJS(offset, value, little_endian) {
throw MakeTypeError(kIncompatibleMethodReceiver,
'DataView.setTYPENAME', this);
}
if (%_ArgumentsLength() < 2) throw MakeTypeError(kInvalidArgument);
if (arguments.length < 2) throw MakeTypeError(kInvalidArgument);
offset = ToPositiveInteger(offset, kInvalidDataViewAccessorOffset);
%DataViewSetTYPENAME(this, offset, TO_NUMBER(value), !!little_endian);
}
......
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