| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 11463 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11474 | 11474 |
| 11475 // Clear all stepping set by PrepareStep. | 11475 // Clear all stepping set by PrepareStep. |
| 11476 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearStepping) { | 11476 RUNTIME_FUNCTION(MaybeObject*, Runtime_ClearStepping) { |
| 11477 HandleScope scope(isolate); | 11477 HandleScope scope(isolate); |
| 11478 ASSERT(args.length() == 0); | 11478 ASSERT(args.length() == 0); |
| 11479 isolate->debug()->ClearStepping(); | 11479 isolate->debug()->ClearStepping(); |
| 11480 return isolate->heap()->undefined_value(); | 11480 return isolate->heap()->undefined_value(); |
| 11481 } | 11481 } |
| 11482 | 11482 |
| 11483 | 11483 |
| 11484 static bool IsBlockOrCatchOrWithScope(ScopeIterator::ScopeType type) { |
| 11485 return type == ScopeIterator::ScopeTypeBlock || |
| 11486 type == ScopeIterator::ScopeTypeCatch || |
| 11487 type == ScopeIterator::ScopeTypeWith; |
| 11488 } |
| 11489 |
| 11490 |
| 11484 // Creates a copy of the with context chain. The copy of the context chain is | 11491 // Creates a copy of the with context chain. The copy of the context chain is |
| 11485 // is linked to the function context supplied. | 11492 // is linked to the function context supplied. |
| 11486 static Handle<Context> CopyNestedScopeContextChain(Isolate* isolate, | 11493 static Handle<Context> CopyNestedScopeContextChain(Isolate* isolate, |
| 11487 Handle<JSFunction> function, | 11494 Handle<JSFunction> function, |
| 11488 Handle<Context> base, | 11495 Handle<Context> base, |
| 11489 JavaScriptFrame* frame, | 11496 JavaScriptFrame* frame, |
| 11490 int inlined_jsframe_index) { | 11497 int inlined_jsframe_index) { |
| 11491 HandleScope scope(isolate); | 11498 HandleScope scope(isolate); |
| 11492 List<Handle<ScopeInfo> > scope_chain; | 11499 List<Handle<ScopeInfo> > scope_chain; |
| 11493 List<Handle<Context> > context_chain; | 11500 List<Handle<Context> > context_chain; |
| 11494 | 11501 |
| 11495 ScopeIterator it(isolate, frame, inlined_jsframe_index); | 11502 ScopeIterator it(isolate, frame, inlined_jsframe_index); |
| 11496 if (it.Failed()) return Handle<Context>::null(); | 11503 if (it.Failed()) return Handle<Context>::null(); |
| 11497 | 11504 |
| 11498 for (; it.Type() != ScopeIterator::ScopeTypeGlobal && | 11505 for ( ; IsBlockOrCatchOrWithScope(it.Type()); it.Next()) { |
| 11499 it.Type() != ScopeIterator::ScopeTypeLocal ; it.Next()) { | |
| 11500 ASSERT(!it.Done()); | 11506 ASSERT(!it.Done()); |
| 11501 scope_chain.Add(it.CurrentScopeInfo()); | 11507 scope_chain.Add(it.CurrentScopeInfo()); |
| 11502 context_chain.Add(it.CurrentContext()); | 11508 context_chain.Add(it.CurrentContext()); |
| 11503 } | 11509 } |
| 11504 | 11510 |
| 11505 // At the end of the chain. Return the base context to link to. | 11511 // At the end of the chain. Return the base context to link to. |
| 11506 Handle<Context> context = base; | 11512 Handle<Context> context = base; |
| 11507 | 11513 |
| 11508 // Iteratively copy and or materialize the nested contexts. | 11514 // Iteratively copy and or materialize the nested contexts. |
| 11509 while (!scope_chain.is_empty()) { | 11515 while (!scope_chain.is_empty()) { |
| 11510 Handle<ScopeInfo> scope_info = scope_chain.RemoveLast(); | 11516 Handle<ScopeInfo> scope_info = scope_chain.RemoveLast(); |
| 11511 Handle<Context> current = context_chain.RemoveLast(); | 11517 Handle<Context> current = context_chain.RemoveLast(); |
| 11512 ASSERT(!(scope_info->HasContext() & current.is_null())); | 11518 ASSERT(!(scope_info->HasContext() & current.is_null())); |
| 11513 | 11519 |
| 11514 if (scope_info->Type() == CATCH_SCOPE) { | 11520 if (scope_info->Type() == CATCH_SCOPE) { |
| 11521 ASSERT(current->IsCatchContext()); |
| 11515 Handle<String> name(String::cast(current->extension())); | 11522 Handle<String> name(String::cast(current->extension())); |
| 11516 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX), | 11523 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX), |
| 11517 isolate); | 11524 isolate); |
| 11518 context = | 11525 context = |
| 11519 isolate->factory()->NewCatchContext(function, | 11526 isolate->factory()->NewCatchContext(function, |
| 11520 context, | 11527 context, |
| 11521 name, | 11528 name, |
| 11522 thrown_object); | 11529 thrown_object); |
| 11523 } else if (scope_info->Type() == BLOCK_SCOPE) { | 11530 } else if (scope_info->Type() == BLOCK_SCOPE) { |
| 11524 // Materialize the contents of the block scope into a JSObject. | 11531 // Materialize the contents of the block scope into a JSObject. |
| 11532 ASSERT(current->IsBlockContext()); |
| 11525 Handle<JSObject> block_scope_object = | 11533 Handle<JSObject> block_scope_object = |
| 11526 MaterializeBlockScope(isolate, current); | 11534 MaterializeBlockScope(isolate, current); |
| 11527 CHECK(!block_scope_object.is_null()); | 11535 CHECK(!block_scope_object.is_null()); |
| 11528 // Allocate a new function context for the debug evaluation and set the | 11536 // Allocate a new function context for the debug evaluation and set the |
| 11529 // extension object. | 11537 // extension object. |
| 11530 Handle<Context> new_context = | 11538 Handle<Context> new_context = |
| 11531 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, | 11539 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, |
| 11532 function); | 11540 function); |
| 11533 new_context->set_extension(*block_scope_object); | 11541 new_context->set_extension(*block_scope_object); |
| 11534 new_context->set_previous(*context); | 11542 new_context->set_previous(*context); |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11681 Handle<ScopeInfo> go_between_scope_info(go_between->shared()->scope_info()); | 11689 Handle<ScopeInfo> go_between_scope_info(go_between->shared()->scope_info()); |
| 11682 ASSERT(go_between_scope_info->ParameterCount() == 0); | 11690 ASSERT(go_between_scope_info->ParameterCount() == 0); |
| 11683 ASSERT(go_between_scope_info->ContextLocalCount() == 0); | 11691 ASSERT(go_between_scope_info->ContextLocalCount() == 0); |
| 11684 #endif | 11692 #endif |
| 11685 | 11693 |
| 11686 // Materialize the content of the local scope including the arguments object. | 11694 // Materialize the content of the local scope including the arguments object. |
| 11687 Handle<JSObject> local_scope = MaterializeLocalScopeWithFrameInspector( | 11695 Handle<JSObject> local_scope = MaterializeLocalScopeWithFrameInspector( |
| 11688 isolate, frame, &frame_inspector); | 11696 isolate, frame, &frame_inspector); |
| 11689 RETURN_IF_EMPTY_HANDLE(isolate, local_scope); | 11697 RETURN_IF_EMPTY_HANDLE(isolate, local_scope); |
| 11690 | 11698 |
| 11691 Handle<Context> frame_context(Context::cast(frame->context())); | 11699 // Do not materialize the arguments object for eval or top-level code. |
| 11692 Handle<Context> function_context; | 11700 if (function->shared()->is_function()) { |
| 11693 Handle<ScopeInfo> scope_info(function->shared()->scope_info()); | 11701 Handle<Context> frame_context(Context::cast(frame->context())); |
| 11694 if (scope_info->HasContext()) { | 11702 Handle<Context> function_context; |
| 11695 function_context = Handle<Context>(frame_context->declaration_context()); | 11703 Handle<ScopeInfo> scope_info(function->shared()->scope_info()); |
| 11704 if (scope_info->HasContext()) { |
| 11705 function_context = Handle<Context>(frame_context->declaration_context()); |
| 11706 } |
| 11707 Handle<Object> arguments = GetArgumentsObject(isolate, |
| 11708 frame, |
| 11709 &frame_inspector, |
| 11710 scope_info, |
| 11711 function_context); |
| 11712 SetProperty(isolate, |
| 11713 local_scope, |
| 11714 isolate->factory()->arguments_string(), |
| 11715 arguments, |
| 11716 ::NONE, |
| 11717 kNonStrictMode); |
| 11696 } | 11718 } |
| 11697 Handle<Object> arguments = GetArgumentsObject(isolate, | |
| 11698 frame, | |
| 11699 &frame_inspector, | |
| 11700 scope_info, | |
| 11701 function_context); | |
| 11702 SetProperty(isolate, | |
| 11703 local_scope, | |
| 11704 isolate->factory()->arguments_string(), | |
| 11705 arguments, | |
| 11706 ::NONE, | |
| 11707 kNonStrictMode); | |
| 11708 | 11719 |
| 11709 // Allocate a new context for the debug evaluation and set the extension | 11720 // Allocate a new context for the debug evaluation and set the extension |
| 11710 // object build. | 11721 // object build. |
| 11711 Handle<Context> context = isolate->factory()->NewFunctionContext( | 11722 Handle<Context> context = isolate->factory()->NewFunctionContext( |
| 11712 Context::MIN_CONTEXT_SLOTS, go_between); | 11723 Context::MIN_CONTEXT_SLOTS, go_between); |
| 11713 | 11724 |
| 11714 // Use the materialized local scope in a with context. | 11725 // Use the materialized local scope in a with context. |
| 11715 context = | 11726 context = |
| 11716 isolate->factory()->NewWithContext(go_between, context, local_scope); | 11727 isolate->factory()->NewWithContext(go_between, context, local_scope); |
| 11717 | 11728 |
| (...skipping 1284 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13002 // Handle last resort GC and make sure to allow future allocations | 13013 // Handle last resort GC and make sure to allow future allocations |
| 13003 // to grow the heap without causing GCs (if possible). | 13014 // to grow the heap without causing GCs (if possible). |
| 13004 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13015 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13005 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13016 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13006 "Runtime::PerformGC"); | 13017 "Runtime::PerformGC"); |
| 13007 } | 13018 } |
| 13008 } | 13019 } |
| 13009 | 13020 |
| 13010 | 13021 |
| 13011 } } // namespace v8::internal | 13022 } } // namespace v8::internal |
| OLD | NEW |