Reviewers: adamk,

Description:
Split off a separate --harmony_sloppy_let flag

--harmony_sloppy includes behavior to turn on sloppy mode lexical
bindings. Before this patch, it also included a way to parse let
which is likely web-incompatible (let is disallowed as an
identifier). This patch splits off the let parsing from the more
general block scoping code, so that block scoping can be developed
independently.

R=adamk
LOG=N
BUG=v8:3305

Please review this at https://codereview.chromium.org/1255013002/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+15, -2 lines):
  M src/bootstrapper.cc
  M src/flag-definitions.h
  M src/parser.cc
  M src/preparser.h
  M test/cctest/test-parsing.cc


Index: src/bootstrapper.cc
diff --git a/src/bootstrapper.cc b/src/bootstrapper.cc
index db05e3e8dfe0e26ab94235db1a0fdd7a40e4e6a8..71b61e6b52c573e4f64ea64926dee37a9d4c3b0b 100644
--- a/src/bootstrapper.cc
+++ b/src/bootstrapper.cc
@@ -1864,6 +1864,7 @@ EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_regexps)
 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_arrow_functions)
 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_tostring)
 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_sloppy)
+EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_sloppy_let)
 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_unicode)
 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_unicode_regexps)
 EMPTY_NATIVE_FUNCTIONS_FOR_FEATURE(harmony_computed_property_names)
@@ -1900,6 +1901,7 @@ EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_array_includes)
 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_arrow_functions)
 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_proxies)
 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy)
+EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_sloppy_let)
 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_unicode)
 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_computed_property_names)
 EMPTY_INITIALIZE_GLOBAL_FOR_FEATURE(harmony_rest_parameters)
