Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: src/scopes.cc

Issue 7756014: Detect conflicting variable bindings in harmony mode. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index ddde48a77c50eaccb92ef21376dfc510f1a5aeb0..80cbeb7d0b61a1df6cdb8bedd564721c281bdc64 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -383,11 +383,11 @@ Variable* Scope::DeclareFunctionVar(Handle<String> name) {
}
-void Scope::DeclareParameter(Handle<String> name) {
+void Scope::DeclareParameter(Handle<String> name, Variable::Mode mode) {
ASSERT(!already_resolved());
ASSERT(is_function_scope());
Variable* var =
- variables_.Declare(this, name, Variable::VAR, true, Variable::NORMAL);
+ variables_.Declare(this, name, mode, true, Variable::NORMAL);
params_.Add(var);
}
@@ -467,6 +467,25 @@ void Scope::VisitIllegalRedeclaration(AstVisitor* visitor) {
}
+Declaration* Scope::CheckConflictingVarDeclarations() {
+ int length = decls_.length();
+ for (int i = 0; i < length; i++) {
+ Declaration* decl = decls_[i];
+ if (decl->mode() != Variable::VAR) continue;
+ Handle<String> name = decl->proxy()->name();
+ for (Scope* scope = decl->scope();
+ scope->is_block_scope() || scope->is_catch_scope();
+ scope = scope->outer_scope_) {
+ Variable* other_var = scope->variables_.Lookup(name);
Lasse Reichstein 2011/09/01 07:34:04 This should be able to skip the first scope, where
Steven 2011/09/01 15:01:33 When by first scope you mean the innermost scope w
+ if (other_var != NULL && other_var->mode() == Variable::LET) {
Lasse Reichstein 2011/09/01 07:34:04 Is it only LET declarations that can conflict, or
Steven 2011/09/01 15:01:33 Yes any non-VAR. Will fix it. On 2011/09/01 07:34:
+ return decl;
+ }
+ }
+ }
+ return NULL;
+}
+
+
template<class Allocator>
void Scope::CollectUsedVariables(List<Variable*, Allocator>* locals) {
// Collect variables in this scope.
« src/parser.cc ('K') | « src/scopes.h ('k') | test/mjsunit/harmony/block-conflicts.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698