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

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

Issue 1136883006: Reapply "Resolve references to "this" the same way as normal variables"" (Closed) Base URL: https://chromium.googlesource.com/v8/v8@master
Patch Set: Fix this reference in super call, fix "this" in debug evaluator Created 5 years, 7 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
« no previous file with comments | « src/preparser.h ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 841 matching lines...) Expand 10 before | Expand all | Expand 10 after
852 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info, 852 static bool ParameterIsShadowedByContextLocal(Handle<ScopeInfo> info,
853 Handle<String> parameter_name) { 853 Handle<String> parameter_name) {
854 VariableMode mode; 854 VariableMode mode;
855 InitializationFlag init_flag; 855 InitializationFlag init_flag;
856 MaybeAssignedFlag maybe_assigned_flag; 856 MaybeAssignedFlag maybe_assigned_flag;
857 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag, 857 return ScopeInfo::ContextSlotIndex(info, parameter_name, &mode, &init_flag,
858 &maybe_assigned_flag) != -1; 858 &maybe_assigned_flag) != -1;
859 } 859 }
860 860
861 861
862 MUST_USE_RESULT
863 static MaybeHandle<Context> MaterializeReceiver(
864 Isolate* isolate, Handle<Context> target, Handle<JSFunction> function,
865 JavaScriptFrame* frame) {
866 Handle<SharedFunctionInfo> shared(function->shared());
867 Handle<ScopeInfo> scope_info(shared->scope_info());
868 Handle<Object> receiver;
869 switch (scope_info->scope_type()) {
870 case FUNCTION_SCOPE: {
871 VariableMode variable_mode;
872 InitializationFlag init_flag;
873 MaybeAssignedFlag maybe_assigned_flag;
874
875 // Don't bother creating a fake context node if "this" is in the context
876 // already.
877 if (ScopeInfo::ContextSlotIndex(scope_info,
878 isolate->factory()->this_string(), &variable_mode, &init_flag,
879 &maybe_assigned_flag) >= 0) {
880 return target;
881 }
882 receiver = Handle<Object>(frame->receiver(), isolate);
883 break;
884 }
885 case MODULE_SCOPE:
886 receiver = isolate->factory()->undefined_value();
887 break;
888 case SCRIPT_SCOPE:
889 receiver = Handle<Object>(function->global_proxy(), isolate);
890 break;
891 default:
892 // For eval code, arrow functions, and the like, there's no "this" binding
893 // to materialize.
894 return target;
895 }
896
897 return isolate->factory()->NewCatchContext(function, target,
898 isolate->factory()->this_string(), receiver);
899 }
900
901
862 // Create a plain JSObject which materializes the local scope for the specified 902 // Create a plain JSObject which materializes the local scope for the specified
863 // frame. 903 // frame.
864 MUST_USE_RESULT 904 MUST_USE_RESULT
865 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( 905 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector(
866 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, 906 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info,
867 FrameInspector* frame_inspector) { 907 FrameInspector* frame_inspector) {
868 // First fill all parameters. 908 // First fill all parameters.
869 for (int i = 0; i < scope_info->ParameterCount(); ++i) { 909 for (int i = 0; i < scope_info->ParameterCount(); ++i) {
870 // Do not materialize the parameter if it is shadowed by a context local. 910 // Do not materialize the parameter if it is shadowed by a context local.
871 Handle<String> name(scope_info->ParameterName(i)); 911 Handle<String> name(scope_info->ParameterName(i));
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
1468 // Move to the next scope. 1508 // Move to the next scope.
1469 void Next() { 1509 void Next() {
1470 DCHECK(!failed_); 1510 DCHECK(!failed_);
1471 ScopeType scope_type = Type(); 1511 ScopeType scope_type = Type();
1472 if (scope_type == ScopeTypeGlobal) { 1512 if (scope_type == ScopeTypeGlobal) {
1473 // The global scope is always the last in the chain. 1513 // The global scope is always the last in the chain.
1474 DCHECK(context_->IsNativeContext()); 1514 DCHECK(context_->IsNativeContext());
1475 context_ = Handle<Context>(); 1515 context_ = Handle<Context>();
1476 return; 1516 return;
1477 } 1517 }
1478 if (scope_type == ScopeTypeScript) seen_script_scope_ = true; 1518 if (scope_type == ScopeTypeScript) {
1479 if (nested_scope_chain_.is_empty()) { 1519 seen_script_scope_ = true;
1480 if (scope_type == ScopeTypeScript) { 1520 if (context_->IsScriptContext()) {
1481 if (context_->IsScriptContext()) {
1482 context_ = Handle<Context>(context_->previous(), isolate_);
1483 }
1484 CHECK(context_->IsNativeContext());
1485 } else {
1486 context_ = Handle<Context>(context_->previous(), isolate_); 1521 context_ = Handle<Context>(context_->previous(), isolate_);
1487 } 1522 }
1523 if (!nested_scope_chain_.is_empty()) {
1524 DCHECK_EQ(nested_scope_chain_.last()->scope_type(), SCRIPT_SCOPE);
1525 nested_scope_chain_.RemoveLast();
1526 DCHECK(nested_scope_chain_.is_empty());
1527 }
1528 CHECK(context_->IsNativeContext());
1529 return;
1530 }
1531 if (nested_scope_chain_.is_empty()) {
1532 context_ = Handle<Context>(context_->previous(), isolate_);
1488 } else { 1533 } else {
1489 if (nested_scope_chain_.last()->HasContext()) { 1534 if (nested_scope_chain_.last()->HasContext()) {
1490 DCHECK(context_->previous() != NULL); 1535 DCHECK(context_->previous() != NULL);
1491 context_ = Handle<Context>(context_->previous(), isolate_); 1536 context_ = Handle<Context>(context_->previous(), isolate_);
1492 } 1537 }
1493 nested_scope_chain_.RemoveLast(); 1538 nested_scope_chain_.RemoveLast();
1494 } 1539 }
1495 } 1540 }
1496 1541
1497 // Return the type of the current scope. 1542 // Return the type of the current scope.
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after
2446 : isolate_(isolate), 2491 : isolate_(isolate),
2447 frame_(frame), 2492 frame_(frame),
2448 inlined_jsframe_index_(inlined_jsframe_index) { 2493 inlined_jsframe_index_(inlined_jsframe_index) {
2449 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); 2494 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate);
2450 Handle<JSFunction> function = 2495 Handle<JSFunction> function =
2451 handle(JSFunction::cast(frame_inspector.GetFunction())); 2496 handle(JSFunction::cast(frame_inspector.GetFunction()));
2452 Handle<Context> outer_context = handle(function->context(), isolate); 2497 Handle<Context> outer_context = handle(function->context(), isolate);
2453 outer_info_ = handle(function->shared()); 2498 outer_info_ = handle(function->shared());
2454 Handle<Context> inner_context; 2499 Handle<Context> inner_context;
2455 2500
2501 // The "this" binding, if any, can't be bound via "with". If we need to,
2502 // add another node onto the outer context to bind "this".
2503 if (!MaterializeReceiver(isolate, outer_context, function, frame)
2504 .ToHandle(&outer_context))
2505 return;
2506
2456 bool stop = false; 2507 bool stop = false;
2457 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); 2508 for (ScopeIterator it(isolate, frame, inlined_jsframe_index);
2458 !it.Failed() && !it.Done() && !stop; it.Next()) { 2509 !it.Failed() && !it.Done() && !stop; it.Next()) {
2459 ScopeIterator::ScopeType scope_type = it.Type(); 2510 ScopeIterator::ScopeType scope_type = it.Type();
2460 2511
2461 if (scope_type == ScopeIterator::ScopeTypeLocal) { 2512 if (scope_type == ScopeIterator::ScopeTypeLocal) {
2462 Handle<JSObject> materialized_function = 2513 Handle<JSObject> materialized_function =
2463 NewJSObjectWithNullProto(isolate); 2514 NewJSObjectWithNullProto(isolate);
2464 2515
2465 if (!MaterializeStackLocalsWithFrameInspector( 2516 if (!MaterializeStackLocalsWithFrameInspector(
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after
3157 return Smi::FromInt(isolate->debug()->is_active()); 3208 return Smi::FromInt(isolate->debug()->is_active());
3158 } 3209 }
3159 3210
3160 3211
3161 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { 3212 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) {
3162 UNIMPLEMENTED(); 3213 UNIMPLEMENTED();
3163 return NULL; 3214 return NULL;
3164 } 3215 }
3165 } 3216 }
3166 } // namespace v8::internal 3217 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/preparser.h ('k') | src/runtime/runtime-scopes.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698