Revision: 7728
Author:   [email protected]
Date:     Fri Apr 29 08:31:39 2011
Log:      Strict mode eval declares its locals in its own environment.

BUG=
TEST=strict-mode.js

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

Modified:
 /branches/bleeding_edge/src/parser.cc
 /branches/bleeding_edge/src/scopes.h
 /branches/bleeding_edge/test/mjsunit/strict-mode.js

=======================================
--- /branches/bleeding_edge/src/parser.cc       Thu Apr 28 10:49:55 2011
+++ /branches/bleeding_edge/src/parser.cc       Fri Apr 29 08:31:39 2011
@@ -1303,7 +1303,10 @@
   // to the corresponding activation frame at runtime if necessary.
   // For instance declarations inside an eval scope need to be added
   // to the calling function context.
-  if (top_scope_->is_function_scope()) {
+ // Similarly, strict mode eval scope does not leak variable declarations to
+  // the caller's scope so we declare all locals, too.
+  if (top_scope_->is_function_scope() ||
+      top_scope_->is_strict_mode_eval_scope()) {
     // Declare the variable in the function scope.
     var = top_scope_->LocalLookup(name);
     if (var == NULL) {
=======================================
--- /branches/bleeding_edge/src/scopes.h        Wed Apr  6 11:32:01 2011
+++ /branches/bleeding_edge/src/scopes.h        Fri Apr 29 08:31:39 2011
@@ -211,6 +211,9 @@
   bool is_function_scope() const { return type_ == FUNCTION_SCOPE; }
   bool is_global_scope() const { return type_ == GLOBAL_SCOPE; }
   bool is_strict_mode() const { return strict_mode_; }
+  bool is_strict_mode_eval_scope() const {
+    return is_eval_scope() && is_strict_mode();
+  }

   // Information about which scopes calls eval.
   bool calls_eval() const { return scope_calls_eval_; }
=======================================
--- /branches/bleeding_edge/test/mjsunit/strict-mode.js Fri Apr 8 07:30:10 2011 +++ /branches/bleeding_edge/test/mjsunit/strict-mode.js Fri Apr 29 08:31:39 2011
@@ -1179,3 +1179,10 @@
     assertEquals(test(i), true);
   }
 })();
+
+
+(function TestStrictModeEval() {
+  "use strict";
+  eval("var eval_local = 10;");
+  assertThrows(function() { return eval_local; }, ReferenceError);
+})();

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

Reply via email to