Commit 796ac25a authored by mmaly@chromium.org's avatar mmaly@chromium.org

Strict mode eval declares its locals in its own environment.

BUG=
TEST=strict-mode.js

Review URL: http://codereview.chromium.org/6883200

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7728 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 9a2cb300
......@@ -1303,7 +1303,10 @@ VariableProxy* Parser::Declare(Handle<String> name,
// 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) {
......
......@@ -211,6 +211,9 @@ class Scope: public ZoneObject {
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_; }
......
......@@ -1179,3 +1179,10 @@ function CheckPillDescriptor(func, name) {
assertEquals(test(i), true);
}
})();
(function TestStrictModeEval() {
"use strict";
eval("var eval_local = 10;");
assertThrows(function() { return eval_local; }, ReferenceError);
})();
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment