Chromium Code Reviews| 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 7535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7546 | 7546 |
| 7547 static MaybeObject* Runtime_CompileString(Arguments args) { | 7547 static MaybeObject* Runtime_CompileString(Arguments args) { |
| 7548 HandleScope scope; | 7548 HandleScope scope; |
| 7549 ASSERT_EQ(1, args.length()); | 7549 ASSERT_EQ(1, args.length()); |
| 7550 CONVERT_ARG_CHECKED(String, source, 0); | 7550 CONVERT_ARG_CHECKED(String, source, 0); |
| 7551 | 7551 |
| 7552 // Compile source string in the global context. | 7552 // Compile source string in the global context. |
| 7553 Handle<Context> context(Top::context()->global_context()); | 7553 Handle<Context> context(Top::context()->global_context()); |
| 7554 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, | 7554 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, |
| 7555 context, | 7555 context, |
| 7556 true); | 7556 true, |
| 7557 false); | |
| 7557 if (shared.is_null()) return Failure::Exception(); | 7558 if (shared.is_null()) return Failure::Exception(); |
| 7558 Handle<JSFunction> fun = | 7559 Handle<JSFunction> fun = |
| 7559 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED); | 7560 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED); |
| 7560 return *fun; | 7561 return *fun; |
| 7561 } | 7562 } |
| 7562 | 7563 |
| 7563 | 7564 |
| 7564 static ObjectPair CompileGlobalEval(Handle<String> source, | 7565 static ObjectPair CompileGlobalEval(Handle<String> source, |
| 7565 Handle<Object> receiver) { | 7566 Handle<Object> receiver, |
| 7567 bool is_strict) { | |
| 7566 // Deal with a normal eval call with a string argument. Compile it | 7568 // Deal with a normal eval call with a string argument. Compile it |
| 7567 // and return the compiled function bound in the local context. | 7569 // and return the compiled function bound in the local context. |
| 7568 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 7570 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
| 7569 source, | 7571 source, |
| 7570 Handle<Context>(Top::context()), | 7572 Handle<Context>(Top::context()), |
| 7571 Top::context()->IsGlobalContext()); | 7573 Top::context()->IsGlobalContext(), |
| 7574 is_strict); | |
| 7572 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); | 7575 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); |
| 7573 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo( | 7576 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo( |
| 7574 shared, | 7577 shared, |
| 7575 Handle<Context>(Top::context()), | 7578 Handle<Context>(Top::context()), |
| 7576 NOT_TENURED); | 7579 NOT_TENURED); |
| 7577 return MakePair(*compiled, *receiver); | 7580 return MakePair(*compiled, *receiver); |
| 7578 } | 7581 } |
| 7579 | 7582 |
| 7580 | 7583 |
| 7581 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { | 7584 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { |
| 7582 ASSERT(args.length() == 3); | 7585 ASSERT(args.length() == 4); |
| 7583 if (!args[0]->IsJSFunction()) { | 7586 if (!args[0]->IsJSFunction()) { |
| 7584 return MakePair(Top::ThrowIllegalOperation(), NULL); | 7587 return MakePair(Top::ThrowIllegalOperation(), NULL); |
| 7585 } | 7588 } |
| 7586 | 7589 |
| 7587 HandleScope scope; | 7590 HandleScope scope; |
| 7588 Handle<JSFunction> callee = args.at<JSFunction>(0); | 7591 Handle<JSFunction> callee = args.at<JSFunction>(0); |
| 7589 Handle<Object> receiver; // Will be overwritten. | 7592 Handle<Object> receiver; // Will be overwritten. |
| 7590 | 7593 |
| 7591 // Compute the calling context. | 7594 // Compute the calling context. |
| 7592 Handle<Context> context = Handle<Context>(Top::context()); | 7595 Handle<Context> context = Handle<Context>(Top::context()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 7636 return MakePair(*callee, *receiver); | 7639 return MakePair(*callee, *receiver); |
| 7637 } | 7640 } |
| 7638 | 7641 |
| 7639 // 'eval' is bound in the global context, but it may have been overwritten. | 7642 // 'eval' is bound in the global context, but it may have been overwritten. |
| 7640 // Compare it to the builtin 'GlobalEval' function to make sure. | 7643 // Compare it to the builtin 'GlobalEval' function to make sure. |
| 7641 if (*callee != Top::global_context()->global_eval_fun() || | 7644 if (*callee != Top::global_context()->global_eval_fun() || |
| 7642 !args[1]->IsString()) { | 7645 !args[1]->IsString()) { |
| 7643 return MakePair(*callee, Top::context()->global()->global_receiver()); | 7646 return MakePair(*callee, Top::context()->global()->global_receiver()); |
| 7644 } | 7647 } |
| 7645 | 7648 |
| 7646 return CompileGlobalEval(args.at<String>(1), args.at<Object>(2)); | 7649 ASSERT(args[3]->IsSmi()); |
| 7650 return CompileGlobalEval(args.at<String>(1), | |
| 7651 args.at<Object>(2), | |
| 7652 Smi::cast(args[3])->value() != 0); | |
| 7647 } | 7653 } |
| 7648 | 7654 |
| 7649 | 7655 |
| 7650 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) { | 7656 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) { |
| 7651 ASSERT(args.length() == 3); | 7657 ASSERT(args.length() == 4); |
| 7652 if (!args[0]->IsJSFunction()) { | 7658 if (!args[0]->IsJSFunction()) { |
| 7653 return MakePair(Top::ThrowIllegalOperation(), NULL); | 7659 return MakePair(Top::ThrowIllegalOperation(), NULL); |
| 7654 } | 7660 } |
| 7655 | 7661 |
| 7656 HandleScope scope; | 7662 HandleScope scope; |
| 7657 Handle<JSFunction> callee = args.at<JSFunction>(0); | 7663 Handle<JSFunction> callee = args.at<JSFunction>(0); |
| 7658 | 7664 |
| 7659 // 'eval' is bound in the global context, but it may have been overwritten. | 7665 // 'eval' is bound in the global context, but it may have been overwritten. |
| 7660 // Compare it to the builtin 'GlobalEval' function to make sure. | 7666 // Compare it to the builtin 'GlobalEval' function to make sure. |
| 7661 if (*callee != Top::global_context()->global_eval_fun() || | 7667 if (*callee != Top::global_context()->global_eval_fun() || |
| 7662 !args[1]->IsString()) { | 7668 !args[1]->IsString()) { |
| 7663 return MakePair(*callee, Top::context()->global()->global_receiver()); | 7669 return MakePair(*callee, Top::context()->global()->global_receiver()); |
| 7664 } | 7670 } |
| 7665 | 7671 |
| 7666 return CompileGlobalEval(args.at<String>(1), args.at<Object>(2)); | 7672 ASSERT(args[3]->IsSmi()); |
| 7673 return CompileGlobalEval(args.at<String>(1), | |
| 7674 args.at<Object>(2), | |
| 7675 Smi::cast(args[3])->value() != 0); | |
| 7667 } | 7676 } |
| 7668 | 7677 |
| 7669 | 7678 |
| 7670 static MaybeObject* Runtime_SetNewFunctionAttributes(Arguments args) { | 7679 static MaybeObject* Runtime_SetNewFunctionAttributes(Arguments args) { |
| 7671 // This utility adjusts the property attributes for newly created Function | 7680 // This utility adjusts the property attributes for newly created Function |
| 7672 // object ("new Function(...)") by changing the map. | 7681 // object ("new Function(...)") by changing the map. |
| 7673 // All it does is changing the prototype property to enumerable | 7682 // All it does is changing the prototype property to enumerable |
| 7674 // as specified in ECMA262, 15.3.5.2. | 7683 // as specified in ECMA262, 15.3.5.2. |
| 7675 HandleScope scope; | 7684 HandleScope scope; |
| 7676 ASSERT(args.length() == 1); | 7685 ASSERT(args.length() == 1); |
| (...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9796 // function(arguments,__source__) {return eval(__source__);} | 9805 // function(arguments,__source__) {return eval(__source__);} |
| 9797 static const char* source_str = | 9806 static const char* source_str = |
| 9798 "(function(arguments,__source__){return eval(__source__);})"; | 9807 "(function(arguments,__source__){return eval(__source__);})"; |
| 9799 static const int source_str_length = StrLength(source_str); | 9808 static const int source_str_length = StrLength(source_str); |
| 9800 Handle<String> function_source = | 9809 Handle<String> function_source = |
| 9801 Factory::NewStringFromAscii(Vector<const char>(source_str, | 9810 Factory::NewStringFromAscii(Vector<const char>(source_str, |
| 9802 source_str_length)); | 9811 source_str_length)); |
| 9803 Handle<SharedFunctionInfo> shared = | 9812 Handle<SharedFunctionInfo> shared = |
| 9804 Compiler::CompileEval(function_source, | 9813 Compiler::CompileEval(function_source, |
| 9805 context, | 9814 context, |
| 9806 context->IsGlobalContext()); | 9815 context->IsGlobalContext(), |
| 9816 false); | |
|
Lasse Reichstein
2011/02/03 12:36:01
It deserves a comment that we always run the code
Martin Maly
2011/02/04 01:02:34
Done.
| |
| 9807 if (shared.is_null()) return Failure::Exception(); | 9817 if (shared.is_null()) return Failure::Exception(); |
| 9808 Handle<JSFunction> compiled_function = | 9818 Handle<JSFunction> compiled_function = |
| 9809 Factory::NewFunctionFromSharedFunctionInfo(shared, context); | 9819 Factory::NewFunctionFromSharedFunctionInfo(shared, context); |
| 9810 | 9820 |
| 9811 // Invoke the result of the compilation to get the evaluation function. | 9821 // Invoke the result of the compilation to get the evaluation function. |
| 9812 bool has_pending_exception; | 9822 bool has_pending_exception; |
| 9813 Handle<Object> receiver(frame->receiver()); | 9823 Handle<Object> receiver(frame->receiver()); |
| 9814 Handle<Object> evaluation_function = | 9824 Handle<Object> evaluation_function = |
| 9815 Execution::Call(compiled_function, receiver, 0, NULL, | 9825 Execution::Call(compiled_function, receiver, 0, NULL, |
| 9816 &has_pending_exception); | 9826 &has_pending_exception); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 9879 Factory::empty_string(), Factory::undefined_value()); | 9889 Factory::empty_string(), Factory::undefined_value()); |
| 9880 go_between->set_context(*context); | 9890 go_between->set_context(*context); |
| 9881 context = | 9891 context = |
| 9882 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); | 9892 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); |
| 9883 context->set_extension(JSObject::cast(*additional_context)); | 9893 context->set_extension(JSObject::cast(*additional_context)); |
| 9884 is_global = false; | 9894 is_global = false; |
| 9885 } | 9895 } |
| 9886 | 9896 |
| 9887 // Compile the source to be evaluated. | 9897 // Compile the source to be evaluated. |
| 9888 Handle<SharedFunctionInfo> shared = | 9898 Handle<SharedFunctionInfo> shared = |
| 9889 Compiler::CompileEval(source, | 9899 Compiler::CompileEval(source, context, is_global, false); |
| 9890 context, | |
| 9891 is_global); | |
| 9892 if (shared.is_null()) return Failure::Exception(); | 9900 if (shared.is_null()) return Failure::Exception(); |
| 9893 Handle<JSFunction> compiled_function = | 9901 Handle<JSFunction> compiled_function = |
| 9894 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, | 9902 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, |
| 9895 context)); | 9903 context)); |
| 9896 | 9904 |
| 9897 // Invoke the result of the compilation to get the evaluation function. | 9905 // Invoke the result of the compilation to get the evaluation function. |
| 9898 bool has_pending_exception; | 9906 bool has_pending_exception; |
| 9899 Handle<Object> receiver = Top::global(); | 9907 Handle<Object> receiver = Top::global(); |
| 9900 Handle<Object> result = | 9908 Handle<Object> result = |
| 9901 Execution::Call(compiled_function, receiver, 0, NULL, | 9909 Execution::Call(compiled_function, receiver, 0, NULL, |
| (...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 10870 } else { | 10878 } else { |
| 10871 // Handle last resort GC and make sure to allow future allocations | 10879 // Handle last resort GC and make sure to allow future allocations |
| 10872 // to grow the heap without causing GCs (if possible). | 10880 // to grow the heap without causing GCs (if possible). |
| 10873 Counters::gc_last_resort_from_js.Increment(); | 10881 Counters::gc_last_resort_from_js.Increment(); |
| 10874 Heap::CollectAllGarbage(false); | 10882 Heap::CollectAllGarbage(false); |
| 10875 } | 10883 } |
| 10876 } | 10884 } |
| 10877 | 10885 |
| 10878 | 10886 |
| 10879 } } // namespace v8::internal | 10887 } } // namespace v8::internal |
| OLD | NEW |