OLD | NEW |
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 Loading... |
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(Isolate* isolate, |
| 864 Handle<Context> target, |
| 865 Handle<JSFunction> function, |
| 866 JavaScriptFrame* frame) { |
| 867 Handle<SharedFunctionInfo> shared(function->shared()); |
| 868 Handle<ScopeInfo> scope_info(shared->scope_info()); |
| 869 Handle<Object> receiver; |
| 870 switch (scope_info->scope_type()) { |
| 871 case FUNCTION_SCOPE: { |
| 872 VariableMode variable_mode; |
| 873 InitializationFlag init_flag; |
| 874 MaybeAssignedFlag maybe_assigned_flag; |
| 875 |
| 876 // Don't bother creating a fake context node if "this" is in the context |
| 877 // already. |
| 878 if (ScopeInfo::ContextSlotIndex( |
| 879 scope_info, isolate->factory()->this_string(), &variable_mode, |
| 880 &init_flag, &maybe_assigned_flag) >= 0) { |
| 881 return target; |
| 882 } |
| 883 receiver = Handle<Object>(frame->receiver(), isolate); |
| 884 break; |
| 885 } |
| 886 case MODULE_SCOPE: |
| 887 receiver = isolate->factory()->undefined_value(); |
| 888 break; |
| 889 case SCRIPT_SCOPE: |
| 890 receiver = Handle<Object>(function->global_proxy(), isolate); |
| 891 break; |
| 892 default: |
| 893 // For eval code, arrow functions, and the like, there's no "this" binding |
| 894 // to materialize. |
| 895 return target; |
| 896 } |
| 897 |
| 898 return isolate->factory()->NewCatchContext( |
| 899 function, target, isolate->factory()->this_string(), receiver); |
| 900 } |
| 901 |
| 902 |
862 // Create a plain JSObject which materializes the local scope for the specified | 903 // Create a plain JSObject which materializes the local scope for the specified |
863 // frame. | 904 // frame. |
864 MUST_USE_RESULT | 905 MUST_USE_RESULT |
865 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( | 906 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( |
866 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, | 907 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, |
867 FrameInspector* frame_inspector) { | 908 FrameInspector* frame_inspector) { |
868 // First fill all parameters. | 909 // First fill all parameters. |
869 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 910 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
870 // Do not materialize the parameter if it is shadowed by a context local. | 911 // Do not materialize the parameter if it is shadowed by a context local. |
871 Handle<String> name(scope_info->ParameterName(i)); | 912 Handle<String> name(scope_info->ParameterName(i)); |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1468 // Move to the next scope. | 1509 // Move to the next scope. |
1469 void Next() { | 1510 void Next() { |
1470 DCHECK(!failed_); | 1511 DCHECK(!failed_); |
1471 ScopeType scope_type = Type(); | 1512 ScopeType scope_type = Type(); |
1472 if (scope_type == ScopeTypeGlobal) { | 1513 if (scope_type == ScopeTypeGlobal) { |
1473 // The global scope is always the last in the chain. | 1514 // The global scope is always the last in the chain. |
1474 DCHECK(context_->IsNativeContext()); | 1515 DCHECK(context_->IsNativeContext()); |
1475 context_ = Handle<Context>(); | 1516 context_ = Handle<Context>(); |
1476 return; | 1517 return; |
1477 } | 1518 } |
1478 if (scope_type == ScopeTypeScript) seen_script_scope_ = true; | 1519 if (scope_type == ScopeTypeScript) { |
1479 if (nested_scope_chain_.is_empty()) { | 1520 seen_script_scope_ = true; |
1480 if (scope_type == ScopeTypeScript) { | 1521 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_); | 1522 context_ = Handle<Context>(context_->previous(), isolate_); |
1487 } | 1523 } |
| 1524 if (!nested_scope_chain_.is_empty()) { |
| 1525 DCHECK_EQ(nested_scope_chain_.last()->scope_type(), SCRIPT_SCOPE); |
| 1526 nested_scope_chain_.RemoveLast(); |
| 1527 DCHECK(nested_scope_chain_.is_empty()); |
| 1528 } |
| 1529 CHECK(context_->IsNativeContext()); |
| 1530 return; |
| 1531 } |
| 1532 if (nested_scope_chain_.is_empty()) { |
| 1533 context_ = Handle<Context>(context_->previous(), isolate_); |
1488 } else { | 1534 } else { |
1489 if (nested_scope_chain_.last()->HasContext()) { | 1535 if (nested_scope_chain_.last()->HasContext()) { |
1490 DCHECK(context_->previous() != NULL); | 1536 DCHECK(context_->previous() != NULL); |
1491 context_ = Handle<Context>(context_->previous(), isolate_); | 1537 context_ = Handle<Context>(context_->previous(), isolate_); |
1492 } | 1538 } |
1493 nested_scope_chain_.RemoveLast(); | 1539 nested_scope_chain_.RemoveLast(); |
1494 } | 1540 } |
1495 } | 1541 } |
1496 | 1542 |
1497 // Return the type of the current scope. | 1543 // Return the type of the current scope. |
(...skipping 946 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2444 : isolate_(isolate), | 2490 : isolate_(isolate), |
2445 frame_(frame), | 2491 frame_(frame), |
2446 inlined_jsframe_index_(inlined_jsframe_index) { | 2492 inlined_jsframe_index_(inlined_jsframe_index) { |
2447 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 2493 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
2448 Handle<JSFunction> function = | 2494 Handle<JSFunction> function = |
2449 handle(JSFunction::cast(frame_inspector.GetFunction())); | 2495 handle(JSFunction::cast(frame_inspector.GetFunction())); |
2450 Handle<Context> outer_context = handle(function->context(), isolate); | 2496 Handle<Context> outer_context = handle(function->context(), isolate); |
2451 outer_info_ = handle(function->shared()); | 2497 outer_info_ = handle(function->shared()); |
2452 Handle<Context> inner_context; | 2498 Handle<Context> inner_context; |
2453 | 2499 |
| 2500 // The "this" binding, if any, can't be bound via "with". If we need to, |
| 2501 // add another node onto the outer context to bind "this". |
| 2502 if (!MaterializeReceiver(isolate, outer_context, function, frame) |
| 2503 .ToHandle(&outer_context)) |
| 2504 return; |
| 2505 |
2454 bool stop = false; | 2506 bool stop = false; |
2455 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); | 2507 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); |
2456 !it.Failed() && !it.Done() && !stop; it.Next()) { | 2508 !it.Failed() && !it.Done() && !stop; it.Next()) { |
2457 ScopeIterator::ScopeType scope_type = it.Type(); | 2509 ScopeIterator::ScopeType scope_type = it.Type(); |
2458 | 2510 |
2459 if (scope_type == ScopeIterator::ScopeTypeLocal) { | 2511 if (scope_type == ScopeIterator::ScopeTypeLocal) { |
2460 Handle<JSObject> materialized_function = | 2512 Handle<JSObject> materialized_function = |
2461 NewJSObjectWithNullProto(isolate); | 2513 NewJSObjectWithNullProto(isolate); |
2462 | 2514 |
2463 if (!MaterializeStackLocalsWithFrameInspector( | 2515 if (!MaterializeStackLocalsWithFrameInspector( |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3155 return Smi::FromInt(isolate->debug()->is_active()); | 3207 return Smi::FromInt(isolate->debug()->is_active()); |
3156 } | 3208 } |
3157 | 3209 |
3158 | 3210 |
3159 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 3211 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
3160 UNIMPLEMENTED(); | 3212 UNIMPLEMENTED(); |
3161 return NULL; | 3213 return NULL; |
3162 } | 3214 } |
3163 } | 3215 } |
3164 } // namespace v8::internal | 3216 } // namespace v8::internal |
OLD | NEW |