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( | |
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 | |
902 // Create a plain JSObject which materializes the local scope for the specified | 862 // Create a plain JSObject which materializes the local scope for the specified |
903 // frame. | 863 // frame. |
904 MUST_USE_RESULT | 864 MUST_USE_RESULT |
905 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( | 865 static MaybeHandle<JSObject> MaterializeStackLocalsWithFrameInspector( |
906 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, | 866 Isolate* isolate, Handle<JSObject> target, Handle<ScopeInfo> scope_info, |
907 FrameInspector* frame_inspector) { | 867 FrameInspector* frame_inspector) { |
908 // First fill all parameters. | 868 // First fill all parameters. |
909 for (int i = 0; i < scope_info->ParameterCount(); ++i) { | 869 for (int i = 0; i < scope_info->ParameterCount(); ++i) { |
910 // Do not materialize the parameter if it is shadowed by a context local. | 870 // Do not materialize the parameter if it is shadowed by a context local. |
911 Handle<String> name(scope_info->ParameterName(i)); | 871 Handle<String> name(scope_info->ParameterName(i)); |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1508 // Move to the next scope. | 1468 // Move to the next scope. |
1509 void Next() { | 1469 void Next() { |
1510 DCHECK(!failed_); | 1470 DCHECK(!failed_); |
1511 ScopeType scope_type = Type(); | 1471 ScopeType scope_type = Type(); |
1512 if (scope_type == ScopeTypeGlobal) { | 1472 if (scope_type == ScopeTypeGlobal) { |
1513 // The global scope is always the last in the chain. | 1473 // The global scope is always the last in the chain. |
1514 DCHECK(context_->IsNativeContext()); | 1474 DCHECK(context_->IsNativeContext()); |
1515 context_ = Handle<Context>(); | 1475 context_ = Handle<Context>(); |
1516 return; | 1476 return; |
1517 } | 1477 } |
1518 if (scope_type == ScopeTypeScript) { | 1478 if (scope_type == ScopeTypeScript) seen_script_scope_ = true; |
1519 seen_script_scope_ = true; | 1479 if (nested_scope_chain_.is_empty()) { |
1520 if (context_->IsScriptContext()) { | 1480 if (scope_type == ScopeTypeScript) { |
| 1481 if (context_->IsScriptContext()) { |
| 1482 context_ = Handle<Context>(context_->previous(), isolate_); |
| 1483 } |
| 1484 CHECK(context_->IsNativeContext()); |
| 1485 } else { |
1521 context_ = Handle<Context>(context_->previous(), isolate_); | 1486 context_ = Handle<Context>(context_->previous(), isolate_); |
1522 } | 1487 } |
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_); | |
1533 } else { | 1488 } else { |
1534 if (nested_scope_chain_.last()->HasContext()) { | 1489 if (nested_scope_chain_.last()->HasContext()) { |
1535 DCHECK(context_->previous() != NULL); | 1490 DCHECK(context_->previous() != NULL); |
1536 context_ = Handle<Context>(context_->previous(), isolate_); | 1491 context_ = Handle<Context>(context_->previous(), isolate_); |
1537 } | 1492 } |
1538 nested_scope_chain_.RemoveLast(); | 1493 nested_scope_chain_.RemoveLast(); |
1539 } | 1494 } |
1540 } | 1495 } |
1541 | 1496 |
1542 // Return the type of the current scope. | 1497 // Return the type of the current scope. |
(...skipping 948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2491 : isolate_(isolate), | 2446 : isolate_(isolate), |
2492 frame_(frame), | 2447 frame_(frame), |
2493 inlined_jsframe_index_(inlined_jsframe_index) { | 2448 inlined_jsframe_index_(inlined_jsframe_index) { |
2494 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); | 2449 FrameInspector frame_inspector(frame, inlined_jsframe_index, isolate); |
2495 Handle<JSFunction> function = | 2450 Handle<JSFunction> function = |
2496 handle(JSFunction::cast(frame_inspector.GetFunction())); | 2451 handle(JSFunction::cast(frame_inspector.GetFunction())); |
2497 Handle<Context> outer_context = handle(function->context(), isolate); | 2452 Handle<Context> outer_context = handle(function->context(), isolate); |
2498 outer_info_ = handle(function->shared()); | 2453 outer_info_ = handle(function->shared()); |
2499 Handle<Context> inner_context; | 2454 Handle<Context> inner_context; |
2500 | 2455 |
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 | |
2507 bool stop = false; | 2456 bool stop = false; |
2508 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); | 2457 for (ScopeIterator it(isolate, frame, inlined_jsframe_index); |
2509 !it.Failed() && !it.Done() && !stop; it.Next()) { | 2458 !it.Failed() && !it.Done() && !stop; it.Next()) { |
2510 ScopeIterator::ScopeType scope_type = it.Type(); | 2459 ScopeIterator::ScopeType scope_type = it.Type(); |
2511 | 2460 |
2512 if (scope_type == ScopeIterator::ScopeTypeLocal) { | 2461 if (scope_type == ScopeIterator::ScopeTypeLocal) { |
2513 Handle<JSObject> materialized_function = | 2462 Handle<JSObject> materialized_function = |
2514 NewJSObjectWithNullProto(isolate); | 2463 NewJSObjectWithNullProto(isolate); |
2515 | 2464 |
2516 if (!MaterializeStackLocalsWithFrameInspector( | 2465 if (!MaterializeStackLocalsWithFrameInspector( |
(...skipping 691 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3208 return Smi::FromInt(isolate->debug()->is_active()); | 3157 return Smi::FromInt(isolate->debug()->is_active()); |
3209 } | 3158 } |
3210 | 3159 |
3211 | 3160 |
3212 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 3161 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
3213 UNIMPLEMENTED(); | 3162 UNIMPLEMENTED(); |
3214 return NULL; | 3163 return NULL; |
3215 } | 3164 } |
3216 } | 3165 } |
3217 } // namespace v8::internal | 3166 } // namespace v8::internal |
OLD | NEW |