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 3989 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4000 return JSGlobalObject::cast(global)->global_receiver(); | 4000 return JSGlobalObject::cast(global)->global_receiver(); |
4001 } | 4001 } |
4002 | 4002 |
4003 | 4003 |
4004 static Object* Runtime_CompileString(Arguments args) { | 4004 static Object* Runtime_CompileString(Arguments args) { |
4005 HandleScope scope; | 4005 HandleScope scope; |
4006 ASSERT(args.length() == 2); | 4006 ASSERT(args.length() == 2); |
4007 CONVERT_ARG_CHECKED(String, source, 0); | 4007 CONVERT_ARG_CHECKED(String, source, 0); |
4008 CONVERT_ARG_CHECKED(Smi, line_offset, 1); | 4008 CONVERT_ARG_CHECKED(Smi, line_offset, 1); |
4009 | 4009 |
4010 // Compile source string. | 4010 // Compile source string in the global context. |
| 4011 Handle<Context> context(Top::context()->global_context()); |
4011 Handle<JSFunction> boilerplate = | 4012 Handle<JSFunction> boilerplate = |
4012 Compiler::CompileEval(source, line_offset->value(), true); | 4013 Compiler::CompileEval(source, context, line_offset->value(), true); |
4013 if (boilerplate.is_null()) return Failure::Exception(); | 4014 if (boilerplate.is_null()) return Failure::Exception(); |
4014 Handle<Context> context(Top::context()->global_context()); | |
4015 Handle<JSFunction> fun = | 4015 Handle<JSFunction> fun = |
4016 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 4016 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
4017 return *fun; | 4017 return *fun; |
4018 } | 4018 } |
4019 | 4019 |
4020 | 4020 |
4021 static Handle<JSFunction> GetBuiltinFunction(String* name) { | 4021 static Handle<JSFunction> GetBuiltinFunction(String* name) { |
4022 LookupResult result; | 4022 LookupResult result; |
4023 Top::global_context()->builtins()->LocalLookup(name, &result); | 4023 Top::global_context()->builtins()->LocalLookup(name, &result); |
4024 return Handle<JSFunction>(JSFunction::cast(result.GetValue())); | 4024 return Handle<JSFunction>(JSFunction::cast(result.GetValue())); |
4025 } | 4025 } |
4026 | 4026 |
4027 | 4027 |
4028 static Object* CompileDirectEval(Handle<String> source) { | 4028 static Object* CompileDirectEval(Handle<String> source) { |
4029 // Compute the eval context. | 4029 // Compute the eval context. |
4030 HandleScope scope; | 4030 HandleScope scope; |
4031 StackFrameLocator locator; | 4031 StackFrameLocator locator; |
4032 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); | 4032 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); |
4033 Handle<Context> context(Context::cast(frame->context())); | 4033 Handle<Context> context(Context::cast(frame->context())); |
4034 bool is_global = context->IsGlobalContext(); | 4034 bool is_global = context->IsGlobalContext(); |
4035 | 4035 |
4036 // Compile source string. | 4036 // Compile source string in the current context. |
4037 Handle<JSFunction> boilerplate = Compiler::CompileEval(source, 0, is_global); | 4037 Handle<JSFunction> boilerplate = |
| 4038 Compiler::CompileEval(source, context, 0, is_global); |
4038 if (boilerplate.is_null()) return Failure::Exception(); | 4039 if (boilerplate.is_null()) return Failure::Exception(); |
4039 Handle<JSFunction> fun = | 4040 Handle<JSFunction> fun = |
4040 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 4041 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
4041 return *fun; | 4042 return *fun; |
4042 } | 4043 } |
4043 | 4044 |
4044 | 4045 |
4045 static Object* Runtime_ResolvePossiblyDirectEval(Arguments args) { | 4046 static Object* Runtime_ResolvePossiblyDirectEval(Arguments args) { |
4046 ASSERT(args.length() == 2); | 4047 ASSERT(args.length() == 2); |
4047 | 4048 |
(...skipping 1539 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5587 // 'arguments'. This it to have access to what would have been 'arguments' in | 5588 // 'arguments'. This it to have access to what would have been 'arguments' in |
5588 // the function being debugged. | 5589 // the function being debugged. |
5589 // function(arguments,__source__) {return eval(__source__);} | 5590 // function(arguments,__source__) {return eval(__source__);} |
5590 static const char* source_str = | 5591 static const char* source_str = |
5591 "function(arguments,__source__){return eval(__source__);}"; | 5592 "function(arguments,__source__){return eval(__source__);}"; |
5592 static const int source_str_length = strlen(source_str); | 5593 static const int source_str_length = strlen(source_str); |
5593 Handle<String> function_source = | 5594 Handle<String> function_source = |
5594 Factory::NewStringFromAscii(Vector<const char>(source_str, | 5595 Factory::NewStringFromAscii(Vector<const char>(source_str, |
5595 source_str_length)); | 5596 source_str_length)); |
5596 Handle<JSFunction> boilerplate = | 5597 Handle<JSFunction> boilerplate = |
5597 Compiler::CompileEval(function_source, 0, context->IsGlobalContext()); | 5598 Compiler::CompileEval(function_source, |
| 5599 context, |
| 5600 0, |
| 5601 context->IsGlobalContext()); |
5598 if (boilerplate.is_null()) return Failure::Exception(); | 5602 if (boilerplate.is_null()) return Failure::Exception(); |
5599 Handle<JSFunction> compiled_function = | 5603 Handle<JSFunction> compiled_function = |
5600 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 5604 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
5601 | 5605 |
5602 // Invoke the result of the compilation to get the evaluation function. | 5606 // Invoke the result of the compilation to get the evaluation function. |
5603 bool has_pending_exception; | 5607 bool has_pending_exception; |
5604 Handle<Object> receiver(frame->receiver()); | 5608 Handle<Object> receiver(frame->receiver()); |
5605 Handle<Object> evaluation_function = | 5609 Handle<Object> evaluation_function = |
5606 Execution::Call(compiled_function, receiver, 0, NULL, | 5610 Execution::Call(compiled_function, receiver, 0, NULL, |
5607 &has_pending_exception); | 5611 &has_pending_exception); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5644 } | 5648 } |
5645 if (top != NULL) { | 5649 if (top != NULL) { |
5646 Top::set_context(*top->context()); | 5650 Top::set_context(*top->context()); |
5647 } | 5651 } |
5648 | 5652 |
5649 // Get the global context now set to the top context from before the | 5653 // Get the global context now set to the top context from before the |
5650 // debugger was invoked. | 5654 // debugger was invoked. |
5651 Handle<Context> context = Top::global_context(); | 5655 Handle<Context> context = Top::global_context(); |
5652 | 5656 |
5653 // Compile the source to be evaluated. | 5657 // Compile the source to be evaluated. |
5654 Handle<JSFunction> boilerplate(Compiler::CompileEval(source, 0, true)); | 5658 Handle<JSFunction> boilerplate = |
| 5659 Handle<JSFunction>(Compiler::CompileEval(source, context, 0, true)); |
5655 if (boilerplate.is_null()) return Failure::Exception(); | 5660 if (boilerplate.is_null()) return Failure::Exception(); |
5656 Handle<JSFunction> compiled_function = | 5661 Handle<JSFunction> compiled_function = |
5657 Handle<JSFunction>(Factory::NewFunctionFromBoilerplate(boilerplate, | 5662 Handle<JSFunction>(Factory::NewFunctionFromBoilerplate(boilerplate, |
5658 context)); | 5663 context)); |
5659 | 5664 |
5660 // Invoke the result of the compilation to get the evaluation function. | 5665 // Invoke the result of the compilation to get the evaluation function. |
5661 bool has_pending_exception; | 5666 bool has_pending_exception; |
5662 Handle<Object> receiver = Top::global(); | 5667 Handle<Object> receiver = Top::global(); |
5663 Handle<Object> result = | 5668 Handle<Object> result = |
5664 Execution::Call(compiled_function, receiver, 0, NULL, | 5669 Execution::Call(compiled_function, receiver, 0, NULL, |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6091 } else { | 6096 } else { |
6092 // Handle last resort GC and make sure to allow future allocations | 6097 // Handle last resort GC and make sure to allow future allocations |
6093 // to grow the heap without causing GCs (if possible). | 6098 // to grow the heap without causing GCs (if possible). |
6094 Counters::gc_last_resort_from_js.Increment(); | 6099 Counters::gc_last_resort_from_js.Increment(); |
6095 Heap::CollectAllGarbage(); | 6100 Heap::CollectAllGarbage(); |
6096 } | 6101 } |
6097 } | 6102 } |
6098 | 6103 |
6099 | 6104 |
6100 } } // namespace v8::internal | 6105 } } // namespace v8::internal |
OLD | NEW |