Skip to content

Commit f39fbb2

Browse files
author
ager@chromium.org
committed
Fix case where we treat an unaliased call to eval as an aliased call
to eval. BUG=http://code.google.com/p/v8/issues/detail?id=496 Review URL: http://codereview.chromium.org/366027 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@3225 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
1 parent efd2068 commit f39fbb2

2 files changed

Lines changed: 48 additions & 7 deletions

File tree

src/scopes.cc

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -540,11 +540,11 @@ Variable* Scope::NonLocal(Handle<String> name, Variable::Mode mode) {
540540

541541

542542
// Lookup a variable starting with this scope. The result is either
543-
// the statically resolved (local!) variable belonging to an outer scope,
544-
// or NULL. It may be NULL because a) we couldn't find a variable, or b)
545-
// because the variable is just a guess (and may be shadowed by another
546-
// variable that is introduced dynamically via an 'eval' call or a 'with'
547-
// statement).
543+
// the statically resolved variable belonging to an outer scope, or
544+
// NULL. It may be NULL because a) we couldn't find a variable, or b)
545+
// because the variable is just a guess (and may be shadowed by
546+
// another variable that is introduced dynamically via an 'eval' call
547+
// or a 'with' statement).
548548
Variable* Scope::LookupRecursive(Handle<String> name,
549549
bool inner_lookup,
550550
Variable** invalidated_local) {
@@ -598,9 +598,11 @@ Variable* Scope::LookupRecursive(Handle<String> name,
598598
if (inner_lookup)
599599
var->is_accessed_from_inner_scope_ = true;
600600

601-
// If the variable we have found is just a guess, invalidate the result.
601+
// If the variable we have found is just a guess, invalidate the
602+
// result. If the found variable is local, record that fact so we
603+
// can generate fast code to get it if it is not shadowed by eval.
602604
if (guess) {
603-
*invalidated_local = var;
605+
if (!var->is_global()) *invalidated_local = var;
604606
var = NULL;
605607
}
606608

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2009 the V8 project authors. All rights reserved.
2+
// Redistribution and use in source and binary forms, with or without
3+
// modification, are permitted provided that the following conditions are
4+
// met:
5+
//
6+
// * Redistributions of source code must retain the above copyright
7+
// notice, this list of conditions and the following disclaimer.
8+
// * Redistributions in binary form must reproduce the above
9+
// copyright notice, this list of conditions and the following
10+
// disclaimer in the documentation and/or other materials provided
11+
// with the distribution.
12+
// * Neither the name of Google Inc. nor the names of its
13+
// contributors may be used to endorse or promote products derived
14+
// from this software without specific prior written permission.
15+
//
16+
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27+
28+
// Regression test for http://code.google.com/p/v8/issues/detail?id=496.
29+
//
30+
// Tests that we do not treat the unaliased eval call in g as an
31+
// aliased call to eval.
32+
33+
function h() {
34+
function f() { return eval; }
35+
function g() { var x = 44; return eval("x"); }
36+
assertEquals(44, g());
37+
}
38+
39+
h();

0 commit comments

Comments
 (0)