Skip to content

Commit 885a1ba

Browse files
DevSDKV8 LUCI CQ
authored andcommitted
[maglev] add missing arg type check for string.prototype.startsWith
js-call-reducer only reduces string argument[1] but maglev consumes unsupported type like regexp. hence, we should check it and stop reduce if it is not valid type. [1] https://source.chromium.org/chromium/chromium/src/+/main:v8/src/compiler/js-call-reducer.cc;l=6995?q=src%2Fcompiler%2Fjs-call-reducer.cc Bug: 442086665 Change-Id: Ifadaa7008257df3fff61e3569489fc7033171a7c Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/6905506 Auto-Submit: Seokho Song <[email protected]> Commit-Queue: Seokho Song <[email protected]> Reviewed-by: Victor Gomes <[email protected]> Cr-Commit-Position: refs/heads/main@{#102173}
1 parent df61520 commit 885a1ba

File tree

2 files changed

+27
-2
lines changed

2 files changed

+27
-2
lines changed

src/maglev/maglev-graph-builder.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9298,9 +9298,14 @@ MaybeReduceResult MaglevGraphBuilder::TryReduceStringPrototypeCodePointAt(
92989298
MaybeReduceResult MaglevGraphBuilder::TryReduceStringPrototypeStartsWith(
92999299
compiler::JSFunctionRef target, CallArguments& args) {
93009300
if (!CanSpeculateCall()) return {};
9301-
ValueNode* receiver = GetValueOrUndefined(args.receiver());
9301+
93029302
ValueNode* search_element =
9303-
BuildToString(GetValueOrUndefined(args[0]), ToString::kThrowOnSymbol);
9303+
args[0] ? args[0] : GetRootConstant(RootIndex::kundefined_string);
9304+
9305+
ValueNode* receiver = GetValueOrUndefined(args.receiver());
9306+
9307+
if (!NodeTypeIs(GetType(search_element), NodeType::kString)) return {};
9308+
93049309
ValueNode* start_arg = GetValueOrUndefined(args[1]);
93059310
ValueNode* start =
93069311
IsUndefinedValue(start_arg) ? GetInt32Constant(0) : start_arg;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2025 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+
var __caught = 0;
8+
function foo() {
9+
try {
10+
"".startsWith(/a/);
11+
} catch (e) {
12+
__caught++;
13+
}
14+
}
15+
16+
%PrepareFunctionForOptimization(foo);
17+
foo();
18+
%OptimizeFunctionOnNextCall(foo);
19+
foo();
20+
assertEquals(__caught, 2);

0 commit comments

Comments
 (0)