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 kNonStrictMode); |
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 StrictModeFlag mode) { |
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 mode); |
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 static_cast<StrictModeFlag>( |
| 7653 Smi::cast(args[3])->value())); |
7647 } | 7654 } |
7648 | 7655 |
7649 | 7656 |
7650 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) { | 7657 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) { |
7651 ASSERT(args.length() == 3); | 7658 ASSERT(args.length() == 4); |
7652 if (!args[0]->IsJSFunction()) { | 7659 if (!args[0]->IsJSFunction()) { |
7653 return MakePair(Top::ThrowIllegalOperation(), NULL); | 7660 return MakePair(Top::ThrowIllegalOperation(), NULL); |
7654 } | 7661 } |
7655 | 7662 |
7656 HandleScope scope; | 7663 HandleScope scope; |
7657 Handle<JSFunction> callee = args.at<JSFunction>(0); | 7664 Handle<JSFunction> callee = args.at<JSFunction>(0); |
7658 | 7665 |
7659 // 'eval' is bound in the global context, but it may have been overwritten. | 7666 // 'eval' is bound in the global context, but it may have been overwritten. |
7660 // Compare it to the builtin 'GlobalEval' function to make sure. | 7667 // Compare it to the builtin 'GlobalEval' function to make sure. |
7661 if (*callee != Top::global_context()->global_eval_fun() || | 7668 if (*callee != Top::global_context()->global_eval_fun() || |
7662 !args[1]->IsString()) { | 7669 !args[1]->IsString()) { |
7663 return MakePair(*callee, Top::context()->global()->global_receiver()); | 7670 return MakePair(*callee, Top::context()->global()->global_receiver()); |
7664 } | 7671 } |
7665 | 7672 |
7666 return CompileGlobalEval(args.at<String>(1), args.at<Object>(2)); | 7673 ASSERT(args[3]->IsSmi()); |
| 7674 return CompileGlobalEval(args.at<String>(1), |
| 7675 args.at<Object>(2), |
| 7676 static_cast<StrictModeFlag>( |
| 7677 Smi::cast(args[3])->value())); |
7667 } | 7678 } |
7668 | 7679 |
7669 | 7680 |
7670 static MaybeObject* Runtime_SetNewFunctionAttributes(Arguments args) { | 7681 static MaybeObject* Runtime_SetNewFunctionAttributes(Arguments args) { |
7671 // This utility adjusts the property attributes for newly created Function | 7682 // This utility adjusts the property attributes for newly created Function |
7672 // object ("new Function(...)") by changing the map. | 7683 // object ("new Function(...)") by changing the map. |
7673 // All it does is changing the prototype property to enumerable | 7684 // All it does is changing the prototype property to enumerable |
7674 // as specified in ECMA262, 15.3.5.2. | 7685 // as specified in ECMA262, 15.3.5.2. |
7675 HandleScope scope; | 7686 HandleScope scope; |
7676 ASSERT(args.length() == 1); | 7687 ASSERT(args.length() == 1); |
(...skipping 2116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9793 // created context. The function has one parameter which has to be called | 9804 // created context. The function has one parameter which has to be called |
9794 // 'arguments'. This it to have access to what would have been 'arguments' in | 9805 // 'arguments'. This it to have access to what would have been 'arguments' in |
9795 // the function being debugged. | 9806 // the function being debugged. |
9796 // function(arguments,__source__) {return eval(__source__);} | 9807 // function(arguments,__source__) {return eval(__source__);} |
9797 static const char* source_str = | 9808 static const char* source_str = |
9798 "(function(arguments,__source__){return eval(__source__);})"; | 9809 "(function(arguments,__source__){return eval(__source__);})"; |
9799 static const int source_str_length = StrLength(source_str); | 9810 static const int source_str_length = StrLength(source_str); |
9800 Handle<String> function_source = | 9811 Handle<String> function_source = |
9801 Factory::NewStringFromAscii(Vector<const char>(source_str, | 9812 Factory::NewStringFromAscii(Vector<const char>(source_str, |
9802 source_str_length)); | 9813 source_str_length)); |
| 9814 |
| 9815 // Currently, the eval code will be executed in non-strict mode, |
| 9816 // even in the strict code context. |
9803 Handle<SharedFunctionInfo> shared = | 9817 Handle<SharedFunctionInfo> shared = |
9804 Compiler::CompileEval(function_source, | 9818 Compiler::CompileEval(function_source, |
9805 context, | 9819 context, |
9806 context->IsGlobalContext()); | 9820 context->IsGlobalContext(), |
| 9821 kNonStrictMode); |
9807 if (shared.is_null()) return Failure::Exception(); | 9822 if (shared.is_null()) return Failure::Exception(); |
9808 Handle<JSFunction> compiled_function = | 9823 Handle<JSFunction> compiled_function = |
9809 Factory::NewFunctionFromSharedFunctionInfo(shared, context); | 9824 Factory::NewFunctionFromSharedFunctionInfo(shared, context); |
9810 | 9825 |
9811 // Invoke the result of the compilation to get the evaluation function. | 9826 // Invoke the result of the compilation to get the evaluation function. |
9812 bool has_pending_exception; | 9827 bool has_pending_exception; |
9813 Handle<Object> receiver(frame->receiver()); | 9828 Handle<Object> receiver(frame->receiver()); |
9814 Handle<Object> evaluation_function = | 9829 Handle<Object> evaluation_function = |
9815 Execution::Call(compiled_function, receiver, 0, NULL, | 9830 Execution::Call(compiled_function, receiver, 0, NULL, |
9816 &has_pending_exception); | 9831 &has_pending_exception); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9878 Handle<JSFunction> go_between = Factory::NewFunction( | 9893 Handle<JSFunction> go_between = Factory::NewFunction( |
9879 Factory::empty_string(), Factory::undefined_value()); | 9894 Factory::empty_string(), Factory::undefined_value()); |
9880 go_between->set_context(*context); | 9895 go_between->set_context(*context); |
9881 context = | 9896 context = |
9882 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); | 9897 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); |
9883 context->set_extension(JSObject::cast(*additional_context)); | 9898 context->set_extension(JSObject::cast(*additional_context)); |
9884 is_global = false; | 9899 is_global = false; |
9885 } | 9900 } |
9886 | 9901 |
9887 // Compile the source to be evaluated. | 9902 // Compile the source to be evaluated. |
| 9903 // Currently, the eval code will be executed in non-strict mode, |
| 9904 // even in the strict code context. |
9888 Handle<SharedFunctionInfo> shared = | 9905 Handle<SharedFunctionInfo> shared = |
9889 Compiler::CompileEval(source, | 9906 Compiler::CompileEval(source, context, is_global, kNonStrictMode); |
9890 context, | |
9891 is_global); | |
9892 if (shared.is_null()) return Failure::Exception(); | 9907 if (shared.is_null()) return Failure::Exception(); |
9893 Handle<JSFunction> compiled_function = | 9908 Handle<JSFunction> compiled_function = |
9894 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, | 9909 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, |
9895 context)); | 9910 context)); |
9896 | 9911 |
9897 // Invoke the result of the compilation to get the evaluation function. | 9912 // Invoke the result of the compilation to get the evaluation function. |
9898 bool has_pending_exception; | 9913 bool has_pending_exception; |
9899 Handle<Object> receiver = Top::global(); | 9914 Handle<Object> receiver = Top::global(); |
9900 Handle<Object> result = | 9915 Handle<Object> result = |
9901 Execution::Call(compiled_function, receiver, 0, NULL, | 9916 Execution::Call(compiled_function, receiver, 0, NULL, |
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
10870 } else { | 10885 } else { |
10871 // Handle last resort GC and make sure to allow future allocations | 10886 // Handle last resort GC and make sure to allow future allocations |
10872 // to grow the heap without causing GCs (if possible). | 10887 // to grow the heap without causing GCs (if possible). |
10873 Counters::gc_last_resort_from_js.Increment(); | 10888 Counters::gc_last_resort_from_js.Increment(); |
10874 Heap::CollectAllGarbage(false); | 10889 Heap::CollectAllGarbage(false); |
10875 } | 10890 } |
10876 } | 10891 } |
10877 | 10892 |
10878 | 10893 |
10879 } } // namespace v8::internal | 10894 } } // namespace v8::internal |
OLD | NEW |