Commit 3a6ecfec authored by Sigurd Schneider's avatar Sigurd Schneider Committed by Commit Bot

Revert "[turbofan] add CheckSmi call to String.p.startsWith"

This reverts commit 6d209c9b.

Reason for revert: chromium:941952

Original change's description:
> [turbofan] add CheckSmi call to String.p.startsWith
> 
> Add a CheckSmi call to the value of the position argument to
> String.prototype.startsWith(search, [position]).
> 
> Bug: v8:8400, chromium:939746
> Change-Id: I7462bebe0d3fde605a4c27a34c0d9bb3f0cc1c20
> Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1514198
> Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
> Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#60216}

TBR=sigurds@chromium.org,bmeurer@chromium.org,usharma1998@gmail.com

# Not skipping CQ checks because original CL landed > 1 day ago.

Bug: v8:8400, chromium:939746
Change-Id: Ifee58b9e57313bbf93bca293e92d88af279a0261
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1524204
Commit-Queue: Sigurd Schneider <sigurds@chromium.org>
Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Cr-Commit-Position: refs/heads/master@{#60277}
parent e3f2fe44
......@@ -5191,8 +5191,6 @@ Reduction JSCallReducer::ReduceStringPrototypeStartsWith(Node* node) {
// Ensure that the {string} is actually a String.
string = effect = graph()->NewNode(
simplified()->CheckString(p.feedback()), string, effect, control);
position = effect = graph()->NewNode(
simplified()->CheckSmi(p.feedback()), position, effect, control);
Node* string_length =
graph()->NewNode(simplified()->StringLength(), string);
......
// Copyright 2019 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
// String.p.startsWith(x, NaN) shouldn't crash V8 when optimized.
(function () {
function f() { 'a'.startsWith('a', NaN); }
%PrepareFunctionForOptimization(f);
f();
f();
%OptimizeFunctionOnNextCall(f);
f();
})();
// String.p.startsWith should try to coerce non-numbers to numbers.
(function() {
let wasCalled = false;
const obj = {
[Symbol.toPrimitive]: () => wasCalled = true
};
function f() { ''.startsWith('a', obj); }
%PrepareFunctionForOptimization(f);
f();
f();
%OptimizeFunctionOnNextCall(f);
f();
assertTrue(wasCalled, "String.p.startsWith didn't attempt to coerce the position argument to a Number.")
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment