Chromium Code Reviews| Index: src/scopes.cc |
| diff --git a/src/scopes.cc b/src/scopes.cc |
| index 29fd5ebad6db1a02b38efa6d81b5446ddecd35c0..fe14b5c25346c0c75fae5bdbed5f740f9e15acfb 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 (!info->is_native() && FLAG_harmony_scoping) { |
|
fschneider
2011/11/30 16:11:46
Can you explain why you need to test for is_native
Steven
2011/12/05 11:56:57
The test is not needed anymore, I'll remove it. It
|
| + 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,31 @@ 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]->IsUsedAsLValue()) { |
| + 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); |