| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 3938 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3949 } | 3949 } |
| 3950 | 3950 |
| 3951 // Fetch the caller context from the frame. | 3951 // Fetch the caller context from the frame. |
| 3952 Handle<Context> caller(Context::cast(frame->context())); | 3952 Handle<Context> caller(Context::cast(frame->context())); |
| 3953 | 3953 |
| 3954 // Check for eval() invocations that cross environments. Use the | 3954 // Check for eval() invocations that cross environments. Use the |
| 3955 // context from the stack if evaluating in current environment. | 3955 // context from the stack if evaluating in current environment. |
| 3956 Handle<Context> target = Top::global_context(); | 3956 Handle<Context> target = Top::global_context(); |
| 3957 if (caller->global_context() == *target) return *caller; | 3957 if (caller->global_context() == *target) return *caller; |
| 3958 | 3958 |
| 3959 // Compute a function closure that captures the calling context. We | 3959 // Otherwise, use the global context from the other environment. |
| 3960 // need a function that has trivial scope info, since it is only | 3960 return *target; |
| 3961 // used to hold the context chain together. | |
| 3962 Handle<JSFunction> closure = Factory::NewFunction(Factory::empty_symbol(), | |
| 3963 Factory::undefined_value()); | |
| 3964 closure->set_context(*caller); | |
| 3965 | |
| 3966 // Create a new adaptor context that has the target environment as | |
| 3967 // the extension object. This enables the evaluated code to see both | |
| 3968 // the current context with locals and everything and to see global | |
| 3969 // variables declared in the target global object. Furthermore, any | |
| 3970 // properties introduced with 'var' will be added to the target | |
| 3971 // global object because it is the extension object. | |
| 3972 Handle<Context> adaptor = | |
| 3973 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, closure); | |
| 3974 adaptor->set_extension(target->global()); | |
| 3975 return *adaptor; | |
| 3976 } | 3961 } |
| 3977 | 3962 |
| 3978 | 3963 |
| 3979 static Object* Runtime_EvalReceiver(Arguments args) { | 3964 static Object* Runtime_EvalReceiver(Arguments args) { |
| 3965 ASSERT(args.length() == 1); |
| 3980 StackFrameLocator locator; | 3966 StackFrameLocator locator; |
| 3981 return locator.FindJavaScriptFrame(1)->receiver(); | 3967 JavaScriptFrame* frame = locator.FindJavaScriptFrame(1); |
| 3968 // Fetch the caller context from the frame. |
| 3969 Context* caller = Context::cast(frame->context()); |
| 3970 |
| 3971 // Check for eval() invocations that cross environments. Use the |
| 3972 // top frames receiver if evaluating in current environment. |
| 3973 Context* global_context = Top::context()->global()->global_context(); |
| 3974 if (caller->global_context() == global_context) { |
| 3975 return frame->receiver(); |
| 3976 } |
| 3977 |
| 3978 // Otherwise use the given argument (the global object of the |
| 3979 // receiving context). |
| 3980 return args[0]; |
| 3982 } | 3981 } |
| 3983 | 3982 |
| 3984 | 3983 |
| 3985 static Object* Runtime_GlobalReceiver(Arguments args) { | 3984 static Object* Runtime_GlobalReceiver(Arguments args) { |
| 3986 ASSERT(args.length() == 1); | 3985 ASSERT(args.length() == 1); |
| 3987 Object* global = args[0]; | 3986 Object* global = args[0]; |
| 3988 if (!global->IsJSGlobalObject()) return Heap::null_value(); | 3987 if (!global->IsJSGlobalObject()) return Heap::null_value(); |
| 3989 return JSGlobalObject::cast(global)->global_receiver(); | 3988 return JSGlobalObject::cast(global)->global_receiver(); |
| 3990 } | 3989 } |
| 3991 | 3990 |
| (...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4790 JavaScriptFrameIterator it(id); | 4789 JavaScriptFrameIterator it(id); |
| 4791 for (; !it.done(); it.Advance()) { | 4790 for (; !it.done(); it.Advance()) { |
| 4792 if (count == index) break; | 4791 if (count == index) break; |
| 4793 count++; | 4792 count++; |
| 4794 } | 4793 } |
| 4795 if (it.done()) return Heap::undefined_value(); | 4794 if (it.done()) return Heap::undefined_value(); |
| 4796 | 4795 |
| 4797 // Traverse the saved contexts chain to find the active context for the | 4796 // Traverse the saved contexts chain to find the active context for the |
| 4798 // selected frame. | 4797 // selected frame. |
| 4799 SaveContext* save = Top::save_context(); | 4798 SaveContext* save = Top::save_context(); |
| 4800 while (save != NULL && reinterpret_cast<Address>(save) < it.frame()->sp()) { | 4799 while (save != NULL && !save->below(it.frame())) { |
| 4801 save = save->prev(); | 4800 save = save->prev(); |
| 4802 } | 4801 } |
| 4802 ASSERT(save != NULL); |
| 4803 | 4803 |
| 4804 // Get the frame id. | 4804 // Get the frame id. |
| 4805 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); | 4805 Handle<Object> frame_id(WrapFrameId(it.frame()->id())); |
| 4806 | 4806 |
| 4807 // Find source position. | 4807 // Find source position. |
| 4808 int position = it.frame()->FindCode()->SourcePosition(it.frame()->pc()); | 4808 int position = it.frame()->FindCode()->SourcePosition(it.frame()->pc()); |
| 4809 | 4809 |
| 4810 // Check for constructor frame. | 4810 // Check for constructor frame. |
| 4811 bool constructor = it.frame()->IsConstructor(); | 4811 bool constructor = it.frame()->IsConstructor(); |
| 4812 | 4812 |
| (...skipping 268 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5081 } | 5081 } |
| 5082 } | 5082 } |
| 5083 | 5083 |
| 5084 // If the candidate found is compiled we are done. NOTE: when lazy | 5084 // If the candidate found is compiled we are done. NOTE: when lazy |
| 5085 // compilation of inner functions is introduced some additional checking | 5085 // compilation of inner functions is introduced some additional checking |
| 5086 // needs to be done here to compile inner functions. | 5086 // needs to be done here to compile inner functions. |
| 5087 done = target->is_compiled(); | 5087 done = target->is_compiled(); |
| 5088 if (!done) { | 5088 if (!done) { |
| 5089 // If the candidate is not compiled compile it to reveal any inner | 5089 // If the candidate is not compiled compile it to reveal any inner |
| 5090 // functions which might contain the requested source position. | 5090 // functions which might contain the requested source position. |
| 5091 CompileLazyShared(target, KEEP_EXCEPTION); | 5091 CompileLazyShared(target, KEEP_EXCEPTION, 0); |
| 5092 } | 5092 } |
| 5093 } | 5093 } |
| 5094 | 5094 |
| 5095 return *target; | 5095 return *target; |
| 5096 } | 5096 } |
| 5097 | 5097 |
| 5098 | 5098 |
| 5099 // Change the state of a break point in a script. NOTE: Regarding performance | 5099 // Change the state of a break point in a script. NOTE: Regarding performance |
| 5100 // see the NOTE for GetScriptFromScriptData. | 5100 // see the NOTE for GetScriptFromScriptData. |
| 5101 // args[0]: script to set break point in | 5101 // args[0]: script to set break point in |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5292 StackFrame::Id id = UnwrapFrameId(wrapped_id); | 5292 StackFrame::Id id = UnwrapFrameId(wrapped_id); |
| 5293 JavaScriptFrameIterator it(id); | 5293 JavaScriptFrameIterator it(id); |
| 5294 JavaScriptFrame* frame = it.frame(); | 5294 JavaScriptFrame* frame = it.frame(); |
| 5295 Handle<JSFunction> function(JSFunction::cast(frame->function())); | 5295 Handle<JSFunction> function(JSFunction::cast(frame->function())); |
| 5296 Handle<Code> code(function->code()); | 5296 Handle<Code> code(function->code()); |
| 5297 ScopeInfo<> sinfo(*code); | 5297 ScopeInfo<> sinfo(*code); |
| 5298 | 5298 |
| 5299 // Traverse the saved contexts chain to find the active context for the | 5299 // Traverse the saved contexts chain to find the active context for the |
| 5300 // selected frame. | 5300 // selected frame. |
| 5301 SaveContext* save = Top::save_context(); | 5301 SaveContext* save = Top::save_context(); |
| 5302 while (save != NULL && reinterpret_cast<Address>(save) < frame->sp()) { | 5302 while (save != NULL && !save->below(frame)) { |
| 5303 save = save->prev(); | 5303 save = save->prev(); |
| 5304 } | 5304 } |
| 5305 ASSERT(save != NULL); | 5305 ASSERT(save != NULL); |
| 5306 SaveContext savex; | 5306 SaveContext savex; |
| 5307 Top::set_context(*(save->context())); | 5307 Top::set_context(*(save->context())); |
| 5308 | 5308 |
| 5309 // Create the (empty) function replacing the function on the stack frame for | 5309 // Create the (empty) function replacing the function on the stack frame for |
| 5310 // the purpose of evaluating in the context created below. It is important | 5310 // the purpose of evaluating in the context created below. It is important |
| 5311 // that this function does not describe any parameters and local variables | 5311 // that this function does not describe any parameters and local variables |
| 5312 // in the context. If it does then this will cause problems with the lookup | 5312 // in the context. If it does then this will cause problems with the lookup |
| (...skipping 559 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5872 } else { | 5872 } else { |
| 5873 // Handle last resort GC and make sure to allow future allocations | 5873 // Handle last resort GC and make sure to allow future allocations |
| 5874 // to grow the heap without causing GCs (if possible). | 5874 // to grow the heap without causing GCs (if possible). |
| 5875 Counters::gc_last_resort_from_js.Increment(); | 5875 Counters::gc_last_resort_from_js.Increment(); |
| 5876 Heap::CollectAllGarbage(); | 5876 Heap::CollectAllGarbage(); |
| 5877 } | 5877 } |
| 5878 } | 5878 } |
| 5879 | 5879 |
| 5880 | 5880 |
| 5881 } } // namespace v8::internal | 5881 } } // namespace v8::internal |
| OLD | NEW |