Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 9664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9675 // function is created as well to be used as the closure for the context. | 9675 // function is created as well to be used as the closure for the context. |
| 9676 // This function and the context acts as replacements for the function on the | 9676 // This function and the context acts as replacements for the function on the |
| 9677 // stack frame presenting the same view of the values of parameters and | 9677 // stack frame presenting the same view of the values of parameters and |
| 9678 // local variables as if the piece of JavaScript was evaluated at the point | 9678 // local variables as if the piece of JavaScript was evaluated at the point |
| 9679 // where the function on the stack frame is currently stopped. | 9679 // where the function on the stack frame is currently stopped. |
| 9680 static MaybeObject* Runtime_DebugEvaluate(Arguments args) { | 9680 static MaybeObject* Runtime_DebugEvaluate(Arguments args) { |
| 9681 HandleScope scope; | 9681 HandleScope scope; |
| 9682 | 9682 |
| 9683 // Check the execution state and decode arguments frame and source to be | 9683 // Check the execution state and decode arguments frame and source to be |
| 9684 // evaluated. | 9684 // evaluated. |
| 9685 ASSERT(args.length() == 4); | 9685 ASSERT(args.length() == 5); |
| 9686 Object* check_result; | 9686 Object* check_result; |
| 9687 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); | 9687 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); |
| 9688 if (!maybe_check_result->ToObject(&check_result)) { | 9688 if (!maybe_check_result->ToObject(&check_result)) { |
| 9689 return maybe_check_result; | 9689 return maybe_check_result; |
| 9690 } | 9690 } |
| 9691 } | 9691 } |
| 9692 CONVERT_CHECKED(Smi, wrapped_id, args[1]); | 9692 CONVERT_CHECKED(Smi, wrapped_id, args[1]); |
| 9693 CONVERT_ARG_CHECKED(String, source, 2); | 9693 CONVERT_ARG_CHECKED(String, source, 2); |
| 9694 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); | 9694 CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); |
| 9695 Handle<Object> additional_context(args[4]); | |
| 9695 | 9696 |
| 9696 // Handle the processing of break. | 9697 // Handle the processing of break. |
| 9697 DisableBreak disable_break_save(disable_break); | 9698 DisableBreak disable_break_save(disable_break); |
| 9698 | 9699 |
| 9699 // Get the frame where the debugging is performed. | 9700 // Get the frame where the debugging is performed. |
| 9700 StackFrame::Id id = UnwrapFrameId(wrapped_id); | 9701 StackFrame::Id id = UnwrapFrameId(wrapped_id); |
| 9701 JavaScriptFrameIterator it(id); | 9702 JavaScriptFrameIterator it(id); |
| 9702 JavaScriptFrame* frame = it.frame(); | 9703 JavaScriptFrame* frame = it.frame(); |
| 9703 Handle<JSFunction> function(JSFunction::cast(frame->function())); | 9704 Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 9704 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); | 9705 Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 9735 // Allocate a new context for the debug evaluation and set the extension | 9736 // Allocate a new context for the debug evaluation and set the extension |
| 9736 // object build. | 9737 // object build. |
| 9737 Handle<Context> context = | 9738 Handle<Context> context = |
| 9738 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); | 9739 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); |
| 9739 context->set_extension(*local_scope); | 9740 context->set_extension(*local_scope); |
| 9740 // Copy any with contexts present and chain them in front of this context. | 9741 // Copy any with contexts present and chain them in front of this context. |
| 9741 Handle<Context> frame_context(Context::cast(frame->context())); | 9742 Handle<Context> frame_context(Context::cast(frame->context())); |
| 9742 Handle<Context> function_context(frame_context->fcontext()); | 9743 Handle<Context> function_context(frame_context->fcontext()); |
| 9743 context = CopyWithContextChain(frame_context, context); | 9744 context = CopyWithContextChain(frame_context, context); |
| 9744 | 9745 |
| 9746 if (additional_context->IsJSObject()) { | |
| 9747 context = Factory::NewWithContext(context, | |
| 9748 Handle<JSObject>::cast(additional_context), false); | |
| 9749 } | |
| 9750 | |
| 9745 // Wrap the evaluation statement in a new function compiled in the newly | 9751 // Wrap the evaluation statement in a new function compiled in the newly |
| 9746 // created context. The function has one parameter which has to be called | 9752 // created context. The function has one parameter which has to be called |
| 9747 // 'arguments'. This it to have access to what would have been 'arguments' in | 9753 // 'arguments'. This it to have access to what would have been 'arguments' in |
| 9748 // the function being debugged. | 9754 // the function being debugged. |
| 9749 // function(arguments,__source__) {return eval(__source__);} | 9755 // function(arguments,__source__) {return eval(__source__);} |
| 9750 static const char* source_str = | 9756 static const char* source_str = |
| 9751 "(function(arguments,__source__){return eval(__source__);})"; | 9757 "(function(arguments,__source__){return eval(__source__);})"; |
| 9752 static const int source_str_length = StrLength(source_str); | 9758 static const int source_str_length = StrLength(source_str); |
| 9753 Handle<String> function_source = | 9759 Handle<String> function_source = |
| 9754 Factory::NewStringFromAscii(Vector<const char>(source_str, | 9760 Factory::NewStringFromAscii(Vector<const char>(source_str, |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9789 | 9795 |
| 9790 return *result; | 9796 return *result; |
| 9791 } | 9797 } |
| 9792 | 9798 |
| 9793 | 9799 |
| 9794 static MaybeObject* Runtime_DebugEvaluateGlobal(Arguments args) { | 9800 static MaybeObject* Runtime_DebugEvaluateGlobal(Arguments args) { |
| 9795 HandleScope scope; | 9801 HandleScope scope; |
| 9796 | 9802 |
| 9797 // Check the execution state and decode arguments frame and source to be | 9803 // Check the execution state and decode arguments frame and source to be |
| 9798 // evaluated. | 9804 // evaluated. |
| 9799 ASSERT(args.length() == 3); | 9805 ASSERT(args.length() == 4); |
| 9800 Object* check_result; | 9806 Object* check_result; |
| 9801 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); | 9807 { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); |
| 9802 if (!maybe_check_result->ToObject(&check_result)) { | 9808 if (!maybe_check_result->ToObject(&check_result)) { |
| 9803 return maybe_check_result; | 9809 return maybe_check_result; |
| 9804 } | 9810 } |
| 9805 } | 9811 } |
| 9806 CONVERT_ARG_CHECKED(String, source, 1); | 9812 CONVERT_ARG_CHECKED(String, source, 1); |
| 9807 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]); | 9813 CONVERT_BOOLEAN_CHECKED(disable_break, args[2]); |
| 9814 Handle<Object> additional_context(args[3]); | |
| 9808 | 9815 |
| 9809 // Handle the processing of break. | 9816 // Handle the processing of break. |
| 9810 DisableBreak disable_break_save(disable_break); | 9817 DisableBreak disable_break_save(disable_break); |
| 9811 | 9818 |
| 9812 // Enter the top context from before the debugger was invoked. | 9819 // Enter the top context from before the debugger was invoked. |
| 9813 SaveContext save; | 9820 SaveContext save; |
| 9814 SaveContext* top = &save; | 9821 SaveContext* top = &save; |
| 9815 while (top != NULL && *top->context() == *Debug::debug_context()) { | 9822 while (top != NULL && *top->context() == *Debug::debug_context()) { |
| 9816 top = top->prev(); | 9823 top = top->prev(); |
| 9817 } | 9824 } |
| 9818 if (top != NULL) { | 9825 if (top != NULL) { |
| 9819 Top::set_context(*top->context()); | 9826 Top::set_context(*top->context()); |
| 9820 } | 9827 } |
| 9821 | 9828 |
| 9822 // Get the global context now set to the top context from before the | 9829 // Get the global context now set to the top context from before the |
| 9823 // debugger was invoked. | 9830 // debugger was invoked. |
| 9824 Handle<Context> context = Top::global_context(); | 9831 Handle<Context> context = Top::global_context(); |
| 9825 | 9832 |
| 9833 bool is_global = true; | |
| 9834 | |
| 9835 if (additional_context->IsJSObject()) { | |
|
Søren Thygesen Gjesse
2010/12/13 08:37:14
4 char indent.
Peter Rybin
2010/12/14 00:02:52
Done.
| |
| 9836 // Create a function context first, than put 'with' context on top of it. | |
| 9837 Handle<JSFunction> go_between = Factory::NewFunction( | |
| 9838 Factory::empty_string(), Factory::undefined_value()); | |
| 9839 go_between->set_context(*context); | |
| 9840 context = Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, | |
|
Søren Thygesen Gjesse
2010/12/13 08:37:14
I suggest splitting this line either after the '='
Peter Rybin
2010/12/14 00:02:52
Done.
| |
| 9841 go_between); | |
| 9842 context->set_extension(JSObject::cast(*additional_context)); | |
| 9843 is_global = false; | |
| 9844 } | |
| 9845 | |
| 9826 // Compile the source to be evaluated. | 9846 // Compile the source to be evaluated. |
| 9827 Handle<SharedFunctionInfo> shared = | 9847 Handle<SharedFunctionInfo> shared = |
| 9828 Compiler::CompileEval(source, | 9848 Compiler::CompileEval(source, |
| 9829 context, | 9849 context, |
| 9830 true); | 9850 is_global); |
| 9831 if (shared.is_null()) return Failure::Exception(); | 9851 if (shared.is_null()) return Failure::Exception(); |
| 9832 Handle<JSFunction> compiled_function = | 9852 Handle<JSFunction> compiled_function = |
| 9833 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, | 9853 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, |
| 9834 context)); | 9854 context)); |
| 9835 | 9855 |
| 9836 // Invoke the result of the compilation to get the evaluation function. | 9856 // Invoke the result of the compilation to get the evaluation function. |
| 9837 bool has_pending_exception; | 9857 bool has_pending_exception; |
| 9838 Handle<Object> receiver = Top::global(); | 9858 Handle<Object> receiver = Top::global(); |
| 9839 Handle<Object> result = | 9859 Handle<Object> result = |
| 9840 Execution::Call(compiled_function, receiver, 0, NULL, | 9860 Execution::Call(compiled_function, receiver, 0, NULL, |
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10778 } else { | 10798 } else { |
| 10779 // Handle last resort GC and make sure to allow future allocations | 10799 // Handle last resort GC and make sure to allow future allocations |
| 10780 // to grow the heap without causing GCs (if possible). | 10800 // to grow the heap without causing GCs (if possible). |
| 10781 Counters::gc_last_resort_from_js.Increment(); | 10801 Counters::gc_last_resort_from_js.Increment(); |
| 10782 Heap::CollectAllGarbage(false); | 10802 Heap::CollectAllGarbage(false); |
| 10783 } | 10803 } |
| 10784 } | 10804 } |
| 10785 | 10805 |
| 10786 | 10806 |
| 10787 } } // namespace v8::internal | 10807 } } // namespace v8::internal |
| OLD | NEW |