Skip to content

Commit 8584442

Browse files
bmeurerCommit bot
authored andcommitted
[turbofan] Fix return value of Array.prototype.push.
The inlined version of Array.prototype.push returned the value that was pushed instead of the new "length" property value. [email protected] BUG=chromium:656037 Review-Url: https://codereview.chromium.org/2425903002 Cr-Commit-Position: refs/heads/master@{#40384}
1 parent c4e7992 commit 8584442

3 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/compiler/js-builtin-reducer.cc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,10 @@ Reduction JSBuiltinReducer::ReduceArrayPush(Node* node) {
313313
AccessBuilder::ForFixedArrayElement(receiver_map->elements_kind())),
314314
elements, length, value, effect, control);
315315

316+
// Return the new length of the {receiver}.
317+
value = graph()->NewNode(simplified()->NumberAdd(), length,
318+
jsgraph()->OneConstant());
319+
316320
ReplaceWithValue(node, value, effect, control);
317321
return Replace(value);
318322
}

src/compiler/typer.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,6 +1357,8 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
13571357
case kArrayIndexOf:
13581358
case kArrayLastIndexOf:
13591359
return Type::Range(-1, kMaxSafeInteger, t->zone());
1360+
case kArrayPush:
1361+
return t->cache_.kPositiveSafeInteger;
13601362
// Object functions.
13611363
case kObjectHasOwnProperty:
13621364
return Type::Boolean();
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2016 the V8 project authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style license that can be
3+
// found in the LICENSE file.
4+
5+
// Flags: --allow-natives-syntax
6+
7+
function foo(a) {
8+
return a.push(true);
9+
}
10+
11+
var a = [];
12+
assertEquals(1, foo(a));
13+
assertEquals(2, foo(a));
14+
%OptimizeFunctionOnNextCall(foo);
15+
assertEquals(3, foo(a));

0 commit comments

Comments
 (0)