Skip to content

Commit b8f144e

Browse files
bmeurerCommit Bot
authored andcommitted
[turbofan] Fix type of String#indexOf and String#lastIndexOf.
The Typer put the wrong type on String#index and String#lastIndexOf builtins, with an off by one on the upper bound. Bug: chromium:762874 Change-Id: Ia4c29bc2e8e1c85b6a7ae0b99f8aaabf839a5932 Reviewed-on: https://chromium-review.googlesource.com/660000 Reviewed-by: Jaroslav Sevcik <[email protected]> Commit-Queue: Benedikt Meurer <[email protected]> Cr-Commit-Position: refs/heads/master@{#47942}
1 parent d2da19c commit b8f144e

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

src/compiler/typer.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,7 @@ Type* Typer::Visitor::JSCallTyper(Type* fun, Typer* t) {
14531453
return Type::String();
14541454
case kStringIndexOf:
14551455
case kStringLastIndexOf:
1456-
return Type::Range(-1.0, String::kMaxLength - 1.0, t->zone());
1456+
return Type::Range(-1.0, String::kMaxLength, t->zone());
14571457
case kStringEndsWith:
14581458
case kStringIncludes:
14591459
return Type::Boolean();
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
const maxLength = %StringMaxLength();
8+
const s = 'A'.repeat(maxLength);
9+
10+
function foo(s) {
11+
let x = s.indexOf("", maxLength);
12+
return x === maxLength;
13+
}
14+
15+
assertTrue(foo(s));
16+
assertTrue(foo(s));
17+
%OptimizeFunctionOnNextCall(foo);
18+
assertTrue(foo(s));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright 2017 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+
const maxLength = %StringMaxLength();
8+
const s = 'A'.repeat(maxLength);
9+
10+
function foo(s) {
11+
let x = s.lastIndexOf("", maxLength);
12+
return x === maxLength;
13+
}
14+
15+
assertTrue(foo(s));
16+
assertTrue(foo(s));
17+
%OptimizeFunctionOnNextCall(foo);
18+
assertTrue(foo(s));

0 commit comments

Comments
 (0)