| OLD | NEW |
| 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 Loading... |
| 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 Loading... |
| 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 |
| 269 void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_eval, | 276 void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_non_strict_eval) { |
| 270 bool* outer_scope_calls_non_strict_eval) { | |
| 271 // Skip up the context chain checking all the function contexts to see | 277 // Skip up the context chain checking all the function contexts to see |
| 272 // whether they call eval. | 278 // whether they call eval. |
| 273 Context* context = this; | 279 Context* context = this; |
| 274 while (!context->IsGlobalContext()) { | 280 while (!context->IsGlobalContext()) { |
| 275 if (context->IsFunctionContext()) { | 281 if (context->IsFunctionContext()) { |
| 276 Handle<SerializedScopeInfo> scope_info( | 282 Handle<SerializedScopeInfo> scope_info( |
| 277 context->closure()->shared()->scope_info()); | 283 context->closure()->shared()->scope_info()); |
| 278 if (scope_info->CallsEval()) { | 284 if (scope_info->CallsEval() && !scope_info->IsStrictMode()) { |
| 279 *outer_scope_calls_eval = true; | 285 // No need to go further since the answers will not change from |
| 280 if (!scope_info->IsStrictMode()) { | 286 // here. |
| 281 // No need to go further since the answers will not change from | 287 *outer_scope_calls_non_strict_eval = true; |
| 282 // here. | 288 return; |
| 283 *outer_scope_calls_non_strict_eval = true; | |
| 284 return; | |
| 285 } | |
| 286 } | 289 } |
| 287 } | 290 } |
| 288 context = context->previous(); | 291 context = context->previous(); |
| 289 } | 292 } |
| 290 } | 293 } |
| 291 | 294 |
| 292 | 295 |
| 293 void Context::AddOptimizedFunction(JSFunction* function) { | 296 void Context::AddOptimizedFunction(JSFunction* function) { |
| 294 ASSERT(IsGlobalContext()); | 297 ASSERT(IsGlobalContext()); |
| 295 #ifdef DEBUG | 298 #ifdef DEBUG |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 365 // During bootstrapping we allow all objects to pass as global | 368 // During bootstrapping we allow all objects to pass as global |
| 366 // objects. This is necessary to fix circular dependencies. | 369 // objects. This is necessary to fix circular dependencies. |
| 367 Isolate* isolate = Isolate::Current(); | 370 Isolate* isolate = Isolate::Current(); |
| 368 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 371 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 369 isolate->bootstrapper()->IsActive() || | 372 isolate->bootstrapper()->IsActive() || |
| 370 object->IsGlobalObject(); | 373 object->IsGlobalObject(); |
| 371 } | 374 } |
| 372 #endif | 375 #endif |
| 373 | 376 |
| 374 } } // namespace v8::internal | 377 } } // namespace v8::internal |
| OLD | NEW |