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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/debug/debug.h" | 8 #include "src/debug/debug.h" |
9 #include "src/debug/debug-evaluate.h" | 9 #include "src/debug/debug-evaluate.h" |
10 #include "src/debug/debug-frames.h" | 10 #include "src/debug/debug-frames.h" |
(...skipping 1615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1626 return *Script::GetWrapper(found); | 1626 return *Script::GetWrapper(found); |
1627 } | 1627 } |
1628 | 1628 |
1629 | 1629 |
1630 bool DebugStepInIsActive(Debug* debug) { | 1630 bool DebugStepInIsActive(Debug* debug) { |
1631 return debug->is_active() && debug->IsStepping() && | 1631 return debug->is_active() && debug->IsStepping() && |
1632 debug->last_step_action() == StepIn; | 1632 debug->last_step_action() == StepIn; |
1633 } | 1633 } |
1634 | 1634 |
1635 | 1635 |
| 1636 // Check whether debugger is about to step into the callback that is passed |
| 1637 // to a built-in function such as Array.forEach. This check is done before |
| 1638 // %DebugPrepareStepInIfStepping and is not strictly necessary. However, if it |
| 1639 // returns false, we can skip %DebugPrepareStepInIfStepping, useful in loops. |
| 1640 RUNTIME_FUNCTION(Runtime_DebugCallbackSupportsStepping) { |
| 1641 SealHandleScope shs(isolate); |
| 1642 DCHECK(args.length() == 1); |
| 1643 if (!DebugStepInIsActive(isolate->debug())) { |
| 1644 return isolate->heap()->false_value(); |
| 1645 } |
| 1646 CONVERT_ARG_CHECKED(Object, object, 0); |
| 1647 RUNTIME_ASSERT(object->IsJSFunction() || object->IsJSGeneratorObject()); |
| 1648 // We do not step into the callback if it's a builtin other than a bound, |
| 1649 // or not even a function. |
| 1650 JSFunction* fun; |
| 1651 if (object->IsJSFunction()) { |
| 1652 fun = JSFunction::cast(object); |
| 1653 } else { |
| 1654 fun = JSGeneratorObject::cast(object)->function(); |
| 1655 } |
| 1656 return isolate->heap()->ToBoolean(fun->shared()->IsSubjectToDebugging() || |
| 1657 fun->shared()->bound()); |
| 1658 } |
| 1659 |
| 1660 |
| 1661 void FloodDebugSubjectWithOneShot(Debug* debug, Handle<JSFunction> function) { |
| 1662 if (function->shared()->IsSubjectToDebugging() || |
| 1663 function->shared()->bound()) { |
| 1664 // When leaving the function, step out has been activated, but not performed |
| 1665 // if we do not leave the builtin. To be able to step into the function |
| 1666 // again, we need to clear the step out at this point. |
| 1667 debug->ClearStepOut(); |
| 1668 debug->FloodWithOneShotGeneric(function); |
| 1669 } |
| 1670 } |
| 1671 |
| 1672 |
1636 // Set one shot breakpoints for the callback function that is passed to a | 1673 // Set one shot breakpoints for the callback function that is passed to a |
1637 // built-in function such as Array.forEach to enable stepping into the callback, | 1674 // built-in function such as Array.forEach to enable stepping into the callback, |
1638 // if we are indeed stepping and the callback is subject to debugging. | 1675 // if we are indeed stepping and the callback is subject to debugging. |
1639 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { | 1676 RUNTIME_FUNCTION(Runtime_DebugPrepareStepInIfStepping) { |
1640 DCHECK(args.length() == 1); | 1677 DCHECK(args.length() == 1); |
1641 Debug* debug = isolate->debug(); | 1678 Debug* debug = isolate->debug(); |
1642 if (debug->in_debug_scope() || !DebugStepInIsActive(debug)) { | 1679 if (!DebugStepInIsActive(debug)) return isolate->heap()->undefined_value(); |
1643 return isolate->heap()->undefined_value(); | |
1644 } | |
1645 | 1680 |
1646 HandleScope scope(isolate); | 1681 HandleScope scope(isolate); |
1647 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | 1682 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
1648 RUNTIME_ASSERT(object->IsJSFunction() || object->IsJSGeneratorObject()); | 1683 RUNTIME_ASSERT(object->IsJSFunction() || object->IsJSGeneratorObject()); |
1649 Handle<JSFunction> fun; | 1684 Handle<JSFunction> fun; |
1650 if (object->IsJSFunction()) { | 1685 if (object->IsJSFunction()) { |
1651 fun = Handle<JSFunction>::cast(object); | 1686 fun = Handle<JSFunction>::cast(object); |
1652 } else { | 1687 } else { |
1653 fun = Handle<JSFunction>( | 1688 fun = Handle<JSFunction>( |
1654 Handle<JSGeneratorObject>::cast(object)->function(), isolate); | 1689 Handle<JSGeneratorObject>::cast(object)->function(), isolate); |
1655 } | 1690 } |
1656 | 1691 |
1657 debug->ClearStepOut(); | 1692 FloodDebugSubjectWithOneShot(debug, fun); |
1658 debug->FloodWithOneShotGeneric(fun); | |
1659 return isolate->heap()->undefined_value(); | 1693 return isolate->heap()->undefined_value(); |
1660 } | 1694 } |
1661 | 1695 |
1662 | 1696 |
1663 RUNTIME_FUNCTION(Runtime_DebugPushPromise) { | 1697 RUNTIME_FUNCTION(Runtime_DebugPushPromise) { |
1664 DCHECK(args.length() == 2); | 1698 DCHECK(args.length() == 3); |
1665 HandleScope scope(isolate); | 1699 HandleScope scope(isolate); |
1666 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); | 1700 CONVERT_ARG_HANDLE_CHECKED(JSObject, promise, 0); |
1667 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); | 1701 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 1); |
| 1702 CONVERT_ARG_HANDLE_CHECKED(Object, handler, 2); |
1668 isolate->PushPromise(promise, function); | 1703 isolate->PushPromise(promise, function); |
| 1704 Debug* debug = isolate->debug(); |
| 1705 if (handler->IsJSFunction() && DebugStepInIsActive(debug)) { |
| 1706 FloodDebugSubjectWithOneShot(debug, Handle<JSFunction>::cast(handler)); |
| 1707 } |
1669 return isolate->heap()->undefined_value(); | 1708 return isolate->heap()->undefined_value(); |
1670 } | 1709 } |
1671 | 1710 |
1672 | 1711 |
1673 RUNTIME_FUNCTION(Runtime_DebugPopPromise) { | 1712 RUNTIME_FUNCTION(Runtime_DebugPopPromise) { |
1674 DCHECK(args.length() == 0); | 1713 DCHECK(args.length() == 0); |
1675 SealHandleScope shs(isolate); | 1714 SealHandleScope shs(isolate); |
1676 isolate->PopPromise(); | 1715 isolate->PopPromise(); |
1677 return isolate->heap()->undefined_value(); | 1716 return isolate->heap()->undefined_value(); |
1678 } | 1717 } |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1712 return *isolate->factory()->undefined_value(); | 1751 return *isolate->factory()->undefined_value(); |
1713 } | 1752 } |
1714 | 1753 |
1715 | 1754 |
1716 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { | 1755 RUNTIME_FUNCTION(Runtime_DebugBreakInOptimizedCode) { |
1717 UNIMPLEMENTED(); | 1756 UNIMPLEMENTED(); |
1718 return NULL; | 1757 return NULL; |
1719 } | 1758 } |
1720 } // namespace internal | 1759 } // namespace internal |
1721 } // namespace v8 | 1760 } // namespace v8 |
OLD | NEW |