| 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 9671 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 9682 // function is created as well to be used as the closure for the context. | 9682 // function is created as well to be used as the closure for the context. | 
| 9683 // This function and the context acts as replacements for the function on the | 9683 // This function and the context acts as replacements for the function on the | 
| 9684 // stack frame presenting the same view of the values of parameters and | 9684 // stack frame presenting the same view of the values of parameters and | 
| 9685 // local variables as if the piece of JavaScript was evaluated at the point | 9685 // local variables as if the piece of JavaScript was evaluated at the point | 
| 9686 // where the function on the stack frame is currently stopped. | 9686 // where the function on the stack frame is currently stopped. | 
| 9687 static MaybeObject* Runtime_DebugEvaluate(Arguments args) { | 9687 static MaybeObject* Runtime_DebugEvaluate(Arguments args) { | 
| 9688   HandleScope scope; | 9688   HandleScope scope; | 
| 9689 | 9689 | 
| 9690   // Check the execution state and decode arguments frame and source to be | 9690   // Check the execution state and decode arguments frame and source to be | 
| 9691   // evaluated. | 9691   // evaluated. | 
| 9692   ASSERT(args.length() == 4); | 9692   ASSERT(args.length() == 5); | 
| 9693   Object* check_result; | 9693   Object* check_result; | 
| 9694   { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); | 9694   { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); | 
| 9695     if (!maybe_check_result->ToObject(&check_result)) { | 9695     if (!maybe_check_result->ToObject(&check_result)) { | 
| 9696       return maybe_check_result; | 9696       return maybe_check_result; | 
| 9697     } | 9697     } | 
| 9698   } | 9698   } | 
| 9699   CONVERT_CHECKED(Smi, wrapped_id, args[1]); | 9699   CONVERT_CHECKED(Smi, wrapped_id, args[1]); | 
| 9700   CONVERT_ARG_CHECKED(String, source, 2); | 9700   CONVERT_ARG_CHECKED(String, source, 2); | 
| 9701   CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); | 9701   CONVERT_BOOLEAN_CHECKED(disable_break, args[3]); | 
|  | 9702   Handle<Object> additional_context(args[4]); | 
| 9702 | 9703 | 
| 9703   // Handle the processing of break. | 9704   // Handle the processing of break. | 
| 9704   DisableBreak disable_break_save(disable_break); | 9705   DisableBreak disable_break_save(disable_break); | 
| 9705 | 9706 | 
| 9706   // Get the frame where the debugging is performed. | 9707   // Get the frame where the debugging is performed. | 
| 9707   StackFrame::Id id = UnwrapFrameId(wrapped_id); | 9708   StackFrame::Id id = UnwrapFrameId(wrapped_id); | 
| 9708   JavaScriptFrameIterator it(id); | 9709   JavaScriptFrameIterator it(id); | 
| 9709   JavaScriptFrame* frame = it.frame(); | 9710   JavaScriptFrame* frame = it.frame(); | 
| 9710   Handle<JSFunction> function(JSFunction::cast(frame->function())); | 9711   Handle<JSFunction> function(JSFunction::cast(frame->function())); | 
| 9711   Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); | 9712   Handle<SerializedScopeInfo> scope_info(function->shared()->scope_info()); | 
| (...skipping 30 matching lines...) Expand all  Loading... | 
| 9742   // Allocate a new context for the debug evaluation and set the extension | 9743   // Allocate a new context for the debug evaluation and set the extension | 
| 9743   // object build. | 9744   // object build. | 
| 9744   Handle<Context> context = | 9745   Handle<Context> context = | 
| 9745       Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); | 9746       Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); | 
| 9746   context->set_extension(*local_scope); | 9747   context->set_extension(*local_scope); | 
| 9747   // Copy any with contexts present and chain them in front of this context. | 9748   // Copy any with contexts present and chain them in front of this context. | 
| 9748   Handle<Context> frame_context(Context::cast(frame->context())); | 9749   Handle<Context> frame_context(Context::cast(frame->context())); | 
| 9749   Handle<Context> function_context(frame_context->fcontext()); | 9750   Handle<Context> function_context(frame_context->fcontext()); | 
| 9750   context = CopyWithContextChain(frame_context, context); | 9751   context = CopyWithContextChain(frame_context, context); | 
| 9751 | 9752 | 
|  | 9753   if (additional_context->IsJSObject()) { | 
|  | 9754     context = Factory::NewWithContext(context, | 
|  | 9755         Handle<JSObject>::cast(additional_context), false); | 
|  | 9756   } | 
|  | 9757 | 
| 9752   // Wrap the evaluation statement in a new function compiled in the newly | 9758   // Wrap the evaluation statement in a new function compiled in the newly | 
| 9753   // created context. The function has one parameter which has to be called | 9759   // created context. The function has one parameter which has to be called | 
| 9754   // 'arguments'. This it to have access to what would have been 'arguments' in | 9760   // 'arguments'. This it to have access to what would have been 'arguments' in | 
| 9755   // the function being debugged. | 9761   // the function being debugged. | 
| 9756   // function(arguments,__source__) {return eval(__source__);} | 9762   // function(arguments,__source__) {return eval(__source__);} | 
| 9757   static const char* source_str = | 9763   static const char* source_str = | 
| 9758       "(function(arguments,__source__){return eval(__source__);})"; | 9764       "(function(arguments,__source__){return eval(__source__);})"; | 
| 9759   static const int source_str_length = StrLength(source_str); | 9765   static const int source_str_length = StrLength(source_str); | 
| 9760   Handle<String> function_source = | 9766   Handle<String> function_source = | 
| 9761       Factory::NewStringFromAscii(Vector<const char>(source_str, | 9767       Factory::NewStringFromAscii(Vector<const char>(source_str, | 
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 9796 | 9802 | 
| 9797   return *result; | 9803   return *result; | 
| 9798 } | 9804 } | 
| 9799 | 9805 | 
| 9800 | 9806 | 
| 9801 static MaybeObject* Runtime_DebugEvaluateGlobal(Arguments args) { | 9807 static MaybeObject* Runtime_DebugEvaluateGlobal(Arguments args) { | 
| 9802   HandleScope scope; | 9808   HandleScope scope; | 
| 9803 | 9809 | 
| 9804   // Check the execution state and decode arguments frame and source to be | 9810   // Check the execution state and decode arguments frame and source to be | 
| 9805   // evaluated. | 9811   // evaluated. | 
| 9806   ASSERT(args.length() == 3); | 9812   ASSERT(args.length() == 4); | 
| 9807   Object* check_result; | 9813   Object* check_result; | 
| 9808   { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); | 9814   { MaybeObject* maybe_check_result = Runtime_CheckExecutionState(args); | 
| 9809     if (!maybe_check_result->ToObject(&check_result)) { | 9815     if (!maybe_check_result->ToObject(&check_result)) { | 
| 9810       return maybe_check_result; | 9816       return maybe_check_result; | 
| 9811     } | 9817     } | 
| 9812   } | 9818   } | 
| 9813   CONVERT_ARG_CHECKED(String, source, 1); | 9819   CONVERT_ARG_CHECKED(String, source, 1); | 
| 9814   CONVERT_BOOLEAN_CHECKED(disable_break, args[2]); | 9820   CONVERT_BOOLEAN_CHECKED(disable_break, args[2]); | 
|  | 9821   Handle<Object> additional_context(args[3]); | 
| 9815 | 9822 | 
| 9816   // Handle the processing of break. | 9823   // Handle the processing of break. | 
| 9817   DisableBreak disable_break_save(disable_break); | 9824   DisableBreak disable_break_save(disable_break); | 
| 9818 | 9825 | 
| 9819   // Enter the top context from before the debugger was invoked. | 9826   // Enter the top context from before the debugger was invoked. | 
| 9820   SaveContext save; | 9827   SaveContext save; | 
| 9821   SaveContext* top = &save; | 9828   SaveContext* top = &save; | 
| 9822   while (top != NULL && *top->context() == *Debug::debug_context()) { | 9829   while (top != NULL && *top->context() == *Debug::debug_context()) { | 
| 9823     top = top->prev(); | 9830     top = top->prev(); | 
| 9824   } | 9831   } | 
| 9825   if (top != NULL) { | 9832   if (top != NULL) { | 
| 9826     Top::set_context(*top->context()); | 9833     Top::set_context(*top->context()); | 
| 9827   } | 9834   } | 
| 9828 | 9835 | 
| 9829   // Get the global context now set to the top context from before the | 9836   // Get the global context now set to the top context from before the | 
| 9830   // debugger was invoked. | 9837   // debugger was invoked. | 
| 9831   Handle<Context> context = Top::global_context(); | 9838   Handle<Context> context = Top::global_context(); | 
| 9832 | 9839 | 
|  | 9840   bool is_global = true; | 
|  | 9841 | 
|  | 9842   if (additional_context->IsJSObject()) { | 
|  | 9843     // Create a function context first, than put 'with' context on top of it. | 
|  | 9844     Handle<JSFunction> go_between = Factory::NewFunction( | 
|  | 9845         Factory::empty_string(), Factory::undefined_value()); | 
|  | 9846     go_between->set_context(*context); | 
|  | 9847     context = | 
|  | 9848         Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); | 
|  | 9849     context->set_extension(JSObject::cast(*additional_context)); | 
|  | 9850     is_global = false; | 
|  | 9851   } | 
|  | 9852 | 
| 9833   // Compile the source to be evaluated. | 9853   // Compile the source to be evaluated. | 
| 9834   Handle<SharedFunctionInfo> shared = | 9854   Handle<SharedFunctionInfo> shared = | 
| 9835       Compiler::CompileEval(source, | 9855       Compiler::CompileEval(source, | 
| 9836                             context, | 9856                             context, | 
| 9837                             true); | 9857                             is_global); | 
| 9838   if (shared.is_null()) return Failure::Exception(); | 9858   if (shared.is_null()) return Failure::Exception(); | 
| 9839   Handle<JSFunction> compiled_function = | 9859   Handle<JSFunction> compiled_function = | 
| 9840       Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, | 9860       Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, | 
| 9841                                                                     context)); | 9861                                                                     context)); | 
| 9842 | 9862 | 
| 9843   // Invoke the result of the compilation to get the evaluation function. | 9863   // Invoke the result of the compilation to get the evaluation function. | 
| 9844   bool has_pending_exception; | 9864   bool has_pending_exception; | 
| 9845   Handle<Object> receiver = Top::global(); | 9865   Handle<Object> receiver = Top::global(); | 
| 9846   Handle<Object> result = | 9866   Handle<Object> result = | 
| 9847     Execution::Call(compiled_function, receiver, 0, NULL, | 9867     Execution::Call(compiled_function, receiver, 0, NULL, | 
| (...skipping 937 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 10785   } else { | 10805   } else { | 
| 10786     // Handle last resort GC and make sure to allow future allocations | 10806     // Handle last resort GC and make sure to allow future allocations | 
| 10787     // to grow the heap without causing GCs (if possible). | 10807     // to grow the heap without causing GCs (if possible). | 
| 10788     Counters::gc_last_resort_from_js.Increment(); | 10808     Counters::gc_last_resort_from_js.Increment(); | 
| 10789     Heap::CollectAllGarbage(false); | 10809     Heap::CollectAllGarbage(false); | 
| 10790   } | 10810   } | 
| 10791 } | 10811 } | 
| 10792 | 10812 | 
| 10793 | 10813 | 
| 10794 } }  // namespace v8::internal | 10814 } }  // namespace v8::internal | 
| OLD | NEW | 
|---|