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 10570 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10581 receiver = | 10581 receiver = |
10582 isolate->factory()->ToObject(receiver, calling_frames_native_context); | 10582 isolate->factory()->ToObject(receiver, calling_frames_native_context); |
10583 } | 10583 } |
10584 details->set(kFrameDetailsReceiverIndex, *receiver); | 10584 details->set(kFrameDetailsReceiverIndex, *receiver); |
10585 | 10585 |
10586 ASSERT_EQ(details_size, details_index); | 10586 ASSERT_EQ(details_size, details_index); |
10587 return *isolate->factory()->NewJSArrayWithElements(details); | 10587 return *isolate->factory()->NewJSArrayWithElements(details); |
10588 } | 10588 } |
10589 | 10589 |
10590 | 10590 |
| 10591 // Copy all the context locals into an object used to materialize a scope. |
| 10592 static bool CopyContextLocalsToScopeObject( |
| 10593 Isolate* isolate, |
| 10594 Handle<ScopeInfo> scope_info, |
| 10595 Handle<Context> context, |
| 10596 Handle<JSObject> scope_object) { |
| 10597 // Fill all context locals to the context extension. |
| 10598 for (int i = 0; i < scope_info->ContextLocalCount(); i++) { |
| 10599 VariableMode mode; |
| 10600 InitializationFlag init_flag; |
| 10601 int context_index = scope_info->ContextSlotIndex( |
| 10602 scope_info->ContextLocalName(i), &mode, &init_flag); |
| 10603 |
| 10604 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 10605 isolate, |
| 10606 SetProperty(isolate, |
| 10607 scope_object, |
| 10608 Handle<String>(scope_info->ContextLocalName(i)), |
| 10609 Handle<Object>(context->get(context_index), isolate), |
| 10610 NONE, |
| 10611 kNonStrictMode), |
| 10612 false); |
| 10613 } |
| 10614 |
| 10615 return true; |
| 10616 } |
| 10617 |
| 10618 |
10591 // Create a plain JSObject which materializes the local scope for the specified | 10619 // Create a plain JSObject which materializes the local scope for the specified |
10592 // frame. | 10620 // frame. |
10593 static Handle<JSObject> MaterializeLocalScopeWithFrameInspector( | 10621 static Handle<JSObject> MaterializeLocalScopeWithFrameInspector( |
10594 Isolate* isolate, | 10622 Isolate* isolate, |
10595 JavaScriptFrame* frame, | 10623 JavaScriptFrame* frame, |
10596 FrameInspector* frame_inspector) { | 10624 FrameInspector* frame_inspector) { |
10597 Handle<JSFunction> function(JSFunction::cast(frame_inspector->GetFunction())); | 10625 Handle<JSFunction> function(JSFunction::cast(frame_inspector->GetFunction())); |
10598 Handle<SharedFunctionInfo> shared(function->shared()); | 10626 Handle<SharedFunctionInfo> shared(function->shared()); |
10599 Handle<ScopeInfo> scope_info(shared->scope_info()); | 10627 Handle<ScopeInfo> scope_info(shared->scope_info()); |
10600 | 10628 |
(...skipping 29 matching lines...) Expand all Loading... |
10630 Handle<Object>(frame_inspector->GetExpression(i)), | 10658 Handle<Object>(frame_inspector->GetExpression(i)), |
10631 NONE, | 10659 NONE, |
10632 kNonStrictMode), | 10660 kNonStrictMode), |
10633 Handle<JSObject>()); | 10661 Handle<JSObject>()); |
10634 } | 10662 } |
10635 | 10663 |
10636 if (scope_info->HasContext()) { | 10664 if (scope_info->HasContext()) { |
10637 // Third fill all context locals. | 10665 // Third fill all context locals. |
10638 Handle<Context> frame_context(Context::cast(frame->context())); | 10666 Handle<Context> frame_context(Context::cast(frame->context())); |
10639 Handle<Context> function_context(frame_context->declaration_context()); | 10667 Handle<Context> function_context(frame_context->declaration_context()); |
10640 if (!scope_info->CopyContextLocalsToScopeObject( | 10668 if (!CopyContextLocalsToScopeObject( |
10641 isolate, function_context, local_scope)) { | 10669 isolate, scope_info, function_context, local_scope)) { |
10642 return Handle<JSObject>(); | 10670 return Handle<JSObject>(); |
10643 } | 10671 } |
10644 | 10672 |
10645 // Finally copy any properties from the function context extension. | 10673 // Finally copy any properties from the function context extension. |
10646 // These will be variables introduced by eval. | 10674 // These will be variables introduced by eval. |
10647 if (function_context->closure() == *function) { | 10675 if (function_context->closure() == *function) { |
10648 if (function_context->has_extension() && | 10676 if (function_context->has_extension() && |
10649 !function_context->IsNativeContext()) { | 10677 !function_context->IsNativeContext()) { |
10650 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 10678 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
10651 bool threw = false; | 10679 bool threw = false; |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10783 | 10811 |
10784 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 10812 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
10785 Handle<ScopeInfo> scope_info(shared->scope_info()); | 10813 Handle<ScopeInfo> scope_info(shared->scope_info()); |
10786 | 10814 |
10787 // Allocate and initialize a JSObject with all the content of this function | 10815 // Allocate and initialize a JSObject with all the content of this function |
10788 // closure. | 10816 // closure. |
10789 Handle<JSObject> closure_scope = | 10817 Handle<JSObject> closure_scope = |
10790 isolate->factory()->NewJSObject(isolate->object_function()); | 10818 isolate->factory()->NewJSObject(isolate->object_function()); |
10791 | 10819 |
10792 // Fill all context locals to the context extension. | 10820 // Fill all context locals to the context extension. |
10793 if (!scope_info->CopyContextLocalsToScopeObject( | 10821 if (!CopyContextLocalsToScopeObject( |
10794 isolate, context, closure_scope)) { | 10822 isolate, scope_info, context, closure_scope)) { |
10795 return Handle<JSObject>(); | 10823 return Handle<JSObject>(); |
10796 } | 10824 } |
10797 | 10825 |
10798 // Finally copy any properties from the function context extension. This will | 10826 // Finally copy any properties from the function context extension. This will |
10799 // be variables introduced by eval. | 10827 // be variables introduced by eval. |
10800 if (context->has_extension()) { | 10828 if (context->has_extension()) { |
10801 Handle<JSObject> ext(JSObject::cast(context->extension())); | 10829 Handle<JSObject> ext(JSObject::cast(context->extension())); |
10802 bool threw = false; | 10830 bool threw = false; |
10803 Handle<FixedArray> keys = | 10831 Handle<FixedArray> keys = |
10804 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); | 10832 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10903 Handle<Context> context) { | 10931 Handle<Context> context) { |
10904 ASSERT(context->IsBlockContext()); | 10932 ASSERT(context->IsBlockContext()); |
10905 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 10933 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
10906 | 10934 |
10907 // Allocate and initialize a JSObject with all the arguments, stack locals | 10935 // Allocate and initialize a JSObject with all the arguments, stack locals |
10908 // heap locals and extension properties of the debugged function. | 10936 // heap locals and extension properties of the debugged function. |
10909 Handle<JSObject> block_scope = | 10937 Handle<JSObject> block_scope = |
10910 isolate->factory()->NewJSObject(isolate->object_function()); | 10938 isolate->factory()->NewJSObject(isolate->object_function()); |
10911 | 10939 |
10912 // Fill all context locals. | 10940 // Fill all context locals. |
10913 if (!scope_info->CopyContextLocalsToScopeObject( | 10941 if (!CopyContextLocalsToScopeObject( |
10914 isolate, context, block_scope)) { | 10942 isolate, scope_info, context, block_scope)) { |
10915 return Handle<JSObject>(); | 10943 return Handle<JSObject>(); |
10916 } | 10944 } |
10917 | 10945 |
10918 return block_scope; | 10946 return block_scope; |
10919 } | 10947 } |
10920 | 10948 |
10921 | 10949 |
10922 // Create a plain JSObject which materializes the module scope for the specified | 10950 // Create a plain JSObject which materializes the module scope for the specified |
10923 // module context. | 10951 // module context. |
10924 static Handle<JSObject> MaterializeModuleScope( | 10952 static Handle<JSObject> MaterializeModuleScope( |
10925 Isolate* isolate, | 10953 Isolate* isolate, |
10926 Handle<Context> context) { | 10954 Handle<Context> context) { |
10927 ASSERT(context->IsModuleContext()); | 10955 ASSERT(context->IsModuleContext()); |
10928 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 10956 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
10929 | 10957 |
10930 // Allocate and initialize a JSObject with all the members of the debugged | 10958 // Allocate and initialize a JSObject with all the members of the debugged |
10931 // module. | 10959 // module. |
10932 Handle<JSObject> module_scope = | 10960 Handle<JSObject> module_scope = |
10933 isolate->factory()->NewJSObject(isolate->object_function()); | 10961 isolate->factory()->NewJSObject(isolate->object_function()); |
10934 | 10962 |
10935 // Fill all context locals. | 10963 // Fill all context locals. |
10936 if (!scope_info->CopyContextLocalsToScopeObject( | 10964 if (!CopyContextLocalsToScopeObject( |
10937 isolate, context, module_scope)) { | 10965 isolate, scope_info, context, module_scope)) { |
10938 return Handle<JSObject>(); | 10966 return Handle<JSObject>(); |
10939 } | 10967 } |
10940 | 10968 |
10941 return module_scope; | 10969 return module_scope; |
10942 } | 10970 } |
10943 | 10971 |
10944 | 10972 |
10945 // Iterate over the actual scopes visible from a stack frame or from a closure. | 10973 // Iterate over the actual scopes visible from a stack frame or from a closure. |
10946 // The iteration proceeds from the innermost visible nested scope outwards. | 10974 // The iteration proceeds from the innermost visible nested scope outwards. |
10947 // All scopes are backed by an actual context except the local scope, | 10975 // All scopes are backed by an actual context except the local scope, |
(...skipping 2379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13327 // Handle last resort GC and make sure to allow future allocations | 13355 // Handle last resort GC and make sure to allow future allocations |
13328 // to grow the heap without causing GCs (if possible). | 13356 // to grow the heap without causing GCs (if possible). |
13329 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13357 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13330 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13358 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13331 "Runtime::PerformGC"); | 13359 "Runtime::PerformGC"); |
13332 } | 13360 } |
13333 } | 13361 } |
13334 | 13362 |
13335 | 13363 |
13336 } } // namespace v8::internal | 13364 } } // namespace v8::internal |
OLD | NEW |