Use counter for legacy const.

We only report the usages when full parse is happening, i.e. only when the function that declares a legacy const is compiled. This is an approximation that is easy to implement, but still should reflect the real-world usage.

BUG=v8:3942
LOG=N

Review URL: https://codereview.chromium.org/1041863002

Cr-Commit-Position: refs/heads/master@{#27526}
This commit is contained in:
dslomov 2015-03-30 09:20:53 -07:00 committed by Commit bot
parent 06a17e54d9
commit 50f4964085
2 changed files with 20 additions and 0 deletions

View File

@ -2272,6 +2272,7 @@ Block* Parser::ParseVariableDeclarations(
if (is_sloppy(language_mode())) {
mode = CONST_LEGACY;
init_op = Token::INIT_CONST_LEGACY;
++use_counts_[v8::Isolate::kLegacyConst];
} else {
DCHECK(var_context != kStatement);
mode = CONST;

View File

@ -3441,6 +3441,25 @@ TEST(UseAsmUseCount) {
}
TEST(UseConstLegacyCount) {
i::Isolate* isolate = CcTest::i_isolate();
i::HandleScope scope(isolate);
LocalContext env;
int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
global_use_counts = use_counts;
CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
CompileRun(
"const x = 1;\n"
"var foo = 1;\n"
"const y = 1;\n"
"function bar() {\n"
" const z = 1; var baz = 1;\n"
" function q() { const k = 42; }\n"
"}");
CHECK_EQ(4, use_counts[v8::Isolate::kLegacyConst]);
}
TEST(ErrorsArrowFunctions) {
// Tests that parser and preparser generate the same kind of errors
// on invalid arrow function syntax.