Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Merged: [turbofan] Fix return value of Array.prototype.push.
Browse files Browse the repository at this point in the history
Revision: 8584442

BUG=chromium:656037
LOG=N
NOTRY=true
NOPRESUBMIT=true
NOTREECHECKS=true
TBR=jarin@chromium.org

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

Cr-Commit-Position: refs/branch-heads/5.4@{#65}
Cr-Branched-From: 5ce2827-refs/heads/5.4.500@{#2}
Cr-Branched-From: ad07b49-refs/heads/master@{#38841}
  • Loading branch information
bmeurer committed Oct 19, 2016
1 parent 93fbfa2 commit 0112cbb
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/compiler/js-builtin-reducer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,10 @@ Reduction JSBuiltinReducer::ReduceArrayPush(Node* node) {
AccessBuilder::ForFixedArrayElement(receiver_map->elements_kind())),
elements, length, value, effect, control);

// Return the new length of the {receiver}.
value = graph()->NewNode(simplified()->NumberAdd(), length,
jsgraph()->OneConstant());

ReplaceWithValue(node, value, effect, control);
return Replace(value);
}
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/typer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1352,6 +1352,8 @@ Type* Typer::Visitor::JSCallFunctionTyper(Type* fun, Typer* t) {
case kArrayIndexOf:
case kArrayLastIndexOf:
return Type::Range(-1, kMaxSafeInteger, t->zone());
case kArrayPush:
return t->cache_.kPositiveSafeInteger;
// Object functions.
case kObjectHasOwnProperty:
return Type::Boolean();
Expand Down
15 changes: 15 additions & 0 deletions test/mjsunit/regress/regress-crbug-656037.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Flags: --allow-natives-syntax

function foo(a) {
return a.push(true);
}

var a = [];
assertEquals(1, foo(a));
assertEquals(2, foo(a));
%OptimizeFunctionOnNextCall(foo);
assertEquals(3, foo(a));

0 comments on commit 0112cbb

Please sign in to comment.