From: rossberg@chromium.org Date: Fri, 5 Oct 2012 12:47:34 +0000 (+0000) Subject: Make sure that names of temporaries do not clash with real variables. X-Git-Tag: upstream/4.7.83~15895 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=329cf12363b790a8e4c62956528a50e358e09e44;p=platform%2Fupstream%2Fv8.git Make sure that names of temporaries do not clash with real variables. R=mstarzinger@chromium.org BUG=v8:2322 Review URL: https://codereview.chromium.org/11035054 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@12668 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/include/v8.h b/include/v8.h index 92d928b..ff44fdf 100644 --- a/include/v8.h +++ b/include/v8.h @@ -4066,7 +4066,7 @@ class Internals { static const int kNullValueRootIndex = 7; static const int kTrueValueRootIndex = 8; static const int kFalseValueRootIndex = 9; - static const int kEmptySymbolRootIndex = 116; + static const int kEmptySymbolRootIndex = 117; static const int kJSObjectType = 0xaa; static const int kFirstNonstringType = 0x80; diff --git a/src/heap.h b/src/heap.h index 46ec6cf..d6a3d29 100644 --- a/src/heap.h +++ b/src/heap.h @@ -176,6 +176,7 @@ namespace internal { V(constructor_symbol, "constructor") \ V(code_symbol, ".code") \ V(result_symbol, ".result") \ + V(dot_for_symbol, ".for.") \ V(catch_var_symbol, ".catch-var") \ V(empty_symbol, "") \ V(eval_symbol, "eval") \ diff --git a/src/parser.cc b/src/parser.cc index 0326fc9..c2fd015 100644 --- a/src/parser.cc +++ b/src/parser.cc @@ -2842,7 +2842,12 @@ Statement* Parser::ParseForStatement(ZoneStringList* labels, bool* ok) { // TODO(keuchel): Move the temporary variable to the block scope, after // implementing stack allocated block scoped variables. - Variable* temp = top_scope_->DeclarationScope()->NewTemporary(name); + Factory* heap_factory = isolate()->factory(); + Handle dot = + heap_factory->NewStringFromAscii(CStrVector(".for.")); + Handle tempstr = heap_factory->NewConsString(dot, name); + Handle tempname = heap_factory->LookupSymbol(tempstr); + Variable* temp = top_scope_->DeclarationScope()->NewTemporary(tempname); VariableProxy* temp_proxy = factory()->NewVariableProxy(temp); ForInStatement* loop = factory()->NewForInStatement(labels); Target target(&this->target_stack_, loop); diff --git a/src/scopes.h b/src/scopes.h index 6e35d05..b9d151c 100644 --- a/src/scopes.h +++ b/src/scopes.h @@ -189,7 +189,7 @@ class Scope: public ZoneObject { // Creates a new temporary variable in this scope. The name is only used // for printing and cannot be used to find the variable. In particular, // the only way to get hold of the temporary is by keeping the Variable* - // around. + // around. The name should not clash with a legitimate variable names. Variable* NewTemporary(Handle name); // Adds the specific declaration node to the list of declarations in diff --git a/test/mjsunit/harmony/debug-blockscopes.js b/test/mjsunit/harmony/debug-blockscopes.js index 10aac2d..ca2ab9e 100644 --- a/test/mjsunit/harmony/debug-blockscopes.js +++ b/test/mjsunit/harmony/debug-blockscopes.js @@ -376,7 +376,7 @@ listener_delegate = function(exec_state) { debug.ScopeType.Global], exec_state); CheckScopeContent({x:'y'}, 0, exec_state); // The function scope contains a temporary iteration variable. - CheckScopeContent({x:'y'}, 1, exec_state); + CheckScopeContent({'.for.x':'y'}, 1, exec_state); }; for_loop_1(); EndTest(); @@ -401,7 +401,7 @@ listener_delegate = function(exec_state) { CheckScopeContent({x:3}, 0, exec_state); CheckScopeContent({x:'y'}, 1, exec_state); // The function scope contains a temporary iteration variable. - CheckScopeContent({x:'y'}, 2, exec_state); + CheckScopeContent({'.for.x':'y'}, 2, exec_state); }; for_loop_2(); EndTest(); diff --git a/test/mjsunit/regress/regress-2322.js b/test/mjsunit/regress/regress-2322.js index a60af06..1195bab 100644 --- a/test/mjsunit/regress/regress-2322.js +++ b/test/mjsunit/regress/regress-2322.js @@ -27,5 +27,10 @@ // Flags: --harmony-scoping +"use strict"; + assertThrows("'use strict'; for (let x in x);", ReferenceError); +let s; +for (let pppp in {}) {}; +assertThrows(function() { pppp = true }, ReferenceError);