[inspector] Mark Intl builtins as side-effect free.

Fixed: chromium:1073804
Change-Id: Ia8cd29323e2b1c4faa0f115b5f60bc216b7813f1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3196175
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Simon Zünd <szuend@chromium.org>
Auto-Submit: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: Simon Zünd <szuend@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77171}
This commit is contained in:
Benedikt Meurer 2021-09-30 15:27:22 +02:00 committed by V8 LUCI CQ
parent 46088a2838
commit f40998322f
4 changed files with 335 additions and 0 deletions

View File

@ -753,6 +753,7 @@ DebugInfo::SideEffectState BuiltinGetSideEffectState(Builtin id) {
case Builtin::kStringFromCharCode:
case Builtin::kStringFromCodePoint:
case Builtin::kStringConstructor:
case Builtin::kStringListFromIterable:
case Builtin::kStringPrototypeAnchor:
case Builtin::kStringPrototypeAt:
case Builtin::kStringPrototypeBig:
@ -831,6 +832,78 @@ DebugInfo::SideEffectState BuiltinGetSideEffectState(Builtin id) {
case Builtin::kAllocateRegularInOldGeneration:
return DebugInfo::kHasNoSideEffect;
#ifdef V8_INTL_SUPPORT
// Intl builtins.
case Builtin::kIntlGetCanonicalLocales:
// Intl.Collator builtins.
case Builtin::kCollatorConstructor:
case Builtin::kCollatorInternalCompare:
case Builtin::kCollatorPrototypeCompare:
case Builtin::kCollatorPrototypeResolvedOptions:
case Builtin::kCollatorSupportedLocalesOf:
// Intl.DateTimeFormat builtins.
case Builtin::kDateTimeFormatConstructor:
case Builtin::kDateTimeFormatInternalFormat:
case Builtin::kDateTimeFormatPrototypeFormat:
case Builtin::kDateTimeFormatPrototypeFormatRange:
case Builtin::kDateTimeFormatPrototypeFormatRangeToParts:
case Builtin::kDateTimeFormatPrototypeFormatToParts:
case Builtin::kDateTimeFormatPrototypeResolvedOptions:
case Builtin::kDateTimeFormatSupportedLocalesOf:
// Intl.DisplayNames builtins.
case Builtin::kDisplayNamesConstructor:
case Builtin::kDisplayNamesPrototypeOf:
case Builtin::kDisplayNamesPrototypeResolvedOptions:
case Builtin::kDisplayNamesSupportedLocalesOf:
// Intl.ListFormat builtins.
case Builtin::kListFormatConstructor:
case Builtin::kListFormatPrototypeFormat:
case Builtin::kListFormatPrototypeFormatToParts:
case Builtin::kListFormatPrototypeResolvedOptions:
case Builtin::kListFormatSupportedLocalesOf:
// Intl.Locale builtins.
case Builtin::kLocaleConstructor:
case Builtin::kLocalePrototypeBaseName:
case Builtin::kLocalePrototypeCalendar:
case Builtin::kLocalePrototypeCalendars:
case Builtin::kLocalePrototypeCaseFirst:
case Builtin::kLocalePrototypeCollation:
case Builtin::kLocalePrototypeCollations:
case Builtin::kLocalePrototypeHourCycle:
case Builtin::kLocalePrototypeHourCycles:
case Builtin::kLocalePrototypeLanguage:
case Builtin::kLocalePrototypeMaximize:
case Builtin::kLocalePrototypeMinimize:
case Builtin::kLocalePrototypeNumeric:
case Builtin::kLocalePrototypeNumberingSystem:
case Builtin::kLocalePrototypeNumberingSystems:
case Builtin::kLocalePrototypeRegion:
case Builtin::kLocalePrototypeScript:
case Builtin::kLocalePrototypeTextInfo:
case Builtin::kLocalePrototypeTimeZones:
case Builtin::kLocalePrototypeToString:
case Builtin::kLocalePrototypeWeekInfo:
// Intl.NumberFormat builtins.
case Builtin::kNumberFormatConstructor:
case Builtin::kNumberFormatInternalFormatNumber:
case Builtin::kNumberFormatPrototypeFormatNumber:
case Builtin::kNumberFormatPrototypeFormatToParts:
case Builtin::kNumberFormatPrototypeResolvedOptions:
case Builtin::kNumberFormatSupportedLocalesOf:
// Intl.PluralRules builtins.
case Builtin::kPluralRulesConstructor:
case Builtin::kPluralRulesPrototypeResolvedOptions:
case Builtin::kPluralRulesPrototypeSelect:
case Builtin::kPluralRulesSupportedLocalesOf:
// Intl.RelativeTimeFormat builtins.
case Builtin::kRelativeTimeFormatConstructor:
case Builtin::kRelativeTimeFormatPrototypeFormat:
case Builtin::kRelativeTimeFormatPrototypeFormatToParts:
case Builtin::kRelativeTimeFormatPrototypeResolvedOptions:
case Builtin::kRelativeTimeFormatSupportedLocalesOf:
return DebugInfo::kHasNoSideEffect;
#endif // V8_INTL_SUPPORT
// Set builtins.
case Builtin::kSetIteratorPrototypeNext:
case Builtin::kSetPrototypeAdd:
@ -882,6 +955,7 @@ DebugInfo::SideEffectState BuiltinGetSideEffectState(Builtin id) {
case Builtin::kRegExpPrototypeUnicodeGetter:
case Builtin::kRegExpPrototypeStickyGetter:
return DebugInfo::kRequiresRuntimeChecks;
default:
if (FLAG_trace_side_effect_free_debug_evaluate) {
PrintF("[debug-evaluate] built-in %s may cause side effect.\n",

View File

@ -522,4 +522,9 @@
'cpu-profiler/coverage-block': [SKIP],
}], # variant == turboprop or variant = turboprop_as_toptier
##############################################################################
['no_i18n == False', {
'runtime/evaluate-without-side-effects-i18n': [SKIP],
}], # no_i18n == False
]

View File

@ -0,0 +1,74 @@
Tests side-effect-free evaluation with i18n enabled
Running test: testCollator
Intl.Collator.supportedLocalesOf(["en-US"]) : ok
new Intl.Collator("en-US") : ok
someGlobalCollator.compare("foo", "bar") : ok
someGlobalCollator.resolvedOptions() : ok
Running test: testDateTimeFormat
Intl.DateTimeFormat.supportedLocalesOf(["en-US"]) : ok
new Intl.DateTimeFormat("en-US") : ok
someGlobalDateTimeFormat.format(new Date(2021, 5)) : ok
someGlobalDateTimeFormat.formatToParts(new Date(2021, 5)) : ok
someGlobalDateTimeFormat.resolvedOptions() : ok
someGlobalDateTimeFormat.formatRange(new Date(2021, 5), new Date(2022, 1)) : ok
someGlobalDateTimeFormat.formatRangeToParts(new Date(2021, 5), new Date(2022, 1)) : ok
Running test: testDisplayNames
Intl.DisplayNames.supportedLocalesOf(["en-US"]) : ok
new Intl.DisplayNames(["en-US"], {type: "region"}) : ok
someGlobalDisplayNames.of("en") : ok
someGlobalDisplayNames.resolvedOptions() : ok
Running test: testIntl
Intl.getCanonicalLocales("en-US") : ok
Running test: testListFormat
Intl.ListFormat.supportedLocalesOf(["en-US"]) : ok
new Intl.ListFormat("en", { style: "long", type: "conjunction" }); : ok
someGlobalListFormat.format(["a", "b"]) : ok
someGlobalListFormat.formatToParts(["a", "b"]) : ok
someGlobalListFormat.resolvedOptions() : ok
Running test: testLocale
new Intl.Locale("en-US") : ok
someGlobalLocale.baseName : ok
someGlobalLocale.calendar : ok
someGlobalLocale.calendars : ok
someGlobalLocale.caseFirst : ok
someGlobalLocale.collation : ok
someGlobalLocale.hourCycle : ok
someGlobalLocale.hourCycles : ok
someGlobalLocale.language : ok
someGlobalLocale.numberingSystem : ok
someGlobalLocale.numberingSystems : ok
someGlobalLocale.numeric : ok
someGlobalLocale.region : ok
someGlobalLocale.script : ok
someGlobalLocale.textInfo : ok
someGlobalLocale.timeZones : ok
someGlobalLocale.weekInfo : ok
someGlobalLocale.maximize() : ok
someGlobalLocale.minimize() : ok
someGlobalLocale.toString() : ok
Running test: testNumberFormat
Intl.NumberFormat.supportedLocalesOf(["en-US"]) : ok
new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" }) : ok
someGlobalNumberFormat.format(1) : ok
someGlobalNumberFormat.formatToParts(1) : ok
someGlobalNumberFormat.resolvedOptions() : ok
Running test: testPluralRules
Intl.PluralRules.supportedLocalesOf(["en-US"]) : ok
new Intl.PluralRules("en-US") : ok
someGlobalPluralRules.resolvedOptions() : ok
someGlobalPluralRules.select(42) : ok
Running test: testRelativeTimeFormat
Intl.RelativeTimeFormat.supportedLocalesOf(["en-US"]) : ok
new Intl.RelativeTimeFormat("en-US", {style: "narrow"}) : ok
someGlobalRelativeTimeFormat.format(2, "day") : ok
someGlobalRelativeTimeFormat.formatToParts(2, "day") : ok
someGlobalRelativeTimeFormat.resolvedOptions() : ok

View File

@ -0,0 +1,182 @@
// Copyright 2021 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.
let {session, contextGroup, Protocol} = InspectorTest.start('Tests side-effect-free evaluation with i18n enabled');
contextGroup.addScript(`
var someGlobalCollator = new Intl.Collator("en-Latn-US");
var someGlobalDateTimeFormat = new Intl.DateTimeFormat("en-Latn-US");
var someGlobalDisplayNames = new Intl.DisplayNames(["en-Latn-US"], {type: 'region'});
var someGlobalListFormat = new Intl.ListFormat('en', { style: 'long', type: 'conjunction' });
var someGlobalLocale = new Intl.Locale("en-Latn-US", {language: "es"});
var someGlobalNumberFormat = new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' });
var someGlobalPluralRules = new Intl.PluralRules('en-US');
var someGlobalRelativeTimeFormat = new Intl.RelativeTimeFormat("en-US", {style: "narrow"});
`, 0, 0, 'foo.js');
const check = async (expression) => {
const {result:{exceptionDetails}} = await Protocol.Runtime.evaluate({expression, throwOnSideEffect: true});
InspectorTest.log(expression + ' : ' + (exceptionDetails ? 'throws' : 'ok'));
};
InspectorTest.runAsyncTestSuite([
async function testCollator() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.Collator.supportedLocalesOf(["en-US"])');
// constructor
await check('new Intl.Collator("en-US")');
// methods
await check('someGlobalCollator.compare("foo", "bar")');
await check('someGlobalCollator.resolvedOptions()');
await Protocol.Runtime.disable();
},
async function testDateTimeFormat() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.DateTimeFormat.supportedLocalesOf(["en-US"])');
// constructor
await check('new Intl.DateTimeFormat("en-US")');
// methods
await check('someGlobalDateTimeFormat.format(new Date(2021, 5))');
await check('someGlobalDateTimeFormat.formatToParts(new Date(2021, 5))');
await check('someGlobalDateTimeFormat.resolvedOptions()');
await check('someGlobalDateTimeFormat.formatRange(new Date(2021, 5), new Date(2022, 1))');
await check('someGlobalDateTimeFormat.formatRangeToParts(new Date(2021, 5), new Date(2022, 1))');
await Protocol.Runtime.disable();
},
async function testDisplayNames() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.DisplayNames.supportedLocalesOf(["en-US"])');
// constructor
await check('new Intl.DisplayNames(["en-US"], {type: "region"})');
// methods
await check('someGlobalDisplayNames.of("en")');
await check('someGlobalDisplayNames.resolvedOptions()');
await Protocol.Runtime.disable();
},
async function testIntl() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.getCanonicalLocales("en-US")');
await Protocol.Runtime.disable();
},
async function testListFormat() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.ListFormat.supportedLocalesOf(["en-US"])');
// constructor
await check('new Intl.ListFormat("en", { style: "long", type: "conjunction" });')
// methods
await check('someGlobalListFormat.format(["a", "b"])');
await check('someGlobalListFormat.formatToParts(["a", "b"])');
await check('someGlobalListFormat.resolvedOptions()');
await Protocol.Runtime.disable();
},
async function testLocale() {
await Protocol.Runtime.enable();
// constructor
await check('new Intl.Locale("en-US")')
// getters
await check('someGlobalLocale.baseName');
await check('someGlobalLocale.calendar');
await check('someGlobalLocale.calendars');
await check('someGlobalLocale.caseFirst');
await check('someGlobalLocale.collation');
await check('someGlobalLocale.hourCycle');
await check('someGlobalLocale.hourCycles');
await check('someGlobalLocale.language');
await check('someGlobalLocale.numberingSystem');
await check('someGlobalLocale.numberingSystems');
await check('someGlobalLocale.numeric');
await check('someGlobalLocale.region');
await check('someGlobalLocale.script');
await check('someGlobalLocale.textInfo');
await check('someGlobalLocale.timeZones');
await check('someGlobalLocale.weekInfo');
// methods
await check('someGlobalLocale.maximize()');
await check('someGlobalLocale.minimize()');
await check('someGlobalLocale.toString()');
await Protocol.Runtime.disable();
},
async function testNumberFormat() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.NumberFormat.supportedLocalesOf(["en-US"])');
// constructor
await check('new Intl.NumberFormat("de-DE", { style: "currency", currency: "EUR" })');
// methods
await check('someGlobalNumberFormat.format(1)');
await check('someGlobalNumberFormat.formatToParts(1)');
await check('someGlobalNumberFormat.resolvedOptions()');
await Protocol.Runtime.disable();
},
async function testPluralRules() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.PluralRules.supportedLocalesOf(["en-US"])');
// constructor
await check('new Intl.PluralRules("en-US")');
// methods
await check('someGlobalPluralRules.resolvedOptions()');
await check('someGlobalPluralRules.select(42)');
await Protocol.Runtime.disable();
},
async function testRelativeTimeFormat() {
await Protocol.Runtime.enable();
// static methods
await check('Intl.RelativeTimeFormat.supportedLocalesOf(["en-US"])');
// constructor
await check('new Intl.RelativeTimeFormat("en-US", {style: "narrow"})');
// methods
await check('someGlobalRelativeTimeFormat.format(2, "day")');
await check('someGlobalRelativeTimeFormat.formatToParts(2, "day")');
await check('someGlobalRelativeTimeFormat.resolvedOptions()');
await Protocol.Runtime.disable();
}
]);