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

Side by Side Diff: src/contexts.cc

Issue 7992005: Block scoped const variables. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments, function variable mode, preparser. Created 9 years, 2 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/contexts.h ('k') | src/full-codegen.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 *binding_flags = MUTABLE_IS_INITIALIZED; 167 *binding_flags = MUTABLE_IS_INITIALIZED;
168 break; 168 break;
169 case LET: 169 case LET:
170 *attributes = NONE; 170 *attributes = NONE;
171 *binding_flags = MUTABLE_CHECK_INITIALIZED; 171 *binding_flags = MUTABLE_CHECK_INITIALIZED;
172 break; 172 break;
173 case CONST: 173 case CONST:
174 *attributes = READ_ONLY; 174 *attributes = READ_ONLY;
175 *binding_flags = IMMUTABLE_CHECK_INITIALIZED; 175 *binding_flags = IMMUTABLE_CHECK_INITIALIZED;
176 break; 176 break;
177 case CONST_HARMONY:
178 *attributes = READ_ONLY;
179 *binding_flags = IMMUTABLE_CHECK_INITIALIZED_HARMONY;
180 break;
177 case DYNAMIC: 181 case DYNAMIC:
178 case DYNAMIC_GLOBAL: 182 case DYNAMIC_GLOBAL:
179 case DYNAMIC_LOCAL: 183 case DYNAMIC_LOCAL:
180 case TEMPORARY: 184 case TEMPORARY:
181 UNREACHABLE(); 185 UNREACHABLE();
182 break; 186 break;
183 } 187 }
184 return context; 188 return context;
185 } 189 }
186 190
187 // Check the slot corresponding to the intermediate context holding 191 // Check the slot corresponding to the intermediate context holding
188 // only the function name variable. 192 // only the function name variable.
189 if (follow_context_chain && context->IsFunctionContext()) { 193 if (follow_context_chain && context->IsFunctionContext()) {
190 int function_index = scope_info->FunctionContextSlotIndex(*name); 194 VariableMode mode;
195 int function_index = scope_info->FunctionContextSlotIndex(*name, &mode);
191 if (function_index >= 0) { 196 if (function_index >= 0) {
192 if (FLAG_trace_contexts) { 197 if (FLAG_trace_contexts) {
193 PrintF("=> found intermediate function in context slot %d\n", 198 PrintF("=> found intermediate function in context slot %d\n",
194 function_index); 199 function_index);
195 } 200 }
196 *index = function_index; 201 *index = function_index;
197 *attributes = READ_ONLY; 202 *attributes = READ_ONLY;
198 *binding_flags = IMMUTABLE_IS_INITIALIZED; 203 ASSERT(mode == CONST || mode == CONST_HARMONY);
204 *binding_flags = (mode == CONST)
205 ? IMMUTABLE_IS_INITIALIZED : IMMUTABLE_IS_INITIALIZED_HARMONY;
199 return context; 206 return context;
200 } 207 }
201 } 208 }
202 209
203 } else if (context->IsCatchContext()) { 210 } else if (context->IsCatchContext()) {
204 // Catch contexts have the variable name in the extension slot. 211 // Catch contexts have the variable name in the extension slot.
205 if (name->Equals(String::cast(context->extension()))) { 212 if (name->Equals(String::cast(context->extension()))) {
206 if (FLAG_trace_contexts) { 213 if (FLAG_trace_contexts) {
207 PrintF("=> found in catch context\n"); 214 PrintF("=> found in catch context\n");
208 } 215 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 VariableMode mode; 255 VariableMode mode;
249 int index = scope_info->ContextSlotIndex(*name, &mode); 256 int index = scope_info->ContextSlotIndex(*name, &mode);
250 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); 257 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS);
251 if (index >= 0) return false; 258 if (index >= 0) return false;
252 259
253 // Check parameter locals. 260 // Check parameter locals.
254 int param_index = scope_info->ParameterIndex(*name); 261 int param_index = scope_info->ParameterIndex(*name);
255 if (param_index >= 0) return false; 262 if (param_index >= 0) return false;
256 263
257 // Check context only holding the function name variable. 264 // Check context only holding the function name variable.
258 index = scope_info->FunctionContextSlotIndex(*name); 265 index = scope_info->FunctionContextSlotIndex(*name, NULL);
259 if (index >= 0) return false; 266 if (index >= 0) return false;
260 context = context->previous(); 267 context = context->previous();
261 } 268 }
262 269
263 // No local or potential with statement found so the variable is 270 // No local or potential with statement found so the variable is
264 // global unless it is shadowed by an eval-introduced variable. 271 // global unless it is shadowed by an eval-introduced variable.
265 return true; 272 return true;
266 } 273 }
267 274
268 275
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 // During bootstrapping we allow all objects to pass as global 368 // During bootstrapping we allow all objects to pass as global
362 // objects. This is necessary to fix circular dependencies. 369 // objects. This is necessary to fix circular dependencies.
363 Isolate* isolate = Isolate::Current(); 370 Isolate* isolate = Isolate::Current();
364 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || 371 return isolate->heap()->gc_state() != Heap::NOT_IN_GC ||
365 isolate->bootstrapper()->IsActive() || 372 isolate->bootstrapper()->IsActive() ||
366 object->IsGlobalObject(); 373 object->IsGlobalObject();
367 } 374 }
368 #endif 375 #endif
369 376
370 } } // namespace v8::internal 377 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/contexts.h ('k') | src/full-codegen.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698