Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(284)

Side by Side Diff: src/runtime.cc

Issue 11412310: Issue 2399 part 2: In debugger allow modifying local variable values (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: style Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 10835 matching lines...) Expand 10 before | Expand all | Expand 10 after
10846 Isolate* isolate, 10846 Isolate* isolate,
10847 JavaScriptFrame* frame, 10847 JavaScriptFrame* frame,
10848 int inlined_jsframe_index) { 10848 int inlined_jsframe_index) {
10849 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); 10849 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
10850 return MaterializeLocalScopeWithFrameInspector(isolate, 10850 return MaterializeLocalScopeWithFrameInspector(isolate,
10851 frame, 10851 frame,
10852 &frame_inspector); 10852 &frame_inspector);
10853 } 10853 }
10854 10854
10855 10855
10856 // Set the context local variable value.
10857 static bool SetContextLocalValue(
10858 Isolate* isolate,
Yang 2012/12/10 14:15:11 I'd prefer having the first argument in the same l
Peter Rybin 2012/12/11 23:20:44 Done.
10859 Handle<ScopeInfo> scope_info,
10860 Handle<Context> context,
10861 Handle<String> variable_name,
10862 Handle<Object> new_value) {
10863 for (int i = 0; i < scope_info->ContextLocalCount(); i++) {
10864 Handle<String> next_name(scope_info->ContextLocalName(i));
10865 if (variable_name->Equals(*next_name)) {
10866 VariableMode mode;
10867 InitializationFlag init_flag;
10868 int context_index =
10869 scope_info->ContextSlotIndex(*next_name, &mode, &init_flag);
10870 context->set(context_index, *new_value);
10871 return true;
10872 }
10873 }
10874
10875 return false;
10876 }
10877
10878
10879 static bool SetLocalVariableValue(
10880 Isolate* isolate,
Yang 2012/12/10 14:15:11 Ditto about argument formatting.
Peter Rybin 2012/12/11 23:20:44 Done.
10881 JavaScriptFrame* frame,
10882 int inlined_jsframe_index,
10883 Handle<String> variable_name,
10884 Handle<Object> new_value) {
10885 if (inlined_jsframe_index != 0 || frame->is_optimized()) {
10886 // Optimized frames are not supported.
10887 return false;
10888 }
10889
10890 Handle<JSFunction> function(JSFunction::cast(frame->function()));
10891 Handle<SharedFunctionInfo> shared(function->shared());
10892 Handle<ScopeInfo> scope_info(shared->scope_info());
10893
10894 // Parameters.
10895 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
10896 if (scope_info->ParameterName(i)->Equals(*variable_name)) {
10897 frame->SetParameterValue(i, *new_value);
10898 return true;
10899 }
10900 }
10901
10902 // Stack locals.
10903 for (int i = 0; i < scope_info->StackLocalCount(); ++i) {
10904 if (scope_info->StackLocalName(i)->Equals(*variable_name)) {
10905 frame->SetExpression(i, *new_value);
10906 return true;
10907 }
10908 }
10909
10910 if (scope_info->HasContext()) {
10911 // Context locals.
10912 Handle<Context> frame_context(Context::cast(frame->context()));
10913 Handle<Context> function_context(frame_context->declaration_context());
10914 if (SetContextLocalValue(isolate, scope_info, function_context,
Yang 2012/12/10 14:15:11 could you put all arguments on the second line?
Peter Rybin 2012/12/11 23:20:44 Done.
10915 variable_name, new_value)) {
10916 return true;
10917 }
10918
10919 // Function context extension. These are variables introduced by eval.
10920 if (function_context->closure() == *function) {
10921 if (function_context->has_extension() &&
10922 !function_context->IsNativeContext()) {
10923 Handle<JSObject> ext(JSObject::cast(function_context->extension()));
10924
10925 if (ext->HasProperty(*variable_name)) {
10926 // We don't expect this to do anything except replacing
10927 // property value.
10928 SetProperty(isolate,
10929 ext,
10930 variable_name,
10931 new_value,
10932 NONE,
10933 kNonStrictMode);
10934 return true;
10935 }
10936 }
10937 }
10938 }
10939
10940 return false;
10941 }
10942
10943
10856 // Create a plain JSObject which materializes the closure content for the 10944 // Create a plain JSObject which materializes the closure content for the
10857 // context. 10945 // context.
10858 static Handle<JSObject> MaterializeClosure(Isolate* isolate, 10946 static Handle<JSObject> MaterializeClosure(Isolate* isolate,
10859 Handle<Context> context) { 10947 Handle<Context> context) {
10860 ASSERT(context->IsFunctionContext()); 10948 ASSERT(context->IsFunctionContext());
10861 10949
10862 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 10950 Handle<SharedFunctionInfo> shared(context->closure()->shared());
10863 Handle<ScopeInfo> scope_info(shared->scope_info()); 10951 Handle<ScopeInfo> scope_info(shared->scope_info());
10864 10952
10865 // Allocate and initialize a JSObject with all the content of this function 10953 // Allocate and initialize a JSObject with all the content of this function
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
10906 static bool SetClosureVariableValue(Isolate* isolate, 10994 static bool SetClosureVariableValue(Isolate* isolate,
10907 Handle<Context> context, 10995 Handle<Context> context,
10908 Handle<String> variable_name, 10996 Handle<String> variable_name,
10909 Handle<Object> new_value) { 10997 Handle<Object> new_value) {
10910 ASSERT(context->IsFunctionContext()); 10998 ASSERT(context->IsFunctionContext());
10911 10999
10912 Handle<SharedFunctionInfo> shared(context->closure()->shared()); 11000 Handle<SharedFunctionInfo> shared(context->closure()->shared());
10913 Handle<ScopeInfo> scope_info(shared->scope_info()); 11001 Handle<ScopeInfo> scope_info(shared->scope_info());
10914 11002
10915 // Context locals to the context extension. 11003 // Context locals to the context extension.
10916 for (int i = 0; i < scope_info->ContextLocalCount(); i++) { 11004 if (SetContextLocalValue(
10917 Handle<String> next_name(scope_info->ContextLocalName(i)); 11005 isolate, scope_info, context, variable_name, new_value)) {
10918 if (variable_name->Equals(*next_name)) { 11006 return true;
10919 VariableMode mode;
10920 InitializationFlag init_flag;
10921 int context_index =
10922 scope_info->ContextSlotIndex(*next_name, &mode, &init_flag);
10923 if (context_index < 0) {
10924 return false;
10925 }
10926 context->set(context_index, *new_value);
10927 return true;
10928 }
10929 } 11007 }
10930 11008
10931 // Properties from the function context extension. This will 11009 // Properties from the function context extension. This will
10932 // be variables introduced by eval. 11010 // be variables introduced by eval.
10933 if (context->has_extension()) { 11011 if (context->has_extension()) {
10934 Handle<JSObject> ext(JSObject::cast(context->extension())); 11012 Handle<JSObject> ext(JSObject::cast(context->extension()));
10935 if (ext->HasProperty(*variable_name)) { 11013 if (ext->HasProperty(*variable_name)) {
10936 // We don't expect this to do anything except replacing property value. 11014 // We don't expect this to do anything except replacing property value.
10937 SetProperty(isolate, 11015 SetProperty(isolate,
10938 ext, 11016 ext,
(...skipping 24 matching lines...) Expand all
10963 catch_scope, 11041 catch_scope,
10964 name, 11042 name,
10965 thrown_object, 11043 thrown_object,
10966 NONE, 11044 NONE,
10967 kNonStrictMode), 11045 kNonStrictMode),
10968 Handle<JSObject>()); 11046 Handle<JSObject>());
10969 return catch_scope; 11047 return catch_scope;
10970 } 11048 }
10971 11049
10972 11050
11051 static bool SetCatchVariableValue(Isolate* isolate,
11052 Handle<Context> context,
11053 Handle<String> variable_name,
11054 Handle<Object> new_value) {
11055 ASSERT(context->IsCatchContext());
11056 Handle<String> name(String::cast(context->extension()));
11057 if (!name->Equals(*variable_name)) {
11058 return false;
11059 }
11060 context->set(Context::THROWN_OBJECT_INDEX, *new_value);
11061 return true;
11062 }
11063
11064
10973 // Create a plain JSObject which materializes the block scope for the specified 11065 // Create a plain JSObject which materializes the block scope for the specified
10974 // block context. 11066 // block context.
10975 static Handle<JSObject> MaterializeBlockScope( 11067 static Handle<JSObject> MaterializeBlockScope(
10976 Isolate* isolate, 11068 Isolate* isolate,
10977 Handle<Context> context) { 11069 Handle<Context> context) {
10978 ASSERT(context->IsBlockContext()); 11070 ASSERT(context->IsBlockContext());
10979 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension())); 11071 Handle<ScopeInfo> scope_info(ScopeInfo::cast(context->extension()));
10980 11072
10981 // Allocate and initialize a JSObject with all the arguments, stack locals 11073 // Allocate and initialize a JSObject with all the arguments, stack locals
10982 // heap locals and extension properties of the debugged function. 11074 // heap locals and extension properties of the debugged function.
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
11228 return Handle<JSObject>(); 11320 return Handle<JSObject>();
11229 } 11321 }
11230 11322
11231 bool SetVariableValue(Handle<String> variable_name, 11323 bool SetVariableValue(Handle<String> variable_name,
11232 Handle<Object> new_value) { 11324 Handle<Object> new_value) {
11233 ASSERT(!failed_); 11325 ASSERT(!failed_);
11234 switch (Type()) { 11326 switch (Type()) {
11235 case ScopeIterator::ScopeTypeGlobal: 11327 case ScopeIterator::ScopeTypeGlobal:
11236 break; 11328 break;
11237 case ScopeIterator::ScopeTypeLocal: 11329 case ScopeIterator::ScopeTypeLocal:
11238 // TODO(2399): implement. 11330 return SetLocalVariableValue(isolate_, frame_, inlined_jsframe_index_,
11239 break; 11331 variable_name, new_value);
11240 case ScopeIterator::ScopeTypeWith: 11332 case ScopeIterator::ScopeTypeWith:
11241 break; 11333 break;
11242 case ScopeIterator::ScopeTypeCatch: 11334 case ScopeIterator::ScopeTypeCatch:
11243 // TODO(2399): implement. 11335 return SetCatchVariableValue(isolate_, CurrentContext(),
11244 break; 11336 variable_name, new_value);
11245 case ScopeIterator::ScopeTypeClosure: 11337 case ScopeIterator::ScopeTypeClosure:
11246 return SetClosureVariableValue(isolate_, CurrentContext(), 11338 return SetClosureVariableValue(isolate_, CurrentContext(),
11247 variable_name, new_value); 11339 variable_name, new_value);
11248 case ScopeIterator::ScopeTypeBlock: 11340 case ScopeIterator::ScopeTypeBlock:
11249 // TODO(2399): should we implement it? 11341 // TODO(2399): should we implement it?
11250 break; 11342 break;
11251 case ScopeIterator::ScopeTypeModule: 11343 case ScopeIterator::ScopeTypeModule:
11252 // TODO(2399): should we implement it? 11344 // TODO(2399): should we implement it?
11253 break; 11345 break;
11254 } 11346 }
(...skipping 2294 matching lines...) Expand 10 before | Expand all | Expand 10 after
13549 // Handle last resort GC and make sure to allow future allocations 13641 // Handle last resort GC and make sure to allow future allocations
13550 // to grow the heap without causing GCs (if possible). 13642 // to grow the heap without causing GCs (if possible).
13551 isolate->counters()->gc_last_resort_from_js()->Increment(); 13643 isolate->counters()->gc_last_resort_from_js()->Increment();
13552 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13644 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13553 "Runtime::PerformGC"); 13645 "Runtime::PerformGC");
13554 } 13646 }
13555 } 13647 }
13556 13648
13557 13649
13558 } } // namespace v8::internal 13650 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698