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 11206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11217 | 11217 |
11218 // Catch the case when the debugger stops in an internal function. | 11218 // Catch the case when the debugger stops in an internal function. |
11219 Handle<SharedFunctionInfo> shared_info(function_->shared()); | 11219 Handle<SharedFunctionInfo> shared_info(function_->shared()); |
11220 if (shared_info->script() == isolate->heap()->undefined_value()) { | 11220 if (shared_info->script() == isolate->heap()->undefined_value()) { |
11221 while (context_->closure() == *function_) { | 11221 while (context_->closure() == *function_) { |
11222 context_ = Handle<Context>(context_->previous(), isolate_); | 11222 context_ = Handle<Context>(context_->previous(), isolate_); |
11223 } | 11223 } |
11224 return; | 11224 return; |
11225 } | 11225 } |
11226 | 11226 |
11227 // Check whether we are in global code or function code. If there is a stack | |
11228 // slot for .result then this function has been created for evaluating | |
11229 // global code and it is not a real function. | |
11230 // Checking for the existence of .result seems fragile, but the scope info | |
11231 // saved with the code object does not otherwise have that information. | |
11232 int index = shared_info->scope_info()-> | |
11233 StackSlotIndex(isolate_->heap()->result_symbol()); | |
11234 | |
11235 // Reparse the code and analyze the scopes. | 11227 // Reparse the code and analyze the scopes. |
11236 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); | 11228 ZoneScope zone_scope(isolate, DELETE_ON_EXIT); |
11237 Handle<Script> script(Script::cast(shared_info->script())); | 11229 Handle<Script> script(Script::cast(shared_info->script())); |
11238 Scope* scope; | 11230 Scope* scope; |
11239 if (index >= 0) { | 11231 |
11240 // Global code | 11232 // Check whether we are in global, eval or function code. |
| 11233 Handle<ScopeInfo> scope_info(shared_info->scope_info()); |
| 11234 if (scope_info->Type() != FUNCTION_SCOPE) { |
| 11235 // Global or eval code. |
11241 CompilationInfo info(script); | 11236 CompilationInfo info(script); |
11242 info.MarkAsGlobal(); | 11237 if (scope_info->Type() == GLOBAL_SCOPE) { |
| 11238 info.MarkAsGlobal(); |
| 11239 } else { |
| 11240 ASSERT(scope_info->Type() == EVAL_SCOPE); |
| 11241 info.MarkAsEval(); |
| 11242 info.SetCallingContext(Handle<Context>(function_->context())); |
| 11243 } |
11243 CHECK(ParserApi::Parse(&info)); | 11244 CHECK(ParserApi::Parse(&info)); |
11244 CHECK(Scope::Analyze(&info)); | 11245 CHECK(Scope::Analyze(&info)); |
11245 scope = info.function()->scope(); | 11246 scope = info.function()->scope(); |
11246 } else { | 11247 } else { |
11247 // Function code | 11248 // Function code |
11248 CompilationInfo info(shared_info); | 11249 CompilationInfo info(shared_info); |
11249 CHECK(ParserApi::Parse(&info)); | 11250 CHECK(ParserApi::Parse(&info)); |
11250 CHECK(Scope::Analyze(&info)); | 11251 CHECK(Scope::Analyze(&info)); |
11251 scope = info.function()->scope(); | 11252 scope = info.function()->scope(); |
11252 } | 11253 } |
11253 | 11254 |
11254 // Retrieve the scope chain for the current position. | 11255 // Retrieve the scope chain for the current position. |
11255 int statement_position = | 11256 source_position_ = shared_info->code()->SourceStatementPosition(frame_->pc()
); |
11256 shared_info->code()->SourceStatementPosition(frame_->pc()); | 11257 scope->GetNestedScopeChain(&nested_scope_chain_, source_position_); |
11257 scope->GetNestedScopeChain(&nested_scope_chain_, statement_position); | |
11258 } | 11258 } |
11259 | 11259 |
11260 // More scopes? | 11260 // More scopes? |
11261 bool Done() { return context_.is_null(); } | 11261 bool Done() { return context_.is_null(); } |
11262 | 11262 |
11263 // Move to the next scope. | 11263 // Move to the next scope. |
11264 void Next() { | 11264 void Next() { |
11265 ScopeType scope_type = Type(); | 11265 ScopeType scope_type = Type(); |
11266 if (scope_type == ScopeTypeGlobal) { | 11266 if (scope_type == ScopeTypeGlobal) { |
11267 // The global scope is always the last in the chain. | 11267 // The global scope is always the last in the chain. |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11423 } | 11423 } |
11424 #endif | 11424 #endif |
11425 | 11425 |
11426 private: | 11426 private: |
11427 Isolate* isolate_; | 11427 Isolate* isolate_; |
11428 JavaScriptFrame* frame_; | 11428 JavaScriptFrame* frame_; |
11429 int inlined_frame_index_; | 11429 int inlined_frame_index_; |
11430 Handle<JSFunction> function_; | 11430 Handle<JSFunction> function_; |
11431 Handle<Context> context_; | 11431 Handle<Context> context_; |
11432 List<Handle<ScopeInfo> > nested_scope_chain_; | 11432 List<Handle<ScopeInfo> > nested_scope_chain_; |
| 11433 int source_position_; |
11433 | 11434 |
11434 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator); | 11435 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator); |
11435 }; | 11436 }; |
11436 | 11437 |
11437 | 11438 |
11438 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetScopeCount) { | 11439 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetScopeCount) { |
11439 HandleScope scope(isolate); | 11440 HandleScope scope(isolate); |
11440 ASSERT(args.length() == 2); | 11441 ASSERT(args.length() == 2); |
11441 | 11442 |
11442 // Check arguments. | 11443 // Check arguments. |
(...skipping 2094 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13537 } else { | 13538 } else { |
13538 // Handle last resort GC and make sure to allow future allocations | 13539 // Handle last resort GC and make sure to allow future allocations |
13539 // to grow the heap without causing GCs (if possible). | 13540 // to grow the heap without causing GCs (if possible). |
13540 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13541 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13541 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13542 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
13542 } | 13543 } |
13543 } | 13544 } |
13544 | 13545 |
13545 | 13546 |
13546 } } // namespace v8::internal | 13547 } } // namespace v8::internal |
OLD | NEW |