Reviewers: rossberg, Martin Maly,

Description:
[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.


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

SVN Base: https://v8.googlecode.com/svn/branches/experimental/arguments

Affected files:
  M src/compiler.cc
  M src/objects-inl.h
  M src/objects.h
  M src/parser.cc
  M src/scopes.h


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 022c0d20f030ae18563ead5077d2522d4f33b8fe..d137975e8fc113dcf3a8d4d3c20d0c5136cf960b 100755
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -750,6 +750,8 @@ void Compiler::SetFunctionInfo(Handle<SharedFunctionInfo> function_info,
   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->scope()->has_duplicate_parameters());
 }


Index: src/objects-inl.h
diff --git a/src/objects-inl.h b/src/objects-inl.h
index af50894557d1059333af130452d0f0930f14ba72..4e39e2301438fbda8bb5b5e362a5f8b44013581d 100644
--- a/src/objects-inl.h
+++ b/src/objects-inl.h
@@ -3063,6 +3063,10 @@ BOOL_ACCESSORS(SharedFunctionInfo,
                compiler_hints,
                uses_arguments,
                kUsesArguments)
+BOOL_ACCESSORS(SharedFunctionInfo,
+               compiler_hints,
+               has_duplicate_parameters,
+               kHasDuplicateParameters)


 #if V8_HOST_ARCH_32_BIT
Index: src/objects.h
diff --git a/src/objects.h b/src/objects.h
index 26edf212f1acd9ed97471b8d84b02a4738089fd7..223c369a101b82ed677b7638a15ed97ea034c247 100644
--- a/src/objects.h
+++ b/src/objects.h
@@ -4309,6 +4309,9 @@ class SharedFunctionInfo: public HeapObject {
// 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 @@ class SharedFunctionInfo: public HeapObject {
   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
Index: src/parser.cc
diff --git a/src/parser.cc b/src/parser.cc
index 22d4d3f1fe0ed9b101e2d666b1928f219f1c650d..3bf7e857c879b719fc6f0e3c44a57326026a9d74 100644
--- a/src/parser.cc
+++ b/src/parser.cc
@@ -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:
@@ -3557,6 +3557,7 @@ FunctionLiteral* Parser::ParseFunctionLiteral(Handle<String> var_name,
         name_loc = scanner().location();
       }
       if (!dupe_loc.IsValid() && top_scope_->IsDeclared(param_name)) {
+        top_scope_->MarkHasDuplicateParameters();
         dupe_loc = scanner().location();
       }
       if (!reserved_loc.IsValid() && is_reserved) {
Index: src/scopes.h
diff --git a/src/scopes.h b/src/scopes.h
index b8a1aed0d90443b926982f236e27a25b4b3b254c..c9d12600bbc624d02f1e3bac7d322095ed1cf44a 100644
--- a/src/scopes.h
+++ b/src/scopes.h
@@ -221,6 +221,10 @@ class Scope: public ZoneObject {
   // Does this scope contain a with statement.
   bool contains_with() const { return scope_contains_with_; }

+  // Does this scope have duplicated parameter names.
+ bool has_duplicate_parameters() const { return has_duplicate_parameters_; }
+  void MarkHasDuplicateParameters() { has_duplicate_parameters_ = true; }
+
   // The scope immediately surrounding this scope, or NULL.
   Scope* outer_scope() const { return outer_scope_; }

@@ -359,6 +363,7 @@ class Scope: public ZoneObject {
   bool scope_contains_with_;  // this scope contains a 'with' statement
   bool scope_calls_eval_;  // this scope contains an 'eval' call
   bool strict_mode_;  // this scope is a strict mode scope
+  bool has_duplicate_parameters_;

   // Computed via PropagateScopeInfo.
   bool outer_scope_calls_eval_;
@@ -432,6 +437,7 @@ class Scope: public ZoneObject {
     scope_calls_eval_ = false;
     // Inherit the strict mode from the parent scope.
     strict_mode_ = (outer_scope != NULL) && outer_scope->strict_mode_;
+    has_duplicate_parameters_ = false;
     outer_scope_calls_eval_ = false;
     inner_scope_calls_eval_ = false;
     outer_scope_is_eval_scope_ = false;


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

Reply via email to