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 } | |
3977 | |
3978 | |
3979 static Object* Runtime_EvalReceiver(Arguments args) { | |
3980 StackFrameLocator locator; | |
3981 return locator.FindJavaScriptFrame(1)->receiver(); | |
3982 } | 3961 } |
3983 | 3962 |
3984 | 3963 |
3985 static Object* Runtime_GlobalReceiver(Arguments args) { | 3964 static Object* Runtime_GlobalReceiver(Arguments args) { |
3986 ASSERT(args.length() == 1); | 3965 ASSERT(args.length() == 1); |
3987 Object* global = args[0]; | 3966 Object* global = args[0]; |
3988 if (!global->IsJSGlobalObject()) return Heap::null_value(); | 3967 if (!global->IsJSGlobalObject()) return Heap::null_value(); |
3989 return JSGlobalObject::cast(global)->global_receiver(); | 3968 return JSGlobalObject::cast(global)->global_receiver(); |
3990 } | 3969 } |
3991 | 3970 |
(...skipping 1880 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5872 } else { | 5851 } else { |
5873 // Handle last resort GC and make sure to allow future allocations | 5852 // Handle last resort GC and make sure to allow future allocations |
5874 // to grow the heap without causing GCs (if possible). | 5853 // to grow the heap without causing GCs (if possible). |
5875 Counters::gc_last_resort_from_js.Increment(); | 5854 Counters::gc_last_resort_from_js.Increment(); |
5876 Heap::CollectAllGarbage(); | 5855 Heap::CollectAllGarbage(); |
5877 } | 5856 } |
5878 } | 5857 } |
5879 | 5858 |
5880 | 5859 |
5881 } } // namespace v8::internal | 5860 } } // namespace v8::internal |
OLD | NEW |