Skip to content

Commit 4ed27fc

Browse files
bmeurerCommit bot
authored andcommitted
[turbofan] Ensure that all prototypes are stable for push/pop.
When lowering Array.prototype.push/.pop to the fast inlined version, we first need to ensure that all prototypes (including the Object.prototype) are stable. [email protected] BUG=chromium:644689 Review-Url: https://codereview.chromium.org/2319533005 Cr-Commit-Position: refs/heads/master@{#39266}
1 parent 0ef20b5 commit 4ed27fc

3 files changed

Lines changed: 34 additions & 1 deletion

File tree

src/compiler/js-builtin-reducer.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,16 @@ bool CanInlineArrayResizeOperation(Handle<Map> receiver_map) {
145145
if (!receiver_map->prototype()->IsJSArray()) return false;
146146
Handle<JSArray> receiver_prototype(JSArray::cast(receiver_map->prototype()),
147147
isolate);
148+
// Ensure that all prototypes of the {receiver} are stable.
149+
for (PrototypeIterator it(isolate, receiver_prototype, kStartAtReceiver);
150+
!it.IsAtEnd(); it.Advance()) {
151+
Handle<JSReceiver> current = PrototypeIterator::GetCurrent<JSReceiver>(it);
152+
if (!current->map()->is_stable()) return false;
153+
}
148154
return receiver_map->instance_type() == JS_ARRAY_TYPE &&
149155
IsFastElementsKind(receiver_map->elements_kind()) &&
150156
!receiver_map->is_dictionary_map() && receiver_map->is_extensible() &&
151157
(!receiver_map->is_prototype_map() || receiver_map->is_stable()) &&
152-
receiver_prototype->map()->is_stable() &&
153158
isolate->IsFastArrayConstructorPrototypeChainIntact() &&
154159
isolate->IsAnyInitialArrayPrototype(receiver_prototype) &&
155160
!IsReadOnlyLengthDescriptor(receiver_map);
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
for (var i = 0; i < 1024; ++i) Object.prototype["i" + i] = i;
8+
9+
function foo() { [].push(1); }
10+
11+
foo();
12+
foo();
13+
%OptimizeFunctionOnNextCall(foo);
14+
foo();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
for (var i = 0; i < 1024; ++i) Object.prototype["i" + i] = i;
8+
9+
function foo() { [1].pop(); }
10+
11+
foo();
12+
foo();
13+
%OptimizeFunctionOnNextCall(foo);
14+
foo();

0 commit comments

Comments
 (0)