v8/test/mjsunit/check-bounds-string-from-char-code-at.js
Sathya Gunasekaran a1a45f4caa [ic] KeyedLoadIC: Optimize string keys as ArrayIndex
Updates CSA::TryToIntptr to handle array indices that are less than
INT_MAX which allows to handle string keys in the ICs.

Updates ICs to go monomorphic for string keys that are array indices.

Updates Turbofan to handle array indices when lowering element access.

Change-Id: Ibdde20130e075d0d645ab4a8266a968335eaad84
Bug: v8:9449
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1813018
Reviewed-by: Tobias Tebbi <tebbi@chromium.org>
Reviewed-by: Toon Verwaest <verwaest@chromium.org>
Reviewed-by: Georg Neis <neis@chromium.org>
Commit-Queue: Sathya Gunasekaran  <gsathya@chromium.org>
Cr-Commit-Position: refs/heads/master@{#64320}
2019-10-16 13:55:55 +00:00

32 lines
629 B
JavaScript

// 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 --opt --no-always-opt
let string = "foobar";
function f(useArrayIndex) {
let index = useArrayIndex ? '1': '4294967296';
return string.charCodeAt(index);
}
%PrepareFunctionForOptimization(f);
f(true);
f(true);
%OptimizeFunctionOnNextCall(f);
f(false);
assertUnoptimized(f);
%PrepareFunctionForOptimization(f);
f(true);
f(true);
%OptimizeFunctionOnNextCall(f);
f(true);
// no deopt here
f(false);
assertOptimized(f);