@@ -2578,6 +2580,7 @@ bool Genesis::InstallExperimentalNatives() {
static const char* harmony_tostring_natives[] = {"native harmony-tostring.js",
                                                    nullptr};
   static const char* harmony_sloppy_natives[] = {nullptr};
+  static const char* harmony_sloppy_let_natives[] = {nullptr};
   static const char* harmony_unicode_natives[] = {nullptr};
   static const char* harmony_unicode_regexps_natives[] = {nullptr};
   static const char* harmony_computed_property_names_natives[] = {nullptr};
Index: src/flag-definitions.h
diff --git a/src/flag-definitions.h b/src/flag-definitions.h
index 787537e59d46b765a9b6f7ae3c57229ab4d0d57d..9c1b214ab9bb3c974820a389e05b644a279784b6 100644
--- a/src/flag-definitions.h
+++ b/src/flag-definitions.h
@@ -191,6 +191,7 @@ DEFINE_BOOL(legacy_const, true, "legacy semantics for const in sloppy mode")
   V(harmony_regexps, "harmony regular expression extensions")   \
   V(harmony_proxies, "harmony proxies")                         \
   V(harmony_sloppy, "harmony features in sloppy mode")          \
+  V(harmony_sloppy_let, "harmony let in sloppy mode")           \
   V(harmony_unicode_regexps, "harmony unicode regexps")         \
   V(harmony_reflect, "harmony Reflect API")                     \
   V(harmony_destructuring, "harmony destructuring")             \
@@ -240,6 +241,7 @@ HARMONY_SHIPPING(FLAG_SHIPPING_FEATURES)

 // Feature dependencies.
 DEFINE_IMPLICATION(harmony_unicode_regexps, harmony_unicode)
+DEFINE_IMPLICATION(harmony_sloppy_let, harmony_sloppy)


 // Flags for experimental implementation features.
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 8d1bd881a63e7fed137d767fe508f454dfc04baf..027880cd0504454cd8f53e1947f89407fbb4671c 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -913,6 +913,7 @@ Parser::Parser(ParseInfo* info)
   set_allow_harmony_modules(!info->is_native() && FLAG_harmony_modules);
   set_allow_harmony_arrow_functions(FLAG_harmony_arrow_functions);
   set_allow_harmony_sloppy(FLAG_harmony_sloppy);
+  set_allow_harmony_sloppy_let(FLAG_harmony_sloppy_let);
   set_allow_harmony_unicode(FLAG_harmony_unicode);
   set_allow_harmony_computed_property_names(
       FLAG_harmony_computed_property_names);
@@ -4459,6 +4460,7 @@ PreParser::PreParseResult Parser::ParseLazyFunctionBodyWithPreParser(
     SET_ALLOW(harmony_modules);
     SET_ALLOW(harmony_arrow_functions);
     SET_ALLOW(harmony_sloppy);
+    SET_ALLOW(harmony_sloppy_let);
     SET_ALLOW(harmony_unicode);
     SET_ALLOW(harmony_computed_property_names);
     SET_ALLOW(harmony_rest_params);
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index e652a1f1bbef90f477db5680a8f6c939d4e11f38..18a0162913d1774a8c1d3077c1e073f7a0a3762b 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -101,6 +101,7 @@ class ParserBase : public Traits {
         allow_natives_(false),
         allow_harmony_arrow_functions_(false),
         allow_harmony_sloppy_(false),
+        allow_harmony_sloppy_let_(false),
         allow_harmony_computed_property_names_(false),
         allow_harmony_rest_params_(false),
         allow_harmony_spreadcalls_(false),
@@ -118,6 +119,7 @@ class ParserBase : public Traits {
   ALLOW_ACCESSORS(natives);
   ALLOW_ACCESSORS(harmony_arrow_functions);
   ALLOW_ACCESSORS(harmony_sloppy);
+  ALLOW_ACCESSORS(harmony_sloppy_let);
   ALLOW_ACCESSORS(harmony_computed_property_names);
   ALLOW_ACCESSORS(harmony_rest_params);
   ALLOW_ACCESSORS(harmony_spreadcalls);
@@ -504,7 +506,7 @@ class ParserBase : public Traits {
   }

   bool allow_let() {
-    return is_strict(language_mode()) || allow_harmony_sloppy();
+    return is_strict(language_mode()) || allow_harmony_sloppy_let();
   }

   // Report syntax errors.
@@ -797,6 +799,7 @@ class ParserBase : public Traits {
   bool allow_natives_;
   bool allow_harmony_arrow_functions_;
   bool allow_harmony_sloppy_;
+  bool allow_harmony_sloppy_let_;
   bool allow_harmony_computed_property_names_;
   bool allow_harmony_rest_params_;
   bool allow_harmony_spreadcalls_;
Index: test/cctest/test-parsing.cc
diff --git a/test/cctest/test-parsing.cc b/test/cctest/test-parsing.cc
index 703f74d947cdaba3fb1da8f9cea83a0c0c6226ac..5c78f43dd037db63e2eaff331153d26d36d07dcd 100644
--- a/test/cctest/test-parsing.cc
+++ b/test/cctest/test-parsing.cc
@@ -1431,6 +1431,7 @@ enum ParserFlag {
   kAllowHarmonyArrowFunctions,
   kAllowHarmonyRestParameters,
   kAllowHarmonySloppy,
+  kAllowHarmonySloppyLet,
   kAllowHarmonyUnicode,
   kAllowHarmonyComputedPropertyNames,
   kAllowHarmonySpreadCalls,
@@ -1461,6 +1462,7 @@ void SetParserFlags(i::ParserBase<Traits>* parser,
   parser->set_allow_harmony_spreadcalls(
       flags.Contains(kAllowHarmonySpreadCalls));
   parser->set_allow_harmony_sloppy(flags.Contains(kAllowHarmonySloppy));
+ parser->set_allow_harmony_sloppy_let(flags.Contains(kAllowHarmonySloppyLet));
   parser->set_allow_harmony_unicode(flags.Contains(kAllowHarmonyUnicode));
   parser->set_allow_harmony_computed_property_names(
       flags.Contains(kAllowHarmonyComputedPropertyNames));
@@ -6841,7 +6843,8 @@ TEST(LetSloppy) {
   };
   // clang-format on

-  static const ParserFlag always_flags[] = {kAllowHarmonySloppy};
+  static const ParserFlag always_flags[] = {kAllowHarmonySloppy,
+                                            kAllowHarmonySloppyLet};
   RunParserSyncTest(context_data, data, kSuccess, NULL, 0, always_flags,
                     arraysize(always_flags));
 }


--
--
v8-dev mailing list
v8-dev@googlegroups.com
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to