Chromium Code Reviews| Index: src/runtime/runtime-scopes.cc |
| diff --git a/src/runtime/runtime-scopes.cc b/src/runtime/runtime-scopes.cc |
| index c935cdabef7728503710995105291e5da72eca51..8d6d036b8f698647971e092db128bed6d8e6aa11 100644 |
| --- a/src/runtime/runtime-scopes.cc |
| +++ b/src/runtime/runtime-scopes.cc |
| @@ -507,6 +507,23 @@ RUNTIME_FUNCTION(Runtime_NewClosure) { |
| pretenure_flag); |
| } |
| +static bool FindNameClash(Handle<ScopeInfo> scope_info, |
| + Handle<GlobalContextTable> global_context, |
| + Handle<String>* clashed_name) { |
| + for (int var = 0; var < scope_info->ContextLocalCount(); var++) { |
| + Handle<String> name(scope_info->ContextLocalName(var)); |
| + VariableMode mode = scope_info->ContextLocalMode(var); |
| + GlobalContextTable::LookupResult lookup; |
| + if (GlobalContextTable::Lookup(global_context, name, &lookup)) { |
| + if (IsLexicalVariableMode(mode) || IsLexicalVariableMode(lookup.mode_)) { |
|
rossberg
2014/11/06 12:29:12
Are non-lexical variables actually included in tho
Dmitry Lomov (no reviews)
2014/11/06 17:26:58
All done (I kept IsLexicalVariableMode(lookup.mode
|
| + *clashed_name = name; |
| + return true; |
| + } |
| + } |
| + } |
| + return false; |
| +} |
| + |
| RUNTIME_FUNCTION(Runtime_NewGlobalContext) { |
| HandleScope scope(isolate); |
| @@ -514,12 +531,25 @@ RUNTIME_FUNCTION(Runtime_NewGlobalContext) { |
| CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); |
| CONVERT_ARG_HANDLE_CHECKED(ScopeInfo, scope_info, 1); |
| + Handle<Context> native_context( |
| + function->context()->global_object()->native_context()); |
| + Handle<GlobalContextTable> global_context_table( |
| + native_context->global_context_table()); |
| + |
| + Handle<String> clashed_name; |
| + if (FindNameClash(scope_info, global_context_table, &clashed_name)) { |
|
rossberg
2014/11/06 12:29:12
Now that the checking this is a runtime thing and
Dmitry Lomov (no reviews)
2014/11/06 17:26:58
Yes, I will clean it up in separate CL
|
| + return ThrowRedeclarationError(isolate, clashed_name); |
| + } |
| + |
| Handle<Context> result = |
| isolate->factory()->NewGlobalContext(function, scope_info); |
| DCHECK(function->context() == isolate->context()); |
| DCHECK(function->context()->global_object() == result->global_object()); |
| - result->global_object()->set_global_context(*result); |
|
rossberg
2014/11/06 12:29:12
Can't the global_context property on the global ob
Dmitry Lomov (no reviews)
2014/11/06 17:26:58
Yes, I will do the cleanup in separate CL.
|
| + |
| + Handle<GlobalContextTable> new_global_context_table = |
| + GlobalContextTable::Extend(global_context_table, result); |
| + native_context->set_global_context_table(*new_global_context_table); |
| return *result; |
| } |