| 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 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 130 reinterpret_cast<void*>(*object)); | 130 reinterpret_cast<void*>(*object)); |
| 131 } | 131 } |
| 132 return object; | 132 return object; |
| 133 } | 133 } |
| 134 } | 134 } |
| 135 | 135 |
| 136 // 2. Check the context proper if it has slots. | 136 // 2. Check the context proper if it has slots. |
| 137 if (context->IsFunctionContext() || context->IsBlockContext()) { | 137 if (context->IsFunctionContext() || context->IsBlockContext()) { |
| 138 // Use serialized scope information of functions and blocks to search | 138 // Use serialized scope information of functions and blocks to search |
| 139 // for the context index. | 139 // for the context index. |
| 140 Handle<SerializedScopeInfo> scope_info; | 140 Handle<ScopeInfo> scope_info; |
| 141 if (context->IsFunctionContext()) { | 141 if (context->IsFunctionContext()) { |
| 142 scope_info = Handle<SerializedScopeInfo>( | 142 scope_info = Handle<ScopeInfo>( |
| 143 context->closure()->shared()->scope_info(), isolate); | 143 context->closure()->shared()->scope_info(), isolate); |
| 144 } else { | 144 } else { |
| 145 scope_info = Handle<SerializedScopeInfo>( | 145 scope_info = Handle<ScopeInfo>( |
| 146 SerializedScopeInfo::cast(context->extension()), isolate); | 146 ScopeInfo::cast(context->extension()), isolate); |
| 147 } | 147 } |
| 148 VariableMode mode; | 148 VariableMode mode; |
| 149 int slot_index = scope_info->ContextSlotIndex(*name, &mode); | 149 int slot_index = scope_info->ContextSlotIndex(*name, &mode); |
| 150 ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); | 150 ASSERT(slot_index < 0 || slot_index >= MIN_CONTEXT_SLOTS); |
| 151 if (slot_index >= 0) { | 151 if (slot_index >= 0) { |
| 152 if (FLAG_trace_contexts) { | 152 if (FLAG_trace_contexts) { |
| 153 PrintF("=> found local in context slot %d (mode = %d)\n", | 153 PrintF("=> found local in context slot %d (mode = %d)\n", |
| 154 slot_index, mode); | 154 slot_index, mode); |
| 155 } | 155 } |
| 156 *index = slot_index; | 156 *index = slot_index; |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 // extension objects (conservative check for with statements). | 243 // extension objects (conservative check for with statements). |
| 244 while (!context->IsGlobalContext()) { | 244 while (!context->IsGlobalContext()) { |
| 245 // Check if the context is a catch or with context, or has introduced | 245 // Check if the context is a catch or with context, or has introduced |
| 246 // bindings by calling non-strict eval. | 246 // bindings by calling non-strict eval. |
| 247 if (context->has_extension()) return false; | 247 if (context->has_extension()) return false; |
| 248 | 248 |
| 249 // Not a with context so it must be a function context. | 249 // Not a with context so it must be a function context. |
| 250 ASSERT(context->IsFunctionContext()); | 250 ASSERT(context->IsFunctionContext()); |
| 251 | 251 |
| 252 // Check non-parameter locals. | 252 // Check non-parameter locals. |
| 253 Handle<SerializedScopeInfo> scope_info( | 253 Handle<ScopeInfo> scope_info(context->closure()->shared()->scope_info()); |
| 254 context->closure()->shared()->scope_info()); | |
| 255 VariableMode mode; | 254 VariableMode mode; |
| 256 int index = scope_info->ContextSlotIndex(*name, &mode); | 255 int index = scope_info->ContextSlotIndex(*name, &mode); |
| 257 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); | 256 ASSERT(index < 0 || index >= MIN_CONTEXT_SLOTS); |
| 258 if (index >= 0) return false; | 257 if (index >= 0) return false; |
| 259 | 258 |
| 260 // Check parameter locals. | 259 // Check parameter locals. |
| 261 int param_index = scope_info->ParameterIndex(*name); | 260 int param_index = scope_info->ParameterIndex(*name); |
| 262 if (param_index >= 0) return false; | 261 if (param_index >= 0) return false; |
| 263 | 262 |
| 264 // Check context only holding the function name variable. | 263 // Check context only holding the function name variable. |
| 265 index = scope_info->FunctionContextSlotIndex(*name, NULL); | 264 index = scope_info->FunctionContextSlotIndex(*name, &mode); |
| 266 if (index >= 0) return false; | 265 if (index >= 0) return false; |
| 267 context = context->previous(); | 266 context = context->previous(); |
| 268 } | 267 } |
| 269 | 268 |
| 270 // No local or potential with statement found so the variable is | 269 // No local or potential with statement found so the variable is |
| 271 // global unless it is shadowed by an eval-introduced variable. | 270 // global unless it is shadowed by an eval-introduced variable. |
| 272 return true; | 271 return true; |
| 273 } | 272 } |
| 274 | 273 |
| 275 | 274 |
| 276 void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_non_strict_eval) { | 275 void Context::ComputeEvalScopeInfo(bool* outer_scope_calls_non_strict_eval) { |
| 277 // Skip up the context chain checking all the function contexts to see | 276 // Skip up the context chain checking all the function contexts to see |
| 278 // whether they call eval. | 277 // whether they call eval. |
| 279 Context* context = this; | 278 Context* context = this; |
| 280 while (!context->IsGlobalContext()) { | 279 while (!context->IsGlobalContext()) { |
| 281 if (context->IsFunctionContext()) { | 280 if (context->IsFunctionContext()) { |
| 282 Handle<SerializedScopeInfo> scope_info( | 281 if (context->closure()->shared()->scope_info()->CallsNonStrictEval()) { |
| 283 context->closure()->shared()->scope_info()); | |
| 284 if (scope_info->CallsEval() && !scope_info->IsStrictMode()) { | |
| 285 // No need to go further since the answers will not change from | 282 // No need to go further since the answers will not change from |
| 286 // here. | 283 // here. |
| 287 *outer_scope_calls_non_strict_eval = true; | 284 *outer_scope_calls_non_strict_eval = true; |
| 288 return; | 285 return; |
| 289 } | 286 } |
| 290 } | 287 } |
| 291 context = context->previous(); | 288 context = context->previous(); |
| 292 } | 289 } |
| 293 } | 290 } |
| 294 | 291 |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 // During bootstrapping we allow all objects to pass as global | 365 // During bootstrapping we allow all objects to pass as global |
| 369 // objects. This is necessary to fix circular dependencies. | 366 // objects. This is necessary to fix circular dependencies. |
| 370 Isolate* isolate = Isolate::Current(); | 367 Isolate* isolate = Isolate::Current(); |
| 371 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || | 368 return isolate->heap()->gc_state() != Heap::NOT_IN_GC || |
| 372 isolate->bootstrapper()->IsActive() || | 369 isolate->bootstrapper()->IsActive() || |
| 373 object->IsGlobalObject(); | 370 object->IsGlobalObject(); |
| 374 } | 371 } |
| 375 #endif | 372 #endif |
| 376 | 373 |
| 377 } } // namespace v8::internal | 374 } } // namespace v8::internal |
| OLD | NEW |