diff --git a/src/objects/intl-objects.tq b/src/objects/intl-objects.tq index 672f419657..a5f18b9bb3 100644 --- a/src/objects/intl-objects.tq +++ b/src/objects/intl-objects.tq @@ -102,9 +102,9 @@ macro LocaleCompareFastPath( transitioning builtin StringFastLocaleCompare(implicit context: Context)( localeCompareFn: JSFunction, left: JSAny, right: JSAny, locales: JSAny): JSAny { - if (TaggedEqual(left, right)) return SmiConstant(0); try { const left = Cast(left) otherwise Bailout; + if (TaggedEqual(left, right)) return SmiConstant(0); StringToSlice(left) otherwise LeftOneByte, LeftTwoByte; } label LeftOneByte(leftSlice: ConstSlice) { try { diff --git a/test/mjsunit/regress/regress-12495.js b/test/mjsunit/regress/regress-12495.js new file mode 100644 index 0000000000..282ef2dd00 --- /dev/null +++ b/test/mjsunit/regress/regress-12495.js @@ -0,0 +1,21 @@ +// Copyright 2022 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 + +function opt() { + try { + Reflect.apply("".localeCompare, undefined, [undefined]); + return false; + } catch(e) { + return true; + } +} + +%PrepareFunctionForOptimization(opt); +assertTrue(opt()); +assertTrue(opt()); +%OptimizeFunctionOnNextCall(opt); +assertTrue(opt()); +assertTrue(opt());