Revision: 7538
Author:   [email protected]
Date:     Thu Apr  7 04:02:25 2011
Log:      [Arguments] Mark functions with duplicated parameters.

Add a bit to the scope, set when a duplicated parameter is detected by the
parser.  Propagate it to the shared function info.

Review URL: http://codereview.chromium.org/6815006
http://code.google.com/p/v8/source/detail?r=7538

Modified:
 /branches/experimental/arguments/src/ast.h
 /branches/experimental/arguments/src/compiler.cc
 /branches/experimental/arguments/src/objects-inl.h
 /branches/experimental/arguments/src/objects.h
 /branches/experimental/arguments/src/parser.cc

=======================================
--- /branches/experimental/arguments/src/ast.h  Tue Apr  5 07:49:49 2011
+++ /branches/experimental/arguments/src/ast.h  Thu Apr  7 04:02:25 2011
@@ -1706,7 +1706,8 @@
                   int start_position,
                   int end_position,
                   bool is_expression,
-                  bool contains_loops)
+                  bool contains_loops,
+                  bool has_duplicate_parameters)
       : name_(name),
         scope_(scope),
         body_(body),
@@ -1718,11 +1719,13 @@
         num_parameters_(num_parameters),
         start_position_(start_position),
         end_position_(end_position),
-        is_expression_(is_expression),
-        contains_loops_(contains_loops),
         function_token_position_(RelocInfo::kNoPosition),
         inferred_name_(HEAP->empty_string()),
-        pretenure_(false) { }
+        is_expression_(is_expression),
+        contains_loops_(contains_loops),
+        pretenure_(false),
+        has_duplicate_parameters_(has_duplicate_parameters) {
+  }

   DECLARE_NODE_TYPE(FunctionLiteral)

@@ -1761,6 +1764,8 @@

   bool pretenure() { return pretenure_; }
   void set_pretenure(bool value) { pretenure_ = value; }
+
+  bool has_duplicate_parameters() { return has_duplicate_parameters_; }

  private:
   Handle<String> name_;
@@ -1773,12 +1778,13 @@
   int num_parameters_;
   int start_position_;
   int end_position_;
+  int function_token_position_;
+  Handle<String> inferred_name_;
   bool is_expression_;
   bool contains_loops_;
   bool strict_mode_;
-  int function_token_position_;
-  Handle<String> inferred_name_;
   bool pretenure_;
+  bool has_duplicate_parameters_;
 };


=======================================
--- /branches/experimental/arguments/src/compiler.cc Tue Apr 5 07:49:49 2011 +++ /branches/experimental/arguments/src/compiler.cc Thu Apr 7 04:02:25 2011
@@ -750,6 +750,7 @@
   function_info->set_allows_lazy_compilation(lit->AllowsLazyCompilation());
   function_info->set_strict_mode(lit->strict_mode());
   function_info->set_uses_arguments(lit->scope()->arguments() != NULL);
+ function_info->set_has_duplicate_parameters(lit->has_duplicate_parameters());
 }


=======================================
--- /branches/experimental/arguments/src/objects-inl.h Tue Apr 5 07:49:49 2011 +++ /branches/experimental/arguments/src/objects-inl.h Thu Apr 7 04:02:25 2011
@@ -3063,6 +3063,10 @@
                compiler_hints,
                uses_arguments,
                kUsesArguments)
+BOOL_ACCESSORS(SharedFunctionInfo,
+               compiler_hints,
+               has_duplicate_parameters,
+               kHasDuplicateParameters)


 #if V8_HOST_ARCH_32_BIT
=======================================
--- /branches/experimental/arguments/src/objects.h      Tue Apr  5 07:49:49 2011
+++ /branches/experimental/arguments/src/objects.h      Thu Apr  7 04:02:25 2011
@@ -4309,6 +4309,9 @@
// False if the function definitely does not allocate an arguments object.
   DECL_BOOLEAN_ACCESSORS(uses_arguments)

