Add flag for disallowing for-in initializers

This does not affect use counters.

R=nikolaos@chromium.org
BUG=

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

Cr-Commit-Position: refs/heads/master@{#35726}
This commit is contained in:
rossberg 2016-04-22 05:02:48 -07:00 committed by Commit bot
parent 0714485cbb
commit 9ce87d6772
4 changed files with 24 additions and 0 deletions

View File

@ -2397,6 +2397,7 @@ void Bootstrapper::ExportExperimentalFromRuntime(Isolate* isolate,
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode_regexps)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_do_expressions)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_for_in)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_iterator_close)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_exec)
EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_regexp_lookbehind)
@ -2957,6 +2958,7 @@ bool Genesis::InstallExperimentalNatives() {
static const char* harmony_simd_natives[] = {"native harmony-simd.js",
nullptr};
static const char* harmony_do_expressions_natives[] = {nullptr};
static const char* harmony_for_in_natives[] = {nullptr};
static const char* harmony_regexp_exec_natives[] = {
"native harmony-regexp-exec.js", nullptr};
static const char* harmony_regexp_subclass_natives[] = {nullptr};

View File

@ -199,6 +199,7 @@ DEFINE_IMPLICATION(es_staging, move_object_start)
V(harmony_sharedarraybuffer, "harmony sharedarraybuffer") \
V(harmony_simd, "harmony simd") \
V(harmony_do_expressions, "harmony do-expressions") \
V(harmony_for_in, "harmony for-in syntax") \
V(harmony_regexp_property, "harmony unicode regexp property classes") \
V(harmony_string_padding, "harmony String-padding methods")

View File

@ -3502,6 +3502,18 @@ Statement* Parser::ParseForStatement(ZoneList<const AstRawString*>* labels,
if (!IsLexicalVariableMode(parsing_result.descriptor.mode) &&
decl.pattern->IsVariableProxy() && decl.initializer != nullptr) {
++use_counts_[v8::Isolate::kForInInitializer];
if (FLAG_harmony_for_in) {
// TODO(rossberg): This error is not currently generated in the
// preparser, because that would lose some of the use counts
// recorded above. Once either the use counter or the flag is
// removed, the preparser should be adjusted.
ParserTraits::ReportMessageAt(
parsing_result.first_initializer_loc,
MessageTemplate::kForInOfLoopInitializer,
ForEachStatement::VisitModeString(mode));
*ok = false;
return nullptr;
}
const AstRawString* name =
decl.pattern->AsVariableProxy()->raw_name();
VariableProxy* single_var = scope_->NewUnresolved(

View File

@ -0,0 +1,9 @@
// Copyright 2015 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: --harmony-for-in
assertThrows("for (var x = 0 in {});", SyntaxError);
assertThrows("for (const x = 0 in {});", SyntaxError);
assertThrows("for (let x = 0 in {});", SyntaxError);