Reviewers: Mads Ager,

Description:
Use NativesFlag to allow/disallow natives syntax during compilation.

This way we can avoid changing the value of FLAG_allow_natives_syntax.

Please review this at http://codereview.chromium.org/6694024/

Affected files:
  M src/compiler.h
  M src/compiler.cc
  M src/debug.cc
  M src/parser.cc


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 553f4868baa6e05f912d250d7926f974d3eb5f1a..cfba4b22ba2fdf65519036fb45106e10e2ae8b0a 100755
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -529,6 +529,7 @@ Handle<SharedFunctionInfo> Compiler::Compile(Handle<String> source,
     info.MarkAsGlobal();
     info.SetExtension(extension);
     info.SetPreParseData(pre_data);
+    if (natives == NATIVES_CODE) info.MarkAsAllowingNativesSyntax();
     result = MakeFunctionInfo(&info);
     if (extension == NULL && !result.is_null()) {
       CompilationCache::PutScript(source, result);
Index: src/compiler.h
diff --git a/src/compiler.h b/src/compiler.h
index e0a437ac6de8419a777a631772a828796080f763..92ec9ed6c4ff40cac5dbd507481187cef00d738f 100644
--- a/src/compiler.h
+++ b/src/compiler.h
@@ -80,6 +80,12 @@ class CompilationInfo BASE_EMBEDDED {
     ASSERT(is_lazy());
     flags_ |= IsInLoop::encode(true);
   }
+  void MarkAsAllowingNativesSyntax() {
+    flags_ |= IsNativesSyntaxAllowed::encode(true);
+  }
+  bool allows_natives_syntax() const {
+    return IsNativesSyntaxAllowed::decode(flags_);
+  }
   void SetFunction(FunctionLiteral* literal) {
     ASSERT(function_ == NULL);
     function_ = literal;
@@ -174,6 +180,8 @@ class CompilationInfo BASE_EMBEDDED {
   class IsInLoop: public BitField<bool, 3, 1> {};
   // Strict mode - used in eager compilation.
   class IsStrict: public BitField<bool, 4, 1> {};
+  // Native syntax (%-stuff) allowed?
+  class IsNativesSyntaxAllowed: public BitField<bool, 5, 1> {};

   unsigned flags_;

Index: src/debug.cc
diff --git a/src/debug.cc b/src/debug.cc
index cfeb340cea67e83daaddfca6d53879bcdcae22d4..8ae47b9a3820fa2ee71e7486dea404d7a505734b 100644
--- a/src/debug.cc
+++ b/src/debug.cc
@@ -764,15 +764,12 @@ bool Debug::CompileDebuggerScript(int index) {
   Handle<String> script_name = Factory::NewStringFromAscii(name);

   // Compile the script.
-  bool allow_natives_syntax = FLAG_allow_natives_syntax;
-  FLAG_allow_natives_syntax = true;
   Handle<SharedFunctionInfo> function_info;
   function_info = Compiler::Compile(source_code,
                                     script_name,
                                     0, 0, NULL, NULL,
                                     Handle<String>::null(),
                                     NATIVES_CODE);
-  FLAG_allow_natives_syntax = allow_natives_syntax;

   // Silently ignore stack overflows during compilation.
   if (function_info.is_null()) {
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 0725a0a7d35f3148d17926c2e4d79ed2a499ed21..98dfa2bc447cec384abef0a1deb7d8fc0da9e90b 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -5133,7 +5133,7 @@ bool ParserApi::Parse(CompilationInfo* info) {
     result = parser.ParseLazy(info);
   } else {
     bool allow_natives_syntax =
-        FLAG_allow_natives_syntax || Bootstrapper::IsActive();
+        info->allows_natives_syntax() || FLAG_allow_natives_syntax;
     ScriptDataImpl* pre_data = info->pre_parse_data();
Parser parser(script, allow_natives_syntax, info->extension(), pre_data);
     if (pre_data != NULL && pre_data->has_error()) {


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to