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

Unified Diff: src/scopes.cc

Issue 11607016: Simplify implementation of assignment-to-const checks (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed comment Created 8 years 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
« no previous file with comments | « src/scopes.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/scopes.cc
diff --git a/src/scopes.cc b/src/scopes.cc
index 56a922d25da9395604e210f7847ef498043c6e66..c283b969d37913d30ae2ce0bfd0dcb1be3001c5b 100644
--- a/src/scopes.cc
+++ b/src/scopes.cc
@@ -308,23 +308,6 @@ bool Scope::Analyze(CompilationInfo* info) {
}
#endif
- if (FLAG_harmony_scoping) {
- VariableProxy* proxy = scope->CheckAssignmentToConst();
- if (proxy != NULL) {
- // Found an assignment to const. Throw a syntax error.
- MessageLocation location(info->script(),
- proxy->position(),
- proxy->position());
- Isolate* isolate = info->isolate();
- Factory* factory = isolate->factory();
- Handle<JSArray> array = factory->NewJSArray(0);
- Handle<Object> result =
- factory->NewSyntaxError("harmony_const_assign", array);
- isolate->Throw(*result, &location);
- return false;
- }
- }
-
info->SetScope(scope);
return true;
}
@@ -591,29 +574,6 @@ Declaration* Scope::CheckConflictingVarDeclarations() {
}
-VariableProxy* Scope::CheckAssignmentToConst() {
- // Check this scope.
- if (is_extended_mode()) {
- for (int i = 0; i < unresolved_.length(); i++) {
- ASSERT(unresolved_[i]->var() != NULL);
- if (unresolved_[i]->var()->is_const_mode() &&
- unresolved_[i]->IsLValue()) {
- return unresolved_[i];
- }
- }
- }
-
- // Check inner scopes.
- for (int i = 0; i < inner_scopes_.length(); i++) {
- VariableProxy* proxy = inner_scopes_[i]->CheckAssignmentToConst();
- if (proxy != NULL) return proxy;
- }
-
- // No assignments to const found.
- return NULL;
-}
-
-
class VarAndOrder {
public:
VarAndOrder(Variable* var, int order) : var_(var), order_(order) { }
@@ -1102,6 +1062,20 @@ bool Scope::ResolveVariable(CompilationInfo* info,
ASSERT(var != NULL);
+ if (FLAG_harmony_scoping && is_extended_mode() &&
+ var->is_const_mode() && proxy->IsLValue()) {
+ // Assignment to const. Throw a syntax error.
+ MessageLocation location(
+ info->script(), proxy->position(), proxy->position());
+ Isolate* isolate = Isolate::Current();
+ Factory* factory = isolate->factory();
+ Handle<JSArray> array = factory->NewJSArray(0);
+ Handle<Object> result =
+ factory->NewSyntaxError("harmony_const_assign", array);
+ isolate->Throw(*result, &location);
+ return false;
+ }
+
if (FLAG_harmony_modules) {
bool ok;
#ifdef DEBUG
@@ -1122,9 +1096,8 @@ bool Scope::ResolveVariable(CompilationInfo* info,
// Inconsistent use of module. Throw a syntax error.
// TODO(rossberg): generate more helpful error message.
- MessageLocation location(info->script(),
- proxy->position(),
- proxy->position());
+ MessageLocation location(
+ info->script(), proxy->position(), proxy->position());
Isolate* isolate = Isolate::Current();
Factory* factory = isolate->factory();
Handle<JSArray> array = factory->NewJSArray(1);
« no previous file with comments | « src/scopes.h ('k') | src/x64/full-codegen-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698