| 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 10780 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10791 Isolate* isolate, | 10791 Isolate* isolate, |
| 10792 JavaScriptFrame* frame, | 10792 JavaScriptFrame* frame, |
| 10793 int inlined_jsframe_index) { | 10793 int inlined_jsframe_index) { |
| 10794 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 10794 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
| 10795 return MaterializeLocalScopeWithFrameInspector(isolate, | 10795 return MaterializeLocalScopeWithFrameInspector(isolate, |
| 10796 frame, | 10796 frame, |
| 10797 &frame_inspector); | 10797 &frame_inspector); |
| 10798 } | 10798 } |
| 10799 | 10799 |
| 10800 | 10800 |
| 10801 // Set the context local variable value. |
| 10802 static bool SetContextLocalValue(Isolate* isolate, |
| 10803 Handle<ScopeInfo> scope_info, |
| 10804 Handle<Context> context, |
| 10805 Handle<String> variable_name, |
| 10806 Handle<Object> new_value) { |
| 10807 for (int i = 0; i < scope_info->ContextLocalCount(); i++) { |
| 10808 Handle<String> next_name(scope_info->ContextLocalName(i)); |
| 10809 if (variable_name->Equals(*next_name)) { |
| 10810 VariableMode mode; |
| 10811 InitializationFlag init_flag; |
| 10812 int context_index = |
| 10813 scope_info->ContextSlotIndex(*next_name, &mode, &init_flag); |
| 10814 context->set(context_index, *new_value); |
| 10815 return true; |
| 10816 } |
| 10817 } |
| 10818 |
| 10819 return false; |
| 10820 } |
| 10821 |
| 10822 |
| 10823 static bool SetLocalVariableValue(Isolate* isolate, |
| 10824 JavaScriptFrame* frame, |
| 10825 int inlined_jsframe_index, |
| 10826 Handle<String> variable_name, |
| 10827 Handle<Object> new_value) { |
| 10828 if (inlined_jsframe_index != 0 || frame->is_optimized()) { |
| 10829 // Optimized frames are not supported. |
| 10830 return false; |
| 10831 } |
| 10832 |
| 10833 Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 10834 Handle<SharedFunctionInfo> shared(function->shared()); |
| 10835 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 10836 |
| 10837 // Parameters. |
| 10838 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
| 10839 if (scope_info->ParameterName(i)->Equals(*variable_name)) { |
| 10840 frame->SetParameterValue(i, *new_value); |
| 10841 return true; |
| 10842 } |
| 10843 } |
| 10844 |
| 10845 // Stack locals. |
| 10846 for (int i = 0; i < scope_info->StackLocalCount(); ++i) { |
| 10847 if (scope_info->StackLocalName(i)->Equals(*variable_name)) { |
| 10848 frame->SetExpression(i, *new_value); |
| 10849 return true; |
| 10850 } |
| 10851 } |
| 10852 |
| 10853 if (scope_info->HasContext()) { |
| 10854 // Context locals. |
| 10855 Handle<Context> frame_context(Context::cast(frame->context())); |
| 10856 Handle<Context> function_context(frame_context->declaration_context()); |
| 10857 if (SetContextLocalValue( |
| 10858 isolate, scope_info, function_context, variable_name, new_value)) { |
| 10859 return true; |
| 10860 } |
| 10861 |
| 10862 // Function context extension. These are variables introduced by eval. |
| 10863 if (function_context->closure() == *function) { |
| 10864 if (function_context->has_extension() && |
| 10865 !function_context->IsNativeContext()) { |
| 10866 Handle<JSObject> ext(JSObject::cast(function_context->extension())); |
| 10867 |
| 10868 if (ext->HasProperty(*variable_name)) { |
| 10869 // We don't expect this to do anything except replacing |
| 10870 // property value. |
| 10871 SetProperty(isolate, |
| 10872 ext, |
| 10873 variable_name, |
| 10874 new_value, |
| 10875 NONE, |
| 10876 kNonStrictMode); |
| 10877 return true; |
| 10878 } |
| 10879 } |
| 10880 } |
| 10881 } |
| 10882 |
| 10883 return false; |
| 10884 } |
| 10885 |
| 10886 |
| 10801 // Create a plain JSObject which materializes the closure content for the | 10887 // Create a plain JSObject which materializes the closure content for the |
| 10802 // context. | 10888 // context. |
| 10803 static Handle<JSObject> MaterializeClosure(Isolate* isolate, | 10889 static Handle<JSObject> MaterializeClosure(Isolate* isolate, |
| 10804 Handle<Context> context) { | 10890 Handle<Context> context) { |
| 10805 ASSERT(context->IsFunctionContext()); | 10891 ASSERT(context->IsFunctionContext()); |
| 10806 | 10892 |
| 10807 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 10893 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
| 10808 Handle<ScopeInfo> scope_info(shared->scope_info()); | 10894 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 10809 | 10895 |
| 10810 // Allocate and initialize a JSObject with all the content of this function | 10896 // Allocate and initialize a JSObject with all the content of this function |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10851 static bool SetClosureVariableValue(Isolate* isolate, | 10937 static bool SetClosureVariableValue(Isolate* isolate, |
| 10852 Handle<Context> context, | 10938 Handle<Context> context, |
| 10853 Handle<String> variable_name, | 10939 Handle<String> variable_name, |
| 10854 Handle<Object> new_value) { | 10940 Handle<Object> new_value) { |
| 10855 ASSERT(context->IsFunctionContext()); | 10941 ASSERT(context->IsFunctionContext()); |
| 10856 | 10942 |
| 10857 Handle<SharedFunctionInfo> shared(context->closure()->shared()); | 10943 Handle<SharedFunctionInfo> shared(context->closure()->shared()); |
| 10858 Handle<ScopeInfo> scope_info(shared->scope_info()); | 10944 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 10859 | 10945 |
| 10860 // Context locals to the context extension. | 10946 // Context locals to the context extension. |
| 10861 for (int i = 0; i < scope_info->ContextLocalCount(); i++) { | 10947 if (SetContextLocalValue( |
| 10862 Handle<String> next_name(scope_info->ContextLocalName(i)); | 10948 isolate, scope_info, context, variable_name, new_value)) { |
| 10863 if (variable_name->Equals(*next_name)) { | 10949 return true; |
| 10864 VariableMode mode; | |
| 10865 InitializationFlag init_flag; | |
| 10866 int context_index = | |
| 10867 scope_info->ContextSlotIndex(*next_name, &mode, &init_flag); | |
| 10868 if (context_index < 0) { | |
| 10869 return false; | |
| 10870 } | |
| 10871 context->set(context_index, *new_value); | |
| 10872 return true; | |
| 10873 } | |
| 10874 } | 10950 } |
| 10875 | 10951 |
| 10876 // Properties from the function context extension. This will | 10952 // Properties from the function context extension. This will |
| 10877 // be variables introduced by eval. | 10953 // be variables introduced by eval. |
| 10878 if (context->has_extension()) { | 10954 if (context->has_extension()) { |
| 10879 Handle<JSObject> ext(JSObject::cast(context->extension())); | 10955 Handle<JSObject> ext(JSObject::cast(context->extension())); |
| 10880 if (ext->HasProperty(*variable_name)) { | 10956 if (ext->HasProperty(*variable_name)) { |
| 10881 // We don't expect this to do anything except replacing property value. | 10957 // We don't expect this to do anything except replacing property value. |
| 10882 SetProperty(isolate, | 10958 SetProperty(isolate, |
| 10883 ext, | 10959 ext, |
| (...skipping 24 matching lines...) Expand all Loading... |
| 10908 catch_scope, | 10984 catch_scope, |
| 10909 name, | 10985 name, |
| 10910 thrown_object, | 10986 thrown_object, |
| 10911 NONE, | 10987 NONE, |
| 10912 kNonStrictMode), | 10988 kNonStrictMode), |
| 10913 Handle<JSObject>()); | 10989 Handle<JSObject>()); |
| 10914 return catch_scope; | 10990 return catch_scope; |
| 10915 } | 10991 } |
| 10916 | 10992 |
| 10917 | 10993 |
| 10994 static bool SetCatchVariableValue(Isolate* isolate, |
| 10995 Handle<Context> context, |
| 10996 Handle<String> variable_name, |
| 10997 Handle<Object> new_value) { |
| 10998 ASSERT(context->IsCatchContext()); |
| 10999 Handle<String> name(String::cast(context->extension())); |
| 11000 if (!name->Equals(*variable_name)) { |
| 11001 return false; |
| 11002 } |
| 11003 context->set(Context::THROWN_OBJECT_INDEX, *new_value); |
| 11004 return true; |
| 11005 } |
| 11006 |
| 11007 |
| 10918 // Create a plain JSObject which materializes the block scope for the specified | 11008 // Create a plain JSObject which materializes the block scope for the specified |
| 10919 // block context. | 11009 // block context. |
| 10920 static Handle<JSObject> MaterializeBlockScope( | 11010 static Handle<JSObject> MaterializeBlockScope( |
| 10921 Isolate* isolate, | 11011 Isolate* isolate, |
| 10922 Handle<Context> context) { | 11012 Handle<Context> context) { |
| 10923 ASSERT(context->IsBlockContext()); | 11013 ASSERT(context->IsBlockContext()); |
| 10924 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); | 11014 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); |
| 10925 | 11015 |
| 10926 // Allocate and initialize a JSObject with all the arguments, stack locals | 11016 // Allocate and initialize a JSObject with all the arguments, stack locals |
| 10927 // heap locals and extension properties of the debugged function. | 11017 // heap locals and extension properties of the debugged function. |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 11173 return Handle<JSObject>(); | 11263 return Handle<JSObject>(); |
| 11174 } | 11264 } |
| 11175 | 11265 |
| 11176 bool SetVariableValue(Handle<String> variable_name, | 11266 bool SetVariableValue(Handle<String> variable_name, |
| 11177 Handle<Object> new_value) { | 11267 Handle<Object> new_value) { |
| 11178 ASSERT(!failed_); | 11268 ASSERT(!failed_); |
| 11179 switch (Type()) { | 11269 switch (Type()) { |
| 11180 case ScopeIterator::ScopeTypeGlobal: | 11270 case ScopeIterator::ScopeTypeGlobal: |
| 11181 break; | 11271 break; |
| 11182 case ScopeIterator::ScopeTypeLocal: | 11272 case ScopeIterator::ScopeTypeLocal: |
| 11183 // TODO(2399): implement. | 11273 return SetLocalVariableValue(isolate_, frame_, inlined_jsframe_index_, |
| 11184 break; | 11274 variable_name, new_value); |
| 11185 case ScopeIterator::ScopeTypeWith: | 11275 case ScopeIterator::ScopeTypeWith: |
| 11186 break; | 11276 break; |
| 11187 case ScopeIterator::ScopeTypeCatch: | 11277 case ScopeIterator::ScopeTypeCatch: |
| 11188 // TODO(2399): implement. | 11278 return SetCatchVariableValue(isolate_, CurrentContext(), |
| 11189 break; | 11279 variable_name, new_value); |
| 11190 case ScopeIterator::ScopeTypeClosure: | 11280 case ScopeIterator::ScopeTypeClosure: |
| 11191 return SetClosureVariableValue(isolate_, CurrentContext(), | 11281 return SetClosureVariableValue(isolate_, CurrentContext(), |
| 11192 variable_name, new_value); | 11282 variable_name, new_value); |
| 11193 case ScopeIterator::ScopeTypeBlock: | 11283 case ScopeIterator::ScopeTypeBlock: |
| 11194 // TODO(2399): should we implement it? | 11284 // TODO(2399): should we implement it? |
| 11195 break; | 11285 break; |
| 11196 case ScopeIterator::ScopeTypeModule: | 11286 case ScopeIterator::ScopeTypeModule: |
| 11197 // TODO(2399): should we implement it? | 11287 // TODO(2399): should we implement it? |
| 11198 break; | 11288 break; |
| 11199 } | 11289 } |
| (...skipping 2304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13504 // Handle last resort GC and make sure to allow future allocations | 13594 // Handle last resort GC and make sure to allow future allocations |
| 13505 // to grow the heap without causing GCs (if possible). | 13595 // to grow the heap without causing GCs (if possible). |
| 13506 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13596 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13507 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13597 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
| 13508 "Runtime::PerformGC"); | 13598 "Runtime::PerformGC"); |
| 13509 } | 13599 } |
| 13510 } | 13600 } |
| 13511 | 13601 |
| 13512 | 13602 |
| 13513 } } // namespace v8::internal | 13603 } } // namespace v8::internal |
| OLD | NEW |