| Index: src/scopes.cc
|
| diff --git a/src/scopes.cc b/src/scopes.cc
|
| index 29fd5ebad6db1a02b38efa6d81b5446ddecd35c0..321c74c332897a23ea86017201ca0e8cd5e88994 100644
|
| --- a/src/scopes.cc
|
| +++ b/src/scopes.cc
|
| @@ -31,6 +31,7 @@
|
|
|
| #include "bootstrapper.h"
|
| #include "compiler.h"
|
| +#include "messages.h"
|
| #include "scopeinfo.h"
|
|
|
| #include "allocation-inl.h"
|
| @@ -284,8 +285,25 @@ 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; // Can not fail.
|
| + return true;
|
| }
|
|
|
|
|
| @@ -554,6 +572,29 @@ 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;
|
| +}
|
| +
|
| +
|
| void Scope::CollectStackAndContextLocals(ZoneList<Variable*>* stack_locals,
|
| ZoneList<Variable*>* context_locals) {
|
| ASSERT(stack_locals != NULL);
|
|
|