Commit 50f49640 authored by dslomov's avatar dslomov Committed by Commit bot

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}
parent 06a17e54
......@@ -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;
......
......@@ -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.
......
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