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

Side by Side Diff: src/runtime/runtime-debug.cc

Issue 1218783005: Support for global var shortcuts in script contexts. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 5 months 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
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/accessors.h" 7 #include "src/accessors.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/compiler.h" 9 #include "src/compiler.h"
10 #include "src/debug.h" 10 #include "src/debug.h"
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after
674 local++; 674 local++;
675 } 675 }
676 if (local < local_count) { 676 if (local < local_count) {
677 // Get the context containing declarations. 677 // Get the context containing declarations.
678 Handle<Context> context( 678 Handle<Context> context(
679 Context::cast(frame_inspector.GetContext())->declaration_context()); 679 Context::cast(frame_inspector.GetContext())->declaration_context());
680 for (; i < scope_info->LocalCount(); ++i) { 680 for (; i < scope_info->LocalCount(); ++i) {
681 if (scope_info->LocalIsSynthetic(i)) continue; 681 if (scope_info->LocalIsSynthetic(i)) continue;
682 Handle<String> name(scope_info->LocalName(i)); 682 Handle<String> name(scope_info->LocalName(i));
683 VariableMode mode; 683 VariableMode mode;
684 ContextSlotKindFlag slot_kind;
684 InitializationFlag init_flag; 685 InitializationFlag init_flag;
685 MaybeAssignedFlag maybe_assigned_flag; 686 MaybeAssignedFlag maybe_assigned_flag;
686 locals->set(local * 2, *name); 687 locals->set(local * 2, *name);
687 int context_slot_index = ScopeInfo::ContextSlotIndex( 688 int context_slot_index =
688 scope_info, name, &mode, &init_flag, &maybe_assigned_flag); 689 ScopeInfo::ContextSlotIndex(scope_info, name, &mode, &slot_kind,
690 &init_flag, &maybe_assigned_flag);
691 DCHECK(ContextSlotKindFlag::kLocal == slot_kind);
Toon Verwaest 2015/07/01 09:28:55 DCHECK_EQ This may not be necessary anymore if you
Igor Sheludko 2015/07/02 16:50:13 Done.
689 Object* value = context->get(context_slot_index); 692 Object* value = context->get(context_slot_index);
690 locals->set(local * 2 + 1, value); 693 locals->set(local * 2 + 1, value);
691 local++; 694 local++;
692 } 695 }
693 } 696 }
694 697
695 // Check whether this frame is positioned at return. If not top 698 // Check whether this frame is positioned at return. If not top
696 // frame or if the frame is optimized it cannot be at a return. 699 // frame or if the frame is optimized it cannot be at a return.
697 bool at_return = false; 700 bool at_return = false;
698 if (!is_optimized && index == 0) { 701 if (!is_optimized && index == 0) {
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
849 details->set(kFrameDetailsReceiverIndex, *receiver); 852 details->set(kFrameDetailsReceiverIndex, *receiver);
850 853
851 DCHECK_EQ(details_size, details_index); 854 DCHECK_EQ(details_size, details_index);
852 return *isolate->factory()->NewJSArrayWithElements(details); 855 return *isolate->factory()->NewJSArrayWithElements(details);
853 } 856 }
854 857
855 858
856 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info, 859 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info,
857 Handle<String> parameter_name) { 860 Handle<String> parameter_name) {
858 VariableMode mode; 861 VariableMode mode;
862 ContextSlotKindFlag slot_kind;
859 InitializationFlag init_flag; 863 InitializationFlag init_flag;
860 MaybeAssignedFlag maybe_assigned_flag; 864 MaybeAssignedFlag maybe_assigned_flag;
861 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag, 865 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &slot_kind,
862 &maybe_assigned_flag) != -1; 866 &init_flag, &maybe_assigned_flag) != -1;
863 } 867 }
864 868
865 869
866 static Handle<Context> MaterializeReceiver(Isolate* isolate, 870 static Handle<Context> MaterializeReceiver(Isolate* isolate,
867 Handle<Context> target, 871 Handle<Context> target,
868 Handle<JSFunction> function, 872 Handle<JSFunction> function,
869 JavaScriptFrame* frame) { 873 JavaScriptFrame* frame) {
870 Handle<SharedFunctionInfo> shared(function->shared()); 874 Handle<SharedFunctionInfo> shared(function->shared());
871 Handle<ScopeInfo> scope_info(shared->scope_info()); 875 Handle<ScopeInfo> scope_info(shared->scope_info());
872 Handle<Object> receiver; 876 Handle<Object> receiver;
873 switch (scope_info->scope_type()) { 877 switch (scope_info->scope_type()) {
874 case FUNCTION_SCOPE: { 878 case FUNCTION_SCOPE: {
875 VariableMode variable_mode; 879 VariableMode variable_mode;
880 ContextSlotKindFlag slot_kind;
876 InitializationFlag init_flag; 881 InitializationFlag init_flag;
877 MaybeAssignedFlag maybe_assigned_flag; 882 MaybeAssignedFlag maybe_assigned_flag;
878 883
879 // Don't bother creating a fake context node if "this" is in the context 884 // Don't bother creating a fake context node if "this" is in the context
880 // already. 885 // already.
881 if (ScopeInfo::ContextSlotIndex( 886 if (ScopeInfo::ContextSlotIndex(
882 scope_info, isolate->factory()->this_string(), &variable_mode, 887 scope_info, isolate->factory()->this_string(), &variable_mode,
883 &init_flag, &maybe_assigned_flag) >= 0) { 888 &slot_kind, &init_flag, &maybe_assigned_flag) >= 0) {
884 return target; 889 return target;
885 } 890 }
886 receiver = handle(frame->receiver(), isolate); 891 receiver = handle(frame->receiver(), isolate);
887 break; 892 break;
888 } 893 }
889 case MODULE_SCOPE: 894 case MODULE_SCOPE:
890 receiver = isolate->factory()->undefined_value(); 895 receiver = isolate->factory()->undefined_value();
891 break; 896 break;
892 case SCRIPT_SCOPE: 897 case SCRIPT_SCOPE:
893 receiver = handle(function->global_proxy(), isolate); 898 receiver = handle(function->global_proxy(), isolate);
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
1070 1075
1071 // Set the context local variable value. 1076 // Set the context local variable value.
1072 static bool SetContextLocalValue(Isolate* isolate, Handle<ScopeInfo> scope_info, 1077 static bool SetContextLocalValue(Isolate* isolate, Handle<ScopeInfo> scope_info,
1073 Handle<Context> context, 1078 Handle<Context> context,
1074 Handle<String> variable_name, 1079 Handle<String> variable_name,
1075 Handle<Object> new_value) { 1080 Handle<Object> new_value) {
1076 for (int i = 0; i < scope_info->ContextLocalCount(); i++) { 1081 for (int i = 0; i < scope_info->ContextLocalCount(); i++) {
1077 Handle<String> next_name(scope_info->ContextLocalName(i)); 1082 Handle<String> next_name(scope_info->ContextLocalName(i));
1078 if (String::Equals(variable_name, next_name)) { 1083 if (String::Equals(variable_name, next_name)) {
1079 VariableMode mode; 1084 VariableMode mode;
1085 ContextSlotKindFlag slot_kind;
1080 InitializationFlag init_flag; 1086 InitializationFlag init_flag;
1081 MaybeAssignedFlag maybe_assigned_flag; 1087 MaybeAssignedFlag maybe_assigned_flag;
1082 int context_index = ScopeInfo::ContextSlotIndex( 1088 int context_index =
1083 scope_info, next_name, &mode, &init_flag, &maybe_assigned_flag); 1089 ScopeInfo::ContextSlotIndex(scope_info, next_name, &mode, &slot_kind,
1090 &init_flag, &maybe_assigned_flag);
1084 context->set(context_index, *new_value); 1091 context->set(context_index, *new_value);
1085 return true; 1092 return true;
1086 } 1093 }
1087 } 1094 }
1088 1095
1089 return false; 1096 return false;
1090 } 1097 }
1091 1098
1092 1099
1093 static bool SetLocalVariableValue(Isolate* isolate, JavaScriptFrame* frame, 1100 static bool SetLocalVariableValue(Isolate* isolate, JavaScriptFrame* frame,
(...skipping 1570 matching lines...) Expand 10 before | Expand all | Expand 10 after
2664 isolate, context_builder.outer_info(), 2671 isolate, context_builder.outer_info(),
2665 context_builder.innermost_context(), context_extension, receiver, source); 2672 context_builder.innermost_context(), context_extension, receiver, source);
2666 2673
2667 Handle<Object> result; 2674 Handle<Object> result;
2668 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, maybe_result); 2675 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, result, maybe_result);
2669 context_builder.UpdateVariables(); 2676 context_builder.UpdateVariables();
2670 return *result; 2677 return *result;
2671 } 2678 }
2672 2679
2673 2680
2681 static inline bool IsDebugContext(Isolate* isolate, Context* context) {
2682 // Try to unwrap script context if it exist.
2683 if (context->IsScriptContext()) context = context->previous();
2684 DCHECK_NOT_NULL(context);
2685 return context == *isolate->debug()->debug_context();
2686 }
2687
2688
2674 RUNTIME_FUNCTION(Runtime_DebugEvaluateGlobal) { 2689 RUNTIME_FUNCTION(Runtime_DebugEvaluateGlobal) {
2675 HandleScope scope(isolate); 2690 HandleScope scope(isolate);
2676 2691
2677 // Check the execution state and decode arguments frame and source to be 2692 // Check the execution state and decode arguments frame and source to be
2678 // evaluated. 2693 // evaluated.
2679 DCHECK(args.length() == 4); 2694 DCHECK(args.length() == 4);
2680 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]); 2695 CONVERT_NUMBER_CHECKED(int, break_id, Int32, args[0]);
2681 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id)); 2696 RUNTIME_ASSERT(isolate->debug()->CheckExecutionState(break_id));
2682 2697
2683 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); 2698 CONVERT_ARG_HANDLE_CHECKED(String, source, 1);
2684 CONVERT_BOOLEAN_ARG_CHECKED(disable_break, 2); 2699 CONVERT_BOOLEAN_ARG_CHECKED(disable_break, 2);
2685 CONVERT_ARG_HANDLE_CHECKED(Object, context_extension, 3); 2700 CONVERT_ARG_HANDLE_CHECKED(Object, context_extension, 3);
2686 2701
2687 // Handle the processing of break. 2702 // Handle the processing of break.
2688 DisableBreak disable_break_scope(isolate->debug(), disable_break); 2703 DisableBreak disable_break_scope(isolate->debug(), disable_break);
2689 2704
2690 // Enter the top context from before the debugger was invoked. 2705 // Enter the top context from before the debugger was invoked.
2691 SaveContext save(isolate); 2706 SaveContext save(isolate);
2692 SaveContext* top = &save; 2707 SaveContext* top = &save;
2693 while (top != NULL && *top->context() == *isolate->debug()->debug_context()) { 2708 while (top != NULL && IsDebugContext(isolate, *top->context())) {
2694 top = top->prev(); 2709 top = top->prev();
2695 } 2710 }
2696 if (top != NULL) { 2711 if (top != NULL) {
2697 isolate->set_context(*top->context()); 2712 isolate->set_context(*top->context());
2698 } 2713 }
2699 2714
2700 // Get the native context now set to the top context from before the 2715 // Get the native context now set to the top context from before the
2701 // debugger was invoked. 2716 // debugger was invoked.
2702 Handle<Context> context = isolate->native_context(); 2717 Handle<Context> context = isolate->native_context();
2703 Handle<JSObject> receiver(context->global_proxy()); 2718 Handle<JSObject> receiver(context->global_proxy());
(...skipping 493 matching lines...) Expand 10 before | Expand all | Expand 10 after
3197 return Smi::FromInt(isolate->debug()->is_active()); 3212 return Smi::FromInt(isolate->debug()->is_active());
3198 } 3213 }
3199 3214
3200 3215
3201 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 3216 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
3202 UNIMPLEMENTED(); 3217 UNIMPLEMENTED();
3203 return NULL; 3218 return NULL;
3204 } 3219 }
3205 } // namespace internal 3220 } // namespace internal
3206 } // namespace v8 3221 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698