+  // True if the function has any duplicated parameter names.
+  DECL_BOOLEAN_ACCESSORS(has_duplicate_parameters)
+
   // Indicates whether or not the code in the shared function support
   // deoptimization.
   inline bool has_deoptimization_support();
@@ -4482,14 +4485,19 @@
   static const int kStartPositionMask = ~((1 << kStartPositionShift) - 1);

   // Bit positions in compiler_hints.
-  static const int kHasOnlySimpleThisPropertyAssignments = 0;
-  static const int kAllowLazyCompilation = 1;
-  static const int kLiveObjectsMayExist = 2;
-  static const int kCodeAgeShift = 3;
-  static const int kCodeAgeMask = 0x7;
-  static const int kOptimizationDisabled = 6;
-  static const int kStrictModeFunction = 7;
-  static const int kUsesArguments = 8;
+  static const int kCodeAgeSize = 3;
+  static const int kCodeAgeMask = (1 << kCodeAgeSize) - 1;
+
+  enum CompilerHints {
+    kHasOnlySimpleThisPropertyAssignments,
+    kAllowLazyCompilation,
+    kLiveObjectsMayExist,
+    kCodeAgeShift,
+    kOptimizationDisabled = kCodeAgeShift + kCodeAgeSize,
+    kStrictModeFunction,
+    kUsesArguments,
+    kHasDuplicateParameters
+  };

  private:
 #if V8_HOST_ARCH_32_BIT
=======================================
--- /branches/experimental/arguments/src/parser.cc      Tue Apr  5 07:49:49 2011
+++ /branches/experimental/arguments/src/parser.cc      Thu Apr  7 04:02:25 2011
@@ -1,4 +1,4 @@
-// Copyright 2010 the V8 project authors. All rights reserved.
+// Copyright 2011 the V8 project authors. All rights reserved.
 // Redistribution and use in source and binary forms, with or without
 // modification, are permitted provided that the following conditions are
 // met:
@@ -665,7 +665,8 @@
           0,
           source->length(),
           false,
-          lexical_scope.ContainsLoops());
+          lexical_scope.ContainsLoops(),
+          false);
     } else if (stack_overflow_) {
       isolate()->StackOverflow();
     }
@@ -3545,6 +3546,7 @@
     Scanner::Location name_loc = Scanner::NoLocation();
     Scanner::Location dupe_loc = Scanner::NoLocation();
     Scanner::Location reserved_loc = Scanner::NoLocation();
+    bool has_duplicate_parameters = false;

     bool done = (peek() == Token::RPAREN);
     while (!done) {
@@ -3557,6 +3559,7 @@
         name_loc = scanner().location();
       }
       if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) {
+        has_duplicate_parameters = true;
         dupe_loc = scanner().location();
       }
       if (!reserved_loc.IsValid() && is_reserved) {
@@ -3688,17 +3691,18 @@

     FunctionLiteral* function_literal =
         new(zone()) FunctionLiteral(name,
-                            top_scope_,
-                            body,
-                            materialized_literal_count,
-                            expected_property_count,
-                            only_simple_this_property_assignments,
-                            this_property_assignments,
-                            num_parameters,
-                            start_pos,
-                            end_pos,
-                            function_name->length() > 0,
-                            lexical_scope.ContainsLoops());
+                                    top_scope_,
+                                    body,
+                                    materialized_literal_count,
+                                    expected_property_count,
+                                    only_simple_this_property_assignments,
+                                    this_property_assignments,
+                                    num_parameters,
+                                    start_pos,
+                                    end_pos,
+                                    function_name->length() > 0,
+                                    lexical_scope.ContainsLoops(),
+                                    has_duplicate_parameters);
     function_literal->set_function_token_position(function_token_position);

     if (fni_ != NULL && !is_named) fni_->AddFunction(function_literal);

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

Reply via email to