| 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 7953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7964 | 7964 |
| 7965 // Loop over the actual parameters backwards. | 7965 // Loop over the actual parameters backwards. |
| 7966 int index = argument_count - 1; | 7966 int index = argument_count - 1; |
| 7967 while (index >= mapped_count) { | 7967 while (index >= mapped_count) { |
| 7968 // These go directly in the arguments array and have no | 7968 // These go directly in the arguments array and have no |
| 7969 // corresponding slot in the parameter map. | 7969 // corresponding slot in the parameter map. |
| 7970 arguments->set(index, *(parameters - index - 1)); | 7970 arguments->set(index, *(parameters - index - 1)); |
| 7971 --index; | 7971 --index; |
| 7972 } | 7972 } |
| 7973 | 7973 |
| 7974 ScopeInfo<> scope_info(callee->shared()->scope_info()); | 7974 Handle<ScopeInfo> scope_info(callee->shared()->scope_info()); |
| 7975 while (index >= 0) { | 7975 while (index >= 0) { |
| 7976 // Detect duplicate names to the right in the parameter list. | 7976 // Detect duplicate names to the right in the parameter list. |
| 7977 Handle<String> name = scope_info.parameter_name(index); | 7977 Handle<String> name(scope_info->ParameterName(index)); |
| 7978 int context_slot_count = scope_info.number_of_context_slots(); | 7978 int context_local_count = scope_info->NumContextLocals(); |
| 7979 bool duplicate = false; | 7979 bool duplicate = false; |
| 7980 for (int j = index + 1; j < parameter_count; ++j) { | 7980 for (int j = index + 1; j < parameter_count; ++j) { |
| 7981 if (scope_info.parameter_name(j).is_identical_to(name)) { | 7981 if (scope_info->ParameterName(j) == *name) { |
| 7982 duplicate = true; | 7982 duplicate = true; |
| 7983 break; | 7983 break; |
| 7984 } | 7984 } |
| 7985 } | 7985 } |
| 7986 | 7986 |
| 7987 if (duplicate) { | 7987 if (duplicate) { |
| 7988 // This goes directly in the arguments array with a hole in the | 7988 // This goes directly in the arguments array with a hole in the |
| 7989 // parameter map. | 7989 // parameter map. |
| 7990 arguments->set(index, *(parameters - index - 1)); | 7990 arguments->set(index, *(parameters - index - 1)); |
| 7991 parameter_map->set_the_hole(index + 2); | 7991 parameter_map->set_the_hole(index + 2); |
| 7992 } else { | 7992 } else { |
| 7993 // The context index goes in the parameter map with a hole in the | 7993 // The context index goes in the parameter map with a hole in the |
| 7994 // arguments array. | 7994 // arguments array. |
| 7995 int context_index = -1; | 7995 int context_index = -1; |
| 7996 for (int j = Context::MIN_CONTEXT_SLOTS; | 7996 for (int j = 0; j < context_local_count; ++j) { |
| 7997 j < context_slot_count; | 7997 if (scope_info->ContextLocalName(j) == *name) { |
| 7998 ++j) { | |
| 7999 if (scope_info.context_slot_name(j).is_identical_to(name)) { | |
| 8000 context_index = j; | 7998 context_index = j; |
| 8001 break; | 7999 break; |
| 8002 } | 8000 } |
| 8003 } | 8001 } |
| 8004 ASSERT(context_index >= 0); | 8002 ASSERT(context_index >= 0); |
| 8005 arguments->set_the_hole(index); | 8003 arguments->set_the_hole(index); |
| 8006 parameter_map->set(index + 2, Smi::FromInt(context_index)); | 8004 parameter_map->set(index + 2, Smi::FromInt( |
| 8005 Context::MIN_CONTEXT_SLOTS + context_index)); |
| 8007 } | 8006 } |
| 8008 | 8007 |
| 8009 --index; | 8008 --index; |
| 8010 } | 8009 } |
| 8011 } else { | 8010 } else { |
| 8012 // If there is no aliasing, the arguments object elements are not | 8011 // If there is no aliasing, the arguments object elements are not |
| 8013 // special in any way. | 8012 // special in any way. |
| 8014 Handle<FixedArray> elements = | 8013 Handle<FixedArray> elements = |
| 8015 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED); | 8014 isolate->factory()->NewFixedArray(argument_count, NOT_TENURED); |
| 8016 result->set_elements(*elements); | 8015 result->set_elements(*elements); |
| (...skipping 740 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8757 RUNTIME_ASSERT(!args[0]->IsJSFunction()); | 8756 RUNTIME_ASSERT(!args[0]->IsJSFunction()); |
| 8758 return *Execution::GetConstructorDelegate(args.at<Object>(0)); | 8757 return *Execution::GetConstructorDelegate(args.at<Object>(0)); |
| 8759 } | 8758 } |
| 8760 | 8759 |
| 8761 | 8760 |
| 8762 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewFunctionContext) { | 8761 RUNTIME_FUNCTION(MaybeObject*, Runtime_NewFunctionContext) { |
| 8763 NoHandleAllocation ha; | 8762 NoHandleAllocation ha; |
| 8764 ASSERT(args.length() == 1); | 8763 ASSERT(args.length() == 1); |
| 8765 | 8764 |
| 8766 CONVERT_CHECKED(JSFunction, function, args[0]); | 8765 CONVERT_CHECKED(JSFunction, function, args[0]); |
| 8767 int length = function->shared()->scope_info()->NumberOfContextSlots(); | 8766 int length = function->shared()->scope_info()->ContextLength(); |
| 8768 Object* result; | 8767 Object* result; |
| 8769 { MaybeObject* maybe_result = | 8768 { MaybeObject* maybe_result = |
| 8770 isolate->heap()->AllocateFunctionContext(length, function); | 8769 isolate->heap()->AllocateFunctionContext(length, function); |
| 8771 if (!maybe_result->ToObject(&result)) return maybe_result; | 8770 if (!maybe_result->ToObject(&result)) return maybe_result; |
| 8772 } | 8771 } |
| 8773 | 8772 |
| 8774 isolate->set_context(Context::cast(result)); | 8773 isolate->set_context(Context::cast(result)); |
| 8775 | 8774 |
| 8776 return result; // non-failure | 8775 return result; // non-failure |
| 8777 } | 8776 } |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8843 thrown_object); | 8842 thrown_object); |
| 8844 if (!maybe_context->To(&context)) return maybe_context; | 8843 if (!maybe_context->To(&context)) return maybe_context; |
| 8845 isolate->set_context(context); | 8844 isolate->set_context(context); |
| 8846 return context; | 8845 return context; |
| 8847 } | 8846 } |
| 8848 | 8847 |
| 8849 | 8848 |
| 8850 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) { | 8849 RUNTIME_FUNCTION(MaybeObject*, Runtime_PushBlockContext) { |
| 8851 NoHandleAllocation ha; | 8850 NoHandleAllocation ha; |
| 8852 ASSERT(args.length() == 2); | 8851 ASSERT(args.length() == 2); |
| 8853 SerializedScopeInfo* scope_info = SerializedScopeInfo::cast(args[0]); | 8852 ScopeInfo* scope_info = ScopeInfo::cast(args[0]); |
| 8854 JSFunction* function; | 8853 JSFunction* function; |
| 8855 if (args[1]->IsSmi()) { | 8854 if (args[1]->IsSmi()) { |
| 8856 // A smi sentinel indicates a context nested inside global code rather | 8855 // A smi sentinel indicates a context nested inside global code rather |
| 8857 // than some function. There is a canonical empty function that can be | 8856 // than some function. There is a canonical empty function that can be |
| 8858 // gotten from the global context. | 8857 // gotten from the global context. |
| 8859 function = isolate->context()->global_context()->closure(); | 8858 function = isolate->context()->global_context()->closure(); |
| 8860 } else { | 8859 } else { |
| 8861 function = JSFunction::cast(args[1]); | 8860 function = JSFunction::cast(args[1]); |
| 8862 } | 8861 } |
| 8863 Context* context; | 8862 Context* context; |
| (...skipping 1899 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10763 it.frame()->LookupCode()->SourcePosition(it.frame()->pc()); | 10762 it.frame()->LookupCode()->SourcePosition(it.frame()->pc()); |
| 10764 | 10763 |
| 10765 // Check for constructor frame. Inlined frames cannot be construct calls. | 10764 // Check for constructor frame. Inlined frames cannot be construct calls. |
| 10766 bool inlined_frame = | 10765 bool inlined_frame = |
| 10767 it.frame()->is_optimized() && inlined_frame_index != 0; | 10766 it.frame()->is_optimized() && inlined_frame_index != 0; |
| 10768 bool constructor = !inlined_frame && it.frame()->IsConstructor(); | 10767 bool constructor = !inlined_frame && it.frame()->IsConstructor(); |
| 10769 | 10768 |
| 10770 // Get scope info and read from it for local variable information. | 10769 // Get scope info and read from it for local variable information. |
| 10771 Handle<JSFunction> function(JSFunction::cast(it.frame()->function())); | 10770 Handle<JSFunction> function(JSFunction::cast(it.frame()->function())); |
| 10772 Handle<SharedFunctionInfo> shared(function->shared()); | 10771 Handle<SharedFunctionInfo> shared(function->shared()); |
| 10773 Handle<SerializedScopeInfo> scope_info(shared->scope_info()); | 10772 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 10774 ASSERT(*scope_info != SerializedScopeInfo::Empty()); | 10773 ASSERT(*scope_info != ScopeInfo::Empty()); |
| 10775 ScopeInfo<> info(*scope_info); | |
| 10776 | 10774 |
| 10777 // Get the locals names and values into a temporary array. | 10775 // Get the locals names and values into a temporary array. |
| 10778 // | 10776 // |
| 10779 // TODO(1240907): Hide compiler-introduced stack variables | 10777 // TODO(1240907): Hide compiler-introduced stack variables |
| 10780 // (e.g. .result)? For users of the debugger, they will probably be | 10778 // (e.g. .result)? For users of the debugger, they will probably be |
| 10781 // confusing. | 10779 // confusing. |
| 10782 Handle<FixedArray> locals = | 10780 Handle<FixedArray> locals = |
| 10783 isolate->factory()->NewFixedArray(info.NumberOfLocals() * 2); | 10781 isolate->factory()->NewFixedArray(scope_info->NumberOfLocals() * 2); |
| 10784 | 10782 |
| 10785 // Fill in the values of the locals. | 10783 // Fill in the values of the locals. |
| 10786 int i = 0; | 10784 int i = 0; |
| 10787 for (; i < info.number_of_stack_slots(); ++i) { | 10785 for (; i < scope_info->NumStackLocals(); ++i) { |
| 10788 // Use the value from the stack. | 10786 // Use the value from the stack. |
| 10789 locals->set(i * 2, *info.LocalName(i)); | 10787 locals->set(i * 2, scope_info->LocalName(i)); |
| 10790 locals->set(i * 2 + 1, frame_inspector.GetExpression(i)); | 10788 locals->set(i * 2 + 1, frame_inspector.GetExpression(i)); |
| 10791 } | 10789 } |
| 10792 if (i < info.NumberOfLocals()) { | 10790 if (i < scope_info->NumberOfLocals()) { |
| 10793 // Get the context containing declarations. | 10791 // Get the context containing declarations. |
| 10794 Handle<Context> context( | 10792 Handle<Context> context( |
| 10795 Context::cast(it.frame()->context())->declaration_context()); | 10793 Context::cast(it.frame()->context())->declaration_context()); |
| 10796 for (; i < info.NumberOfLocals(); ++i) { | 10794 for (; i < scope_info->NumberOfLocals(); ++i) { |
| 10797 Handle<String> name = info.LocalName(i); | 10795 String* name = scope_info->LocalName(i); |
| 10798 locals->set(i * 2, *name); | 10796 VariableMode mode; |
| 10797 locals->set(i * 2, name); |
| 10799 locals->set(i * 2 + 1, | 10798 locals->set(i * 2 + 1, |
| 10800 context->get(scope_info->ContextSlotIndex(*name, NULL))); | 10799 context->get(scope_info->ContextSlotIndex(name, &mode))); |
| 10801 } | 10800 } |
| 10802 } | 10801 } |
| 10803 | 10802 |
| 10804 // Check whether this frame is positioned at return. If not top | 10803 // Check whether this frame is positioned at return. If not top |
| 10805 // frame or if the frame is optimized it cannot be at a return. | 10804 // frame or if the frame is optimized it cannot be at a return. |
| 10806 bool at_return = false; | 10805 bool at_return = false; |
| 10807 if (!it.frame()->is_optimized() && index == 0) { | 10806 if (!it.frame()->is_optimized() && index == 0) { |
| 10808 at_return = isolate->debug()->IsBreakAtReturn(it.frame()); | 10807 at_return = isolate->debug()->IsBreakAtReturn(it.frame()); |
| 10809 } | 10808 } |
| 10810 | 10809 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10844 // the provided parameters whereas the function frame always have the number | 10843 // the provided parameters whereas the function frame always have the number |
| 10845 // of arguments matching the functions parameters. The rest of the | 10844 // of arguments matching the functions parameters. The rest of the |
| 10846 // information (except for what is collected above) is the same. | 10845 // information (except for what is collected above) is the same. |
| 10847 if (it.frame()->has_adapted_arguments()) { | 10846 if (it.frame()->has_adapted_arguments()) { |
| 10848 it.AdvanceToArgumentsFrame(); | 10847 it.AdvanceToArgumentsFrame(); |
| 10849 frame_inspector.SetArgumentsFrame(it.frame()); | 10848 frame_inspector.SetArgumentsFrame(it.frame()); |
| 10850 } | 10849 } |
| 10851 | 10850 |
| 10852 // Find the number of arguments to fill. At least fill the number of | 10851 // Find the number of arguments to fill. At least fill the number of |
| 10853 // parameters for the function and fill more if more parameters are provided. | 10852 // parameters for the function and fill more if more parameters are provided. |
| 10854 int argument_count = info.number_of_parameters(); | 10853 int argument_count = scope_info->NumParameters(); |
| 10855 if (argument_count < frame_inspector.GetParametersCount()) { | 10854 if (argument_count < frame_inspector.GetParametersCount()) { |
| 10856 argument_count = frame_inspector.GetParametersCount(); | 10855 argument_count = frame_inspector.GetParametersCount(); |
| 10857 } | 10856 } |
| 10858 #ifdef DEBUG | 10857 #ifdef DEBUG |
| 10859 if (it.frame()->is_optimized()) { | 10858 if (it.frame()->is_optimized()) { |
| 10860 ASSERT_EQ(argument_count, frame_inspector.GetParametersCount()); | 10859 ASSERT_EQ(argument_count, frame_inspector.GetParametersCount()); |
| 10861 } | 10860 } |
| 10862 #endif | 10861 #endif |
| 10863 | 10862 |
| 10864 // Calculate the size of the result. | 10863 // Calculate the size of the result. |
| 10865 int details_size = kFrameDetailsFirstDynamicIndex + | 10864 int details_size = kFrameDetailsFirstDynamicIndex + |
| 10866 2 * (argument_count + info.NumberOfLocals()) + | 10865 2 * (argument_count + scope_info->NumberOfLocals()) + |
| 10867 (at_return ? 1 : 0); | 10866 (at_return ? 1 : 0); |
| 10868 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); | 10867 Handle<FixedArray> details = isolate->factory()->NewFixedArray(details_size); |
| 10869 | 10868 |
| 10870 // Add the frame id. | 10869 // Add the frame id. |
| 10871 details->set(kFrameDetailsFrameIdIndex, *frame_id); | 10870 details->set(kFrameDetailsFrameIdIndex, *frame_id); |
| 10872 | 10871 |
| 10873 // Add the function (same as in function frame). | 10872 // Add the function (same as in function frame). |
| 10874 details->set(kFrameDetailsFunctionIndex, frame_inspector.GetFunction()); | 10873 details->set(kFrameDetailsFunctionIndex, frame_inspector.GetFunction()); |
| 10875 | 10874 |
| 10876 // Add the arguments count. | 10875 // Add the arguments count. |
| 10877 details->set(kFrameDetailsArgumentCountIndex, Smi::FromInt(argument_count)); | 10876 details->set(kFrameDetailsArgumentCountIndex, Smi::FromInt(argument_count)); |
| 10878 | 10877 |
| 10879 // Add the locals count | 10878 // Add the locals count |
| 10880 details->set(kFrameDetailsLocalCountIndex, | 10879 details->set(kFrameDetailsLocalCountIndex, |
| 10881 Smi::FromInt(info.NumberOfLocals())); | 10880 Smi::FromInt(scope_info->NumberOfLocals())); |
| 10882 | 10881 |
| 10883 // Add the source position. | 10882 // Add the source position. |
| 10884 if (position != RelocInfo::kNoPosition) { | 10883 if (position != RelocInfo::kNoPosition) { |
| 10885 details->set(kFrameDetailsSourcePositionIndex, Smi::FromInt(position)); | 10884 details->set(kFrameDetailsSourcePositionIndex, Smi::FromInt(position)); |
| 10886 } else { | 10885 } else { |
| 10887 details->set(kFrameDetailsSourcePositionIndex, heap->undefined_value()); | 10886 details->set(kFrameDetailsSourcePositionIndex, heap->undefined_value()); |
| 10888 } | 10887 } |
| 10889 | 10888 |
| 10890 // Add the constructor information. | 10889 // Add the constructor information. |
| 10891 details->set(kFrameDetailsConstructCallIndex, heap->ToBoolean(constructor)); | 10890 details->set(kFrameDetailsConstructCallIndex, heap->ToBoolean(constructor)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 10906 flags |= inlined_frame_index << 2; | 10905 flags |= inlined_frame_index << 2; |
| 10907 } | 10906 } |
| 10908 details->set(kFrameDetailsFlagsIndex, Smi::FromInt(flags)); | 10907 details->set(kFrameDetailsFlagsIndex, Smi::FromInt(flags)); |
| 10909 | 10908 |
| 10910 // Fill the dynamic part. | 10909 // Fill the dynamic part. |
| 10911 int details_index = kFrameDetailsFirstDynamicIndex; | 10910 int details_index = kFrameDetailsFirstDynamicIndex; |
| 10912 | 10911 |
| 10913 // Add arguments name and value. | 10912 // Add arguments name and value. |
| 10914 for (int i = 0; i < argument_count; i++) { | 10913 for (int i = 0; i < argument_count; i++) { |
| 10915 // Name of the argument. | 10914 // Name of the argument. |
| 10916 if (i < info.number_of_parameters()) { | 10915 if (i < scope_info->NumParameters()) { |
| 10917 details->set(details_index++, *info.parameter_name(i)); | 10916 details->set(details_index++, scope_info->ParameterName(i)); |
| 10918 } else { | 10917 } else { |
| 10919 details->set(details_index++, heap->undefined_value()); | 10918 details->set(details_index++, heap->undefined_value()); |
| 10920 } | 10919 } |
| 10921 | 10920 |
| 10922 // Parameter value. | 10921 // Parameter value. |
| 10923 if (i < it.frame()->ComputeParametersCount()) { | 10922 if (i < it.frame()->ComputeParametersCount()) { |
| 10924 // Get the value from the stack. | 10923 // Get the value from the stack. |
| 10925 details->set(details_index++, frame_inspector.GetParameter(i)); | 10924 details->set(details_index++, frame_inspector.GetParameter(i)); |
| 10926 } else { | 10925 } else { |
| 10927 details->set(details_index++, heap->undefined_value()); | 10926 details->set(details_index++, heap->undefined_value()); |
| 10928 } | 10927 } |
| 10929 } | 10928 } |
| 10930 | 10929 |
| 10931 // Add locals name and value from the temporary copy from the function frame. | 10930 // Add locals name and value from the temporary copy from the function frame. |
| 10932 for (int i = 0; i < info.NumberOfLocals() * 2; i++) { | 10931 for (int i = 0; i < scope_info->NumberOfLocals() * 2; i++) { |
| 10933 details->set(details_index++, locals->get(i)); | 10932 details->set(details_index++, locals->get(i)); |
| 10934 } | 10933 } |
| 10935 | 10934 |
| 10936 // Add the value being returned. | 10935 // Add the value being returned. |
| 10937 if (at_return) { | 10936 if (at_return) { |
| 10938 details->set(details_index++, *return_value); | 10937 details->set(details_index++, *return_value); |
| 10939 } | 10938 } |
| 10940 | 10939 |
| 10941 // Add the receiver (same as in function frame). | 10940 // Add the receiver (same as in function frame). |
| 10942 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE | 10941 // THIS MUST BE DONE LAST SINCE WE MIGHT ADVANCE |
| (...skipping 15 matching lines...) Expand all Loading... |
| 10958 details->set(kFrameDetailsReceiverIndex, *receiver); | 10957 details->set(kFrameDetailsReceiverIndex, *receiver); |
| 10959 | 10958 |
| 10960 ASSERT_EQ(details_size, details_index); | 10959 ASSERT_EQ(details_size, details_index); |
| 10961 return *isolate->factory()->NewJSArrayWithElements(details); | 10960 return *isolate->factory()->NewJSArrayWithElements(details); |
| 10962 } | 10961 } |
| 10963 | 10962 |
| 10964 | 10963 |
| 10965 // Copy all the context locals into an object used to materialize a scope. | 10964 // Copy all the context locals into an object used to materialize a scope. |
| 10966 static bool CopyContextLocalsToScopeObject( | 10965 static bool CopyContextLocalsToScopeObject( |
| 10967 Isolate* isolate, | 10966 Isolate* isolate, |
| 10968 Handle<SerializedScopeInfo> serialized_scope_info, | 10967 Handle<ScopeInfo> scope_info, |
| 10969 ScopeInfo<>& scope_info, | |
| 10970 Handle<Context> context, | 10968 Handle<Context> context, |
| 10971 Handle<JSObject> scope_object) { | 10969 Handle<JSObject> scope_object) { |
| 10972 // Fill all context locals to the context extension. | 10970 // Fill all context locals to the context extension. |
| 10973 for (int i = Context::MIN_CONTEXT_SLOTS; | 10971 for (int i = 0; i < scope_info->NumContextLocals(); i++) { |
| 10974 i < scope_info.number_of_context_slots(); | 10972 VariableMode mode; |
| 10975 i++) { | 10973 int context_index = scope_info->ContextSlotIndex( |
| 10976 int context_index = serialized_scope_info->ContextSlotIndex( | 10974 scope_info->ContextLocalName(i), &mode); |
| 10977 *scope_info.context_slot_name(i), NULL); | |
| 10978 | 10975 |
| 10979 RETURN_IF_EMPTY_HANDLE_VALUE( | 10976 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 10980 isolate, | 10977 isolate, |
| 10981 SetProperty(scope_object, | 10978 SetProperty(scope_object, |
| 10982 scope_info.context_slot_name(i), | 10979 Handle<String>(scope_info->ContextLocalName(i)), |
| 10983 Handle<Object>(context->get(context_index), isolate), | 10980 Handle<Object>(context->get(context_index), isolate), |
| 10984 NONE, | 10981 NONE, |
| 10985 kNonStrictMode), | 10982 kNonStrictMode), |
| 10986 false); | 10983 false); |
| 10987 } | 10984 } |
| 10988 | 10985 |
| 10989 return true; | 10986 return true; |
| 10990 } | 10987 } |
| 10991 | 10988 |
| 10992 | 10989 |
| 10993 // Create a plain JSObject which materializes the local scope for the specified | 10990 // Create a plain JSObject which materializes the local scope for the specified |
| 10994 // frame. | 10991 // frame. |
| 10995 static Handle<JSObject> MaterializeLocalScope( | 10992 static Handle<JSObject> MaterializeLocalScope( |
| 10996 Isolate* isolate, | 10993 Isolate* isolate, |
| 10997 JavaScriptFrame* frame, | 10994 JavaScriptFrame* frame, |
| 10998 int inlined_frame_index) { | 10995 int inlined_frame_index) { |
| 10999 Handle<JSFunction> function(JSFunction::cast(frame->function())); | 10996 Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 11000 Handle<SharedFunctionInfo> shared(function->shared()); | 10997 Handle<SharedFunctionInfo> shared(function->shared()); |
| 11001 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); | 10998 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 11002 ScopeInfo<> scope_info(*serialized_scope_info); | |
| 11003 FrameInspector frame_inspector(frame, inlined_frame_index, isolate); | 10999 FrameInspector frame_inspector(frame, inlined_frame_index, isolate); |
| 11004 | 11000 |
| 11005 // Allocate and initialize a JSObject with all the arguments, stack locals | 11001 // Allocate and initialize a JSObject with all the arguments, stack locals |
| 11006 // heap locals and extension properties of the debugged function. | 11002 // heap locals and extension properties of the debugged function. |
| 11007 Handle<JSObject> local_scope = | 11003 Handle<JSObject> local_scope = |
| 11008 isolate->factory()->NewJSObject(isolate->object_function()); | 11004 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11009 | 11005 |
| 11010 // First fill all parameters. | 11006 // First fill all parameters. |
| 11011 for (int i = 0; i < scope_info.number_of_parameters(); ++i) { | 11007 for (int i = 0; i < scope_info->NumParameters(); ++i) { |
| 11012 RETURN_IF_EMPTY_HANDLE_VALUE( | 11008 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11013 isolate, | 11009 isolate, |
| 11014 SetProperty(local_scope, | 11010 SetProperty(local_scope, |
| 11015 scope_info.parameter_name(i), | 11011 Handle<String>(scope_info->ParameterName(i)), |
| 11016 Handle<Object>(frame_inspector.GetParameter(i)), | 11012 Handle<Object>(frame_inspector.GetParameter(i)), |
| 11017 NONE, | 11013 NONE, |
| 11018 kNonStrictMode), | 11014 kNonStrictMode), |
| 11019 Handle<JSObject>()); | 11015 Handle<JSObject>()); |
| 11020 } | 11016 } |
| 11021 | 11017 |
| 11022 // Second fill all stack locals. | 11018 // Second fill all stack locals. |
| 11023 for (int i = 0; i < scope_info.number_of_stack_slots(); ++i) { | 11019 for (int i = 0; i < scope_info->NumStackLocals(); ++i) { |
| 11024 RETURN_IF_EMPTY_HANDLE_VALUE( | 11020 RETURN_IF_EMPTY_HANDLE_VALUE( |
| 11025 isolate, | 11021 isolate, |
| 11026 SetProperty(local_scope, | 11022 SetProperty(local_scope, |
| 11027 scope_info.stack_slot_name(i), | 11023 Handle<String>(scope_info->StackLocalName(i)), |
| 11028 Handle<Object>(frame_inspector.GetExpression(i)), | 11024 Handle<Object>(frame_inspector.GetExpression(i)), |
| 11029 NONE, | 11025 NONE, |
| 11030 kNonStrictMode), | 11026 kNonStrictMode), |
| 11031 Handle<JSObject>()); | 11027 Handle<JSObject>()); |
| 11032 } | 11028 } |
| 11033 | 11029 |
| 11034 if (scope_info.number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { | 11030 if (scope_info->HasContext()) { |
| 11035 // Third fill all context locals. | 11031 // Third fill all context locals. |
| 11036 Handle<Context> frame_context(Context::cast(frame->context())); | 11032 Handle<Context> frame_context(Context::cast(frame->context())); |
| 11037 Handle<Context> function_context(frame_context->declaration_context()); | 11033 Handle<Context> function_context(frame_context->declaration_context()); |
| 11038 if (!CopyContextLocalsToScopeObject(isolate, | 11034 if (!CopyContextLocalsToScopeObject( |
| 11039 serialized_scope_info, scope_info, | 11035 isolate, scope_info, function_context, local_scope)) { |
| 11040 function_context, local_scope)) { | |
| 11041 return Handle<JSObject>(); | 11036 return Handle<JSObject>(); |
| 11042 } | 11037 } |
| 11043 | 11038 |
| 11044 // Finally copy any properties from the function context extension. | 11039 // Finally copy any properties from the function context extension. |
| 11045 // These will be variables introduced by eval. | 11040 // These will be variables introduced by eval. |
| 11046 if (function_context->closure() == *function) { | 11041 if (function_context->closure() == *function) { |
| 11047 if (function_context->has_extension() && | 11042 if (function_context->has_extension() && |
| 11048 !function_context->IsGlobalContext()) { | 11043 !function_context->IsGlobalContext()) { |
| 11049 Handle<JSObject> ext(JSObject::cast(function_context->extension())); | 11044 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
| 11050 bool threw = false; | 11045 bool threw = false; |
| (...skipping 22 matching lines...) Expand all Loading... |
| 11073 } | 11068 } |
| 11074 | 11069 |
| 11075 | 11070 |
| 11076 // Create a plain JSObject which materializes the closure content for the | 11071 // Create a plain JSObject which materializes the closure content for the |
| 11077 // context. | 11072 // context. |
| 11078 static Handle<JSObject> MaterializeClosure(Isolate* isolate, | 11073 static Handle<JSObject> MaterializeClosure(Isolate* isolate, |
| 11079 Handle<Context> context) { | 11074 Handle<Context> context) { |
| 11080 ASSERT(context->IsFunctionContext()); | 11075 ASSERT(context->IsFunctionContext()); |
| 11081 | 11076 |
| 11082 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 11077 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
| 11083 Handle<SerializedScopeInfo> serialized_scope_info(shared->scope_info()); | 11078 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 11084 ScopeInfo<> scope_info(*serialized_scope_info); | |
| 11085 | 11079 |
| 11086 // Allocate and initialize a JSObject with all the content of theis function | 11080 // Allocate and initialize a JSObject with all the content of theis function |
| 11087 // closure. | 11081 // closure. |
| 11088 Handle<JSObject> closure_scope = | 11082 Handle<JSObject> closure_scope = |
| 11089 isolate->factory()->NewJSObject(isolate->object_function()); | 11083 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11090 | 11084 |
| 11091 // Fill all context locals to the context extension. | 11085 // Fill all context locals to the context extension. |
| 11092 if (!CopyContextLocalsToScopeObject(isolate, | 11086 if (!CopyContextLocalsToScopeObject( |
| 11093 serialized_scope_info, scope_info, | 11087 isolate, scope_info, context, closure_scope)) { |
| 11094 context, closure_scope)) { | |
| 11095 return Handle<JSObject>(); | 11088 return Handle<JSObject>(); |
| 11096 } | 11089 } |
| 11097 | 11090 |
| 11098 // Finally copy any properties from the function context extension. This will | 11091 // Finally copy any properties from the function context extension. This will |
| 11099 // be variables introduced by eval. | 11092 // be variables introduced by eval. |
| 11100 if (context->has_extension()) { | 11093 if (context->has_extension()) { |
| 11101 Handle<JSObject> ext(JSObject::cast(context->extension())); | 11094 Handle<JSObject> ext(JSObject::cast(context->extension())); |
| 11102 bool threw = false; | 11095 bool threw = false; |
| 11103 Handle<FixedArray> keys = | 11096 Handle<FixedArray> keys = |
| 11104 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); | 11097 GetKeysInFixedArrayFor(ext, INCLUDE_PROTOS, &threw); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11139 return catch_scope; | 11132 return catch_scope; |
| 11140 } | 11133 } |
| 11141 | 11134 |
| 11142 | 11135 |
| 11143 // Create a plain JSObject which materializes the block scope for the specified | 11136 // Create a plain JSObject which materializes the block scope for the specified |
| 11144 // block context. | 11137 // block context. |
| 11145 static Handle<JSObject> MaterializeBlockScope( | 11138 static Handle<JSObject> MaterializeBlockScope( |
| 11146 Isolate* isolate, | 11139 Isolate* isolate, |
| 11147 Handle<Context> context) { | 11140 Handle<Context> context) { |
| 11148 ASSERT(context->IsBlockContext()); | 11141 ASSERT(context->IsBlockContext()); |
| 11149 Handle<SerializedScopeInfo> serialized_scope_info( | 11142 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
| 11150 SerializedScopeInfo::cast(context->extension())); | |
| 11151 ScopeInfo<> scope_info(*serialized_scope_info); | |
| 11152 | 11143 |
| 11153 // Allocate and initialize a JSObject with all the arguments, stack locals | 11144 // Allocate and initialize a JSObject with all the arguments, stack locals |
| 11154 // heap locals and extension properties of the debugged function. | 11145 // heap locals and extension properties of the debugged function. |
| 11155 Handle<JSObject> block_scope = | 11146 Handle<JSObject> block_scope = |
| 11156 isolate->factory()->NewJSObject(isolate->object_function()); | 11147 isolate->factory()->NewJSObject(isolate->object_function()); |
| 11157 | 11148 |
| 11158 // Fill all context locals. | 11149 // Fill all context locals. |
| 11159 if (scope_info.number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { | 11150 if (!CopyContextLocalsToScopeObject( |
| 11160 if (!CopyContextLocalsToScopeObject(isolate, | 11151 isolate, scope_info, context, block_scope)) { |
| 11161 serialized_scope_info, scope_info, | 11152 return Handle<JSObject>(); |
| 11162 context, block_scope)) { | |
| 11163 return Handle<JSObject>(); | |
| 11164 } | |
| 11165 } | 11153 } |
| 11166 | 11154 |
| 11167 return block_scope; | 11155 return block_scope; |
| 11168 } | 11156 } |
| 11169 | 11157 |
| 11170 | 11158 |
| 11171 // Iterate over the actual scopes visible from a stack frame. The iteration | 11159 // Iterate over the actual scopes visible from a stack frame. The iteration |
| 11172 // proceeds from the innermost visible nested scope outwards. All scopes are | 11160 // proceeds from the innermost visible nested scope outwards. All scopes are |
| 11173 // backed by an actual context except the local scope, which is inserted | 11161 // backed by an actual context except the local scope, which is inserted |
| 11174 // "artificially" in the context chain. | 11162 // "artificially" in the context chain. |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11257 if (nested_scope_chain_.last()->HasContext()) { | 11245 if (nested_scope_chain_.last()->HasContext()) { |
| 11258 context_ = Handle<Context>(context_->previous(), isolate_); | 11246 context_ = Handle<Context>(context_->previous(), isolate_); |
| 11259 } | 11247 } |
| 11260 nested_scope_chain_.RemoveLast(); | 11248 nested_scope_chain_.RemoveLast(); |
| 11261 } | 11249 } |
| 11262 } | 11250 } |
| 11263 | 11251 |
| 11264 // Return the type of the current scope. | 11252 // Return the type of the current scope. |
| 11265 ScopeType Type() { | 11253 ScopeType Type() { |
| 11266 if (!nested_scope_chain_.is_empty()) { | 11254 if (!nested_scope_chain_.is_empty()) { |
| 11267 Handle<SerializedScopeInfo> scope_info = nested_scope_chain_.last(); | 11255 Handle<ScopeInfo> scope_info = nested_scope_chain_.last(); |
| 11268 switch (scope_info->Type()) { | 11256 switch (scope_info->Type()) { |
| 11269 case FUNCTION_SCOPE: | 11257 case FUNCTION_SCOPE: |
| 11270 ASSERT(context_->IsFunctionContext() || | 11258 ASSERT(context_->IsFunctionContext() || |
| 11271 !scope_info->HasContext()); | 11259 !scope_info->HasContext()); |
| 11272 return ScopeTypeLocal; | 11260 return ScopeTypeLocal; |
| 11273 case GLOBAL_SCOPE: | 11261 case GLOBAL_SCOPE: |
| 11274 ASSERT(context_->IsGlobalContext()); | 11262 ASSERT(context_->IsGlobalContext()); |
| 11275 return ScopeTypeGlobal; | 11263 return ScopeTypeGlobal; |
| 11276 case WITH_SCOPE: | 11264 case WITH_SCOPE: |
| 11277 ASSERT(context_->IsWithContext()); | 11265 ASSERT(context_->IsWithContext()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11321 case ScopeIterator::ScopeTypeClosure: | 11309 case ScopeIterator::ScopeTypeClosure: |
| 11322 // Materialize the content of the closure scope into a JSObject. | 11310 // Materialize the content of the closure scope into a JSObject. |
| 11323 return MaterializeClosure(isolate_, CurrentContext()); | 11311 return MaterializeClosure(isolate_, CurrentContext()); |
| 11324 case ScopeIterator::ScopeTypeBlock: | 11312 case ScopeIterator::ScopeTypeBlock: |
| 11325 return MaterializeBlockScope(isolate_, CurrentContext()); | 11313 return MaterializeBlockScope(isolate_, CurrentContext()); |
| 11326 } | 11314 } |
| 11327 UNREACHABLE(); | 11315 UNREACHABLE(); |
| 11328 return Handle<JSObject>(); | 11316 return Handle<JSObject>(); |
| 11329 } | 11317 } |
| 11330 | 11318 |
| 11331 Handle<SerializedScopeInfo> CurrentScopeInfo() { | 11319 Handle<ScopeInfo> CurrentScopeInfo() { |
| 11332 if (!nested_scope_chain_.is_empty()) { | 11320 if (!nested_scope_chain_.is_empty()) { |
| 11333 return nested_scope_chain_.last(); | 11321 return nested_scope_chain_.last(); |
| 11334 } else if (context_->IsBlockContext()) { | 11322 } else if (context_->IsBlockContext()) { |
| 11335 return Handle<SerializedScopeInfo>( | 11323 return Handle<ScopeInfo>(ScopeInfo::cast(context_->extension())); |
| 11336 SerializedScopeInfo::cast(context_->extension())); | |
| 11337 } else if (context_->IsFunctionContext()) { | 11324 } else if (context_->IsFunctionContext()) { |
| 11338 return Handle<SerializedScopeInfo>( | 11325 return Handle<ScopeInfo>(context_->closure()->shared()->scope_info()); |
| 11339 context_->closure()->shared()->scope_info()); | |
| 11340 } | 11326 } |
| 11341 return Handle<SerializedScopeInfo>::null(); | 11327 return Handle<ScopeInfo>::null(); |
| 11342 } | 11328 } |
| 11343 | 11329 |
| 11344 // Return the context for this scope. For the local context there might not | 11330 // Return the context for this scope. For the local context there might not |
| 11345 // be an actual context. | 11331 // be an actual context. |
| 11346 Handle<Context> CurrentContext() { | 11332 Handle<Context> CurrentContext() { |
| 11347 if (Type() == ScopeTypeGlobal || | 11333 if (Type() == ScopeTypeGlobal || |
| 11348 nested_scope_chain_.is_empty()) { | 11334 nested_scope_chain_.is_empty()) { |
| 11349 return context_; | 11335 return context_; |
| 11350 } else if (nested_scope_chain_.last()->HasContext()) { | 11336 } else if (nested_scope_chain_.last()->HasContext()) { |
| 11351 return context_; | 11337 return context_; |
| 11352 } else { | 11338 } else { |
| 11353 return Handle<Context>(); | 11339 return Handle<Context>(); |
| 11354 } | 11340 } |
| 11355 } | 11341 } |
| 11356 | 11342 |
| 11357 #ifdef DEBUG | 11343 #ifdef DEBUG |
| 11358 // Debug print of the content of the current scope. | 11344 // Debug print of the content of the current scope. |
| 11359 void DebugPrint() { | 11345 void DebugPrint() { |
| 11360 switch (Type()) { | 11346 switch (Type()) { |
| 11361 case ScopeIterator::ScopeTypeGlobal: | 11347 case ScopeIterator::ScopeTypeGlobal: |
| 11362 PrintF("Global:\n"); | 11348 PrintF("Global:\n"); |
| 11363 CurrentContext()->Print(); | 11349 CurrentContext()->Print(); |
| 11364 break; | 11350 break; |
| 11365 | 11351 |
| 11366 case ScopeIterator::ScopeTypeLocal: { | 11352 case ScopeIterator::ScopeTypeLocal: { |
| 11367 PrintF("Local:\n"); | 11353 PrintF("Local:\n"); |
| 11368 ScopeInfo<> scope_info(function_->shared()->scope_info()); | 11354 function_->shared()->scope_info()->Print(); |
| 11369 scope_info.Print(); | |
| 11370 if (!CurrentContext().is_null()) { | 11355 if (!CurrentContext().is_null()) { |
| 11371 CurrentContext()->Print(); | 11356 CurrentContext()->Print(); |
| 11372 if (CurrentContext()->has_extension()) { | 11357 if (CurrentContext()->has_extension()) { |
| 11373 Handle<Object> extension(CurrentContext()->extension()); | 11358 Handle<Object> extension(CurrentContext()->extension()); |
| 11374 if (extension->IsJSContextExtensionObject()) { | 11359 if (extension->IsJSContextExtensionObject()) { |
| 11375 extension->Print(); | 11360 extension->Print(); |
| 11376 } | 11361 } |
| 11377 } | 11362 } |
| 11378 } | 11363 } |
| 11379 break; | 11364 break; |
| (...skipping 27 matching lines...) Expand all Loading... |
| 11407 PrintF("\n"); | 11392 PrintF("\n"); |
| 11408 } | 11393 } |
| 11409 #endif | 11394 #endif |
| 11410 | 11395 |
| 11411 private: | 11396 private: |
| 11412 Isolate* isolate_; | 11397 Isolate* isolate_; |
| 11413 JavaScriptFrame* frame_; | 11398 JavaScriptFrame* frame_; |
| 11414 int inlined_frame_index_; | 11399 int inlined_frame_index_; |
| 11415 Handle<JSFunction> function_; | 11400 Handle<JSFunction> function_; |
| 11416 Handle<Context> context_; | 11401 Handle<Context> context_; |
| 11417 List<Handle<SerializedScopeInfo> > nested_scope_chain_; | 11402 List<Handle<ScopeInfo> > nested_scope_chain_; |
| 11418 | 11403 |
| 11419 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator); | 11404 DISALLOW_IMPLICIT_CONSTRUCTORS(ScopeIterator); |
| 11420 }; | 11405 }; |
| 11421 | 11406 |
| 11422 | 11407 |
| 11423 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetScopeCount) { | 11408 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetScopeCount) { |
| 11424 HandleScope scope(isolate); | 11409 HandleScope scope(isolate); |
| 11425 ASSERT(args.length() == 2); | 11410 ASSERT(args.length() == 2); |
| 11426 | 11411 |
| 11427 // Check arguments. | 11412 // Check arguments. |
| (...skipping 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11876 | 11861 |
| 11877 | 11862 |
| 11878 // Creates a copy of the with context chain. The copy of the context chain is | 11863 // Creates a copy of the with context chain. The copy of the context chain is |
| 11879 // is linked to the function context supplied. | 11864 // is linked to the function context supplied. |
| 11880 static Handle<Context> CopyNestedScopeContextChain(Isolate* isolate, | 11865 static Handle<Context> CopyNestedScopeContextChain(Isolate* isolate, |
| 11881 Handle<JSFunction> function, | 11866 Handle<JSFunction> function, |
| 11882 Handle<Context> base, | 11867 Handle<Context> base, |
| 11883 JavaScriptFrame* frame, | 11868 JavaScriptFrame* frame, |
| 11884 int inlined_frame_index) { | 11869 int inlined_frame_index) { |
| 11885 HandleScope scope(isolate); | 11870 HandleScope scope(isolate); |
| 11886 List<Handle<SerializedScopeInfo> > scope_chain; | 11871 List<Handle<ScopeInfo> > scope_chain; |
| 11887 List<Handle<Context> > context_chain; | 11872 List<Handle<Context> > context_chain; |
| 11888 | 11873 |
| 11889 ScopeIterator it(isolate, frame, inlined_frame_index); | 11874 ScopeIterator it(isolate, frame, inlined_frame_index); |
| 11890 for (; it.Type() != ScopeIterator::ScopeTypeGlobal && | 11875 for (; it.Type() != ScopeIterator::ScopeTypeGlobal && |
| 11891 it.Type() != ScopeIterator::ScopeTypeLocal ; it.Next()) { | 11876 it.Type() != ScopeIterator::ScopeTypeLocal ; it.Next()) { |
| 11892 ASSERT(!it.Done()); | 11877 ASSERT(!it.Done()); |
| 11893 scope_chain.Add(it.CurrentScopeInfo()); | 11878 scope_chain.Add(it.CurrentScopeInfo()); |
| 11894 context_chain.Add(it.CurrentContext()); | 11879 context_chain.Add(it.CurrentContext()); |
| 11895 } | 11880 } |
| 11896 | 11881 |
| 11897 // At the end of the chain. Return the base context to link to. | 11882 // At the end of the chain. Return the base context to link to. |
| 11898 Handle<Context> context = base; | 11883 Handle<Context> context = base; |
| 11899 | 11884 |
| 11900 // Iteratively copy and or materialize the nested contexts. | 11885 // Iteratively copy and or materialize the nested contexts. |
| 11901 while (!scope_chain.is_empty()) { | 11886 while (!scope_chain.is_empty()) { |
| 11902 Handle<SerializedScopeInfo> scope_info = scope_chain.RemoveLast(); | 11887 Handle<ScopeInfo> scope_info = scope_chain.RemoveLast(); |
| 11903 Handle<Context> current = context_chain.RemoveLast(); | 11888 Handle<Context> current = context_chain.RemoveLast(); |
| 11904 ASSERT(!(scope_info->HasContext() & current.is_null())); | 11889 ASSERT(!(scope_info->HasContext() & current.is_null())); |
| 11905 | 11890 |
| 11906 if (scope_info->Type() == CATCH_SCOPE) { | 11891 if (scope_info->Type() == CATCH_SCOPE) { |
| 11907 Handle<String> name(String::cast(current->extension())); | 11892 Handle<String> name(String::cast(current->extension())); |
| 11908 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX)); | 11893 Handle<Object> thrown_object(current->get(Context::THROWN_OBJECT_INDEX)); |
| 11909 context = | 11894 context = |
| 11910 isolate->factory()->NewCatchContext(function, | 11895 isolate->factory()->NewCatchContext(function, |
| 11911 context, | 11896 context, |
| 11912 name, | 11897 name, |
| (...skipping 25 matching lines...) Expand all Loading... |
| 11938 return scope.CloseAndEscape(context); | 11923 return scope.CloseAndEscape(context); |
| 11939 } | 11924 } |
| 11940 | 11925 |
| 11941 | 11926 |
| 11942 // Helper function to find or create the arguments object for | 11927 // Helper function to find or create the arguments object for |
| 11943 // Runtime_DebugEvaluate. | 11928 // Runtime_DebugEvaluate. |
| 11944 static Handle<Object> GetArgumentsObject(Isolate* isolate, | 11929 static Handle<Object> GetArgumentsObject(Isolate* isolate, |
| 11945 JavaScriptFrame* frame, | 11930 JavaScriptFrame* frame, |
| 11946 int inlined_frame_index, | 11931 int inlined_frame_index, |
| 11947 Handle<JSFunction> function, | 11932 Handle<JSFunction> function, |
| 11948 Handle<SerializedScopeInfo> scope_info, | 11933 Handle<ScopeInfo> scope_info, |
| 11949 const ScopeInfo<>* sinfo, | |
| 11950 Handle<Context> function_context) { | 11934 Handle<Context> function_context) { |
| 11951 // Try to find the value of 'arguments' to pass as parameter. If it is not | 11935 // Try to find the value of 'arguments' to pass as parameter. If it is not |
| 11952 // found (that is the debugged function does not reference 'arguments' and | 11936 // found (that is the debugged function does not reference 'arguments' and |
| 11953 // does not support eval) then create an 'arguments' object. | 11937 // does not support eval) then create an 'arguments' object. |
| 11954 int index; | 11938 int index; |
| 11955 if (sinfo->number_of_stack_slots() > 0) { | 11939 if (scope_info->NumStackLocals() > 0) { |
| 11956 index = scope_info->StackSlotIndex(isolate->heap()->arguments_symbol()); | 11940 index = scope_info->StackSlotIndex(isolate->heap()->arguments_symbol()); |
| 11957 if (index != -1) { | 11941 if (index != -1) { |
| 11958 return Handle<Object>(frame->GetExpression(index), isolate); | 11942 return Handle<Object>(frame->GetExpression(index), isolate); |
| 11959 } | 11943 } |
| 11960 } | 11944 } |
| 11961 | 11945 |
| 11962 if (sinfo->number_of_context_slots() > Context::MIN_CONTEXT_SLOTS) { | 11946 if (scope_info->HasHeapAllocatedLocals()) { |
| 11963 index = scope_info->ContextSlotIndex(isolate->heap()->arguments_symbol(), | 11947 VariableMode mode; |
| 11964 NULL); | 11948 index = scope_info->ContextSlotIndex( |
| 11949 isolate->heap()->arguments_symbol(), &mode); |
| 11965 if (index != -1) { | 11950 if (index != -1) { |
| 11966 return Handle<Object>(function_context->get(index), isolate); | 11951 return Handle<Object>(function_context->get(index), isolate); |
| 11967 } | 11952 } |
| 11968 } | 11953 } |
| 11969 | 11954 |
| 11970 FrameInspector frame_inspector(frame, inlined_frame_index, isolate); | 11955 FrameInspector frame_inspector(frame, inlined_frame_index, isolate); |
| 11971 | 11956 |
| 11972 int length = frame_inspector.GetParametersCount(); | 11957 int length = frame_inspector.GetParametersCount(); |
| 11973 Handle<JSObject> arguments = | 11958 Handle<JSObject> arguments = |
| 11974 isolate->factory()->NewArgumentsObject(function, length); | 11959 isolate->factory()->NewArgumentsObject(function, length); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12019 Handle<Object> additional_context(args[5]); | 12004 Handle<Object> additional_context(args[5]); |
| 12020 | 12005 |
| 12021 // Handle the processing of break. | 12006 // Handle the processing of break. |
| 12022 DisableBreak disable_break_save(disable_break); | 12007 DisableBreak disable_break_save(disable_break); |
| 12023 | 12008 |
| 12024 // Get the frame where the debugging is performed. | 12009 // Get the frame where the debugging is performed. |
| 12025 StackFrame::Id id = UnwrapFrameId(wrapped_id); | 12010 StackFrame::Id id = UnwrapFrameId(wrapped_id); |
| 12026 JavaScriptFrameIterator it(isolate, id); | 12011 JavaScriptFrameIterator it(isolate, id); |
| 12027 JavaScriptFrame* frame = it.frame(); | 12012 JavaScriptFrame* frame = it.frame(); |
| 12028 Handle<JSFunction> function(JSFunction::cast(frame->function())); | 12013 Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 12029 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); | 12014 Handle<ScopeInfo> scope_info(function->shared()->scope_info()); |
| 12030 ScopeInfo<> sinfo(*scope_info); | |
| 12031 | 12015 |
| 12032 // Traverse the saved contexts chain to find the active context for the | 12016 // Traverse the saved contexts chain to find the active context for the |
| 12033 // selected frame. | 12017 // selected frame. |
| 12034 SaveContext* save = FindSavedContextForFrame(isolate, frame); | 12018 SaveContext* save = FindSavedContextForFrame(isolate, frame); |
| 12035 | 12019 |
| 12036 SaveContext savex(isolate); | 12020 SaveContext savex(isolate); |
| 12037 isolate->set_context(*(save->context())); | 12021 isolate->set_context(*(save->context())); |
| 12038 | 12022 |
| 12039 // Create the (empty) function replacing the function on the stack frame for | 12023 // Create the (empty) function replacing the function on the stack frame for |
| 12040 // the purpose of evaluating in the context created below. It is important | 12024 // the purpose of evaluating in the context created below. It is important |
| 12041 // that this function does not describe any parameters and local variables | 12025 // that this function does not describe any parameters and local variables |
| 12042 // in the context. If it does then this will cause problems with the lookup | 12026 // in the context. If it does then this will cause problems with the lookup |
| 12043 // in Context::Lookup, where context slots for parameters and local variables | 12027 // in Context::Lookup, where context slots for parameters and local variables |
| 12044 // are looked at before the extension object. | 12028 // are looked at before the extension object. |
| 12045 Handle<JSFunction> go_between = | 12029 Handle<JSFunction> go_between = |
| 12046 isolate->factory()->NewFunction(isolate->factory()->empty_string(), | 12030 isolate->factory()->NewFunction(isolate->factory()->empty_string(), |
| 12047 isolate->factory()->undefined_value()); | 12031 isolate->factory()->undefined_value()); |
| 12048 go_between->set_context(function->context()); | 12032 go_between->set_context(function->context()); |
| 12049 #ifdef DEBUG | 12033 #ifdef DEBUG |
| 12050 ScopeInfo<> go_between_sinfo(go_between->shared()->scope_info()); | 12034 Handle<ScopeInfo> go_between_scope_info(go_between->shared()->scope_info()); |
| 12051 ASSERT(go_between_sinfo.number_of_parameters() == 0); | 12035 ASSERT(go_between_scope_info->NumParameters() == 0); |
| 12052 ASSERT(go_between_sinfo.number_of_context_slots() == 0); | 12036 ASSERT(go_between_scope_info->NumContextLocals() == 0); |
| 12053 #endif | 12037 #endif |
| 12054 | 12038 |
| 12055 // Materialize the content of the local scope into a JSObject. | 12039 // Materialize the content of the local scope into a JSObject. |
| 12056 Handle<JSObject> local_scope = MaterializeLocalScope( | 12040 Handle<JSObject> local_scope = MaterializeLocalScope( |
| 12057 isolate, frame, inlined_frame_index); | 12041 isolate, frame, inlined_frame_index); |
| 12058 RETURN_IF_EMPTY_HANDLE(isolate, local_scope); | 12042 RETURN_IF_EMPTY_HANDLE(isolate, local_scope); |
| 12059 | 12043 |
| 12060 // Allocate a new context for the debug evaluation and set the extension | 12044 // Allocate a new context for the debug evaluation and set the extension |
| 12061 // object build. | 12045 // object build. |
| 12062 Handle<Context> context = | 12046 Handle<Context> context = |
| 12063 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, | 12047 isolate->factory()->NewFunctionContext(Context::MIN_CONTEXT_SLOTS, |
| 12064 go_between); | 12048 go_between); |
| 12065 context->set_extension(*local_scope); | 12049 context->set_extension(*local_scope); |
| 12066 // Copy any with contexts present and chain them in front of this context. | 12050 // Copy any with contexts present and chain them in front of this context. |
| 12067 Handle<Context> frame_context(Context::cast(frame->context())); | 12051 Handle<Context> frame_context(Context::cast(frame->context())); |
| 12068 Handle<Context> function_context; | 12052 Handle<Context> function_context; |
| 12069 // Get the function's context if it has one. | 12053 // Get the function's context if it has one. |
| 12070 if (scope_info->HasHeapAllocatedLocals()) { | 12054 if (scope_info->HasContext()) { |
| 12071 function_context = Handle<Context>(frame_context->declaration_context()); | 12055 function_context = Handle<Context>(frame_context->declaration_context()); |
| 12072 } | 12056 } |
| 12073 context = CopyNestedScopeContextChain(isolate, | 12057 context = CopyNestedScopeContextChain(isolate, |
| 12074 go_between, | 12058 go_between, |
| 12075 context, | 12059 context, |
| 12076 frame, | 12060 frame, |
| 12077 inlined_frame_index); | 12061 inlined_frame_index); |
| 12078 | 12062 |
| 12079 if (additional_context->IsJSObject()) { | 12063 if (additional_context->IsJSObject()) { |
| 12080 Handle<JSObject> extension = Handle<JSObject>::cast(additional_context); | 12064 Handle<JSObject> extension = Handle<JSObject>::cast(additional_context); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 12105 | 12089 |
| 12106 // Invoke the result of the compilation to get the evaluation function. | 12090 // Invoke the result of the compilation to get the evaluation function. |
| 12107 bool has_pending_exception; | 12091 bool has_pending_exception; |
| 12108 Handle<Object> receiver(frame->receiver(), isolate); | 12092 Handle<Object> receiver(frame->receiver(), isolate); |
| 12109 Handle<Object> evaluation_function = | 12093 Handle<Object> evaluation_function = |
| 12110 Execution::Call(compiled_function, receiver, 0, NULL, | 12094 Execution::Call(compiled_function, receiver, 0, NULL, |
| 12111 &has_pending_exception); | 12095 &has_pending_exception); |
| 12112 if (has_pending_exception) return Failure::Exception(); | 12096 if (has_pending_exception) return Failure::Exception(); |
| 12113 | 12097 |
| 12114 Handle<Object> arguments = GetArgumentsObject(isolate, | 12098 Handle<Object> arguments = GetArgumentsObject(isolate, |
| 12115 frame, inlined_frame_index, | 12099 frame, |
| 12116 function, scope_info, | 12100 inlined_frame_index, |
| 12117 &sinfo, function_context); | 12101 function, |
| 12102 scope_info, |
| 12103 function_context); |
| 12118 | 12104 |
| 12119 // Invoke the evaluation function and return the result. | 12105 // Invoke the evaluation function and return the result. |
| 12120 Handle<Object> argv[] = { arguments, source }; | 12106 Handle<Object> argv[] = { arguments, source }; |
| 12121 Handle<Object> result = | 12107 Handle<Object> result = |
| 12122 Execution::Call(Handle<JSFunction>::cast(evaluation_function), | 12108 Execution::Call(Handle<JSFunction>::cast(evaluation_function), |
| 12123 receiver, | 12109 receiver, |
| 12124 ARRAY_SIZE(argv), | 12110 ARRAY_SIZE(argv), |
| 12125 argv, | 12111 argv, |
| 12126 &has_pending_exception); | 12112 &has_pending_exception); |
| 12127 if (has_pending_exception) return Failure::Exception(); | 12113 if (has_pending_exception) return Failure::Exception(); |
| (...skipping 1390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13518 } else { | 13504 } else { |
| 13519 // Handle last resort GC and make sure to allow future allocations | 13505 // Handle last resort GC and make sure to allow future allocations |
| 13520 // to grow the heap without causing GCs (if possible). | 13506 // to grow the heap without causing GCs (if possible). |
| 13521 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13507 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13522 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13508 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 13523 } | 13509 } |
| 13524 } | 13510 } |
| 13525 | 13511 |
| 13526 | 13512 |
| 13527 } } // namespace v8::internal | 13513 } } // namespace v8::internal |
| OLD | NEW |