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 4043 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4054 // Find where the 'eval' symbol is bound. It is unaliased only if | 4054 // Find where the 'eval' symbol is bound. It is unaliased only if |
4055 // it is bound in the global context. | 4055 // it is bound in the global context. |
4056 StackFrameLocator locator; | 4056 StackFrameLocator locator; |
4057 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); | 4057 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); |
4058 Handle<Context> context(Context::cast(frame->context())); | 4058 Handle<Context> context(Context::cast(frame->context())); |
4059 int index; | 4059 int index; |
4060 PropertyAttributes attributes; | 4060 PropertyAttributes attributes; |
4061 while (!context.is_null()) { | 4061 while (!context.is_null()) { |
4062 receiver = context->Lookup(Factory::eval_symbol(), FOLLOW_PROTOTYPE_CHAIN, | 4062 receiver = context->Lookup(Factory::eval_symbol(), FOLLOW_PROTOTYPE_CHAIN, |
4063 &index, &attributes); | 4063 &index, &attributes); |
4064 if (attributes != ABSENT) break; | 4064 // Stop search when eval is found or when the global context is |
| 4065 // reached. |
| 4066 if (attributes != ABSENT || context->IsGlobalContext()) break; |
4065 if (context->is_function_context()) { | 4067 if (context->is_function_context()) { |
4066 context = Handle<Context>(Context::cast(context->closure()->context())); | 4068 context = Handle<Context>(Context::cast(context->closure()->context())); |
4067 } else { | 4069 } else { |
4068 context = Handle<Context>(context->previous()); | 4070 context = Handle<Context>(context->previous()); |
4069 } | 4071 } |
4070 } | 4072 } |
4071 | 4073 |
| 4074 // If eval could not be resolved, it has been deleted and we need to |
| 4075 // throw a reference error. |
| 4076 if (attributes == ABSENT) { |
| 4077 Handle<Object> name = Factory::eval_symbol(); |
| 4078 Handle<Object> reference_error = |
| 4079 Factory::NewReferenceError("not_defined", HandleVector(&name, 1)); |
| 4080 return Top::Throw(*reference_error); |
| 4081 } |
| 4082 |
4072 if (context->IsGlobalContext()) { | 4083 if (context->IsGlobalContext()) { |
4073 // 'eval' is bound in the global context, but it may have been overwritten. | 4084 // 'eval' is bound in the global context, but it may have been overwritten. |
4074 // Compare it to the builtin 'GlobalEval' function to make sure. | 4085 // Compare it to the builtin 'GlobalEval' function to make sure. |
4075 Handle<JSFunction> global_eval = | 4086 Handle<JSFunction> global_eval = |
4076 GetBuiltinFunction(Heap::global_eval_symbol()); | 4087 GetBuiltinFunction(Heap::global_eval_symbol()); |
4077 if (global_eval.is_identical_to(callee)) { | 4088 if (global_eval.is_identical_to(callee)) { |
4078 // A direct eval call. | 4089 // A direct eval call. |
4079 if (args[1]->IsString()) { | 4090 if (args[1]->IsString()) { |
4080 CONVERT_ARG_CHECKED(String, source, 1); | 4091 CONVERT_ARG_CHECKED(String, source, 1); |
4081 // A normal eval call on a string. Compile it and return the | 4092 // A normal eval call on a string. Compile it and return the |
(...skipping 2009 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6091 } else { | 6102 } else { |
6092 // Handle last resort GC and make sure to allow future allocations | 6103 // Handle last resort GC and make sure to allow future allocations |
6093 // to grow the heap without causing GCs (if possible). | 6104 // to grow the heap without causing GCs (if possible). |
6094 Counters::gc_last_resort_from_js.Increment(); | 6105 Counters::gc_last_resort_from_js.Increment(); |
6095 Heap::CollectAllGarbage(); | 6106 Heap::CollectAllGarbage(); |
6096 } | 6107 } |
6097 } | 6108 } |
6098 | 6109 |
6099 | 6110 |
6100 } } // namespace v8::internal | 6111 } } // namespace v8::internal |
OLD | NEW |