Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(579)

Side by Side Diff: src/runtime.cc

Issue 6286043: Direct call to eval passes strict mode through. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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);
Lasse Reichstein 2011/02/03 12:10:41 Passing too many boolean literals (some say one is
Martin Maly 2011/02/04 01:02:34 Done.
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() == 3);
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());
7593 #ifdef DEBUG
7594 // Make sure Top::context() agrees with the old code that traversed 7596 // Make sure Top::context() agrees with the old code that traversed
7595 // the stack frames to compute the context. 7597 // the stack frames to compute the context.
7596 StackFrameLocator locator; 7598 StackFrameLocator locator;
7597 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 7599 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
7598 ASSERT(Context::cast(frame->context()) == *context); 7600 ASSERT(Context::cast(frame->context()) == *context);
7599 #endif
7600 7601
7601 // Find where the 'eval' symbol is bound. It is unaliased only if 7602 // Find where the 'eval' symbol is bound. It is unaliased only if
7602 // it is bound in the global context. 7603 // it is bound in the global context.
7603 int index = -1; 7604 int index = -1;
7604 PropertyAttributes attributes = ABSENT; 7605 PropertyAttributes attributes = ABSENT;
7605 while (true) { 7606 while (true) {
7606 receiver = context->Lookup(Factory::eval_symbol(), FOLLOW_PROTOTYPE_CHAIN, 7607 receiver = context->Lookup(Factory::eval_symbol(), FOLLOW_PROTOTYPE_CHAIN,
7607 &index, &attributes); 7608 &index, &attributes);
7608 // Stop search when eval is found or when the global context is 7609 // Stop search when eval is found or when the global context is
7609 // reached. 7610 // reached.
(...skipping 26 matching lines...) Expand all
7636 return MakePair(*callee, *receiver); 7637 return MakePair(*callee, *receiver);
7637 } 7638 }
7638 7639
7639 // 'eval' is bound in the global context, but it may have been overwritten. 7640 // 'eval' is bound in the global context, but it may have been overwritten.
7640 // Compare it to the builtin 'GlobalEval' function to make sure. 7641 // Compare it to the builtin 'GlobalEval' function to make sure.
7641 if (*callee != Top::global_context()->global_eval_fun() || 7642 if (*callee != Top::global_context()->global_eval_fun() ||
7642 !args[1]->IsString()) { 7643 !args[1]->IsString()) {
7643 return MakePair(*callee, Top::context()->global()->global_receiver()); 7644 return MakePair(*callee, Top::context()->global()->global_receiver());
7644 } 7645 }
7645 7646
7646 return CompileGlobalEval(args.at<String>(1), args.at<Object>(2)); 7647 Handle<JSFunction> caller(JSFunction::cast(frame->function()));
Martin Maly 2011/02/02 05:07:26 Alternative to walking the stack frames is passing
Mads Ager (chromium) 2011/02/02 10:30:03 When you are compiling the caller you know whether
Martin Maly 2011/02/02 23:56:22 Done.
7648 return CompileGlobalEval(args.at<String>(1),
7649 args.at<Object>(2),
7650 caller->shared()->strict_mode());
7647 } 7651 }
7648 7652
7649 7653
7650 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) { 7654 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) {
7651 ASSERT(args.length() == 3); 7655 ASSERT(args.length() == 3);
7652 if (!args[0]->IsJSFunction()) { 7656 if (!args[0]->IsJSFunction()) {
7653 return MakePair(Top::ThrowIllegalOperation(), NULL); 7657 return MakePair(Top::ThrowIllegalOperation(), NULL);
7654 } 7658 }
7655 7659
7656 HandleScope scope; 7660 HandleScope scope;
7657 Handle<JSFunction> callee = args.at<JSFunction>(0); 7661 Handle<JSFunction> callee = args.at<JSFunction>(0);
7658 7662
7659 // 'eval' is bound in the global context, but it may have been overwritten. 7663 // 'eval' is bound in the global context, but it may have been overwritten.
7660 // Compare it to the builtin 'GlobalEval' function to make sure. 7664 // Compare it to the builtin 'GlobalEval' function to make sure.
7661 if (*callee != Top::global_context()->global_eval_fun() || 7665 if (*callee != Top::global_context()->global_eval_fun() ||
7662 !args[1]->IsString()) { 7666 !args[1]->IsString()) {
7663 return MakePair(*callee, Top::context()->global()->global_receiver()); 7667 return MakePair(*callee, Top::context()->global()->global_receiver());
7664 } 7668 }
7665 7669
7666 return CompileGlobalEval(args.at<String>(1), args.at<Object>(2)); 7670 StackFrameLocator locator;
7671 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
Martin Maly 2011/02/02 05:07:26 Alternative to walking the stack frames is passing
Mads Ager (chromium) 2011/02/02 10:30:03 I would go for the additional argument here too.
Martin Maly 2011/02/02 23:56:22 Done.
7672 Handle<JSFunction> caller(JSFunction::cast(frame->function()));
7673
7674 return CompileGlobalEval(args.at<String>(1),
7675 args.at<Object>(2),
7676 caller->shared()->strict_mode());
7667 } 7677 }
7668 7678
7669 7679
7670 static MaybeObject* Runtime_SetNewFunctionAttributes(Arguments args) { 7680 static MaybeObject* Runtime_SetNewFunctionAttributes(Arguments args) {
7671 // This utility adjusts the property attributes for newly created Function 7681 // This utility adjusts the property attributes for newly created Function
7672 // object ("new Function(...)") by changing the map. 7682 // object ("new Function(...)") by changing the map.
7673 // All it does is changing the prototype property to enumerable 7683 // All it does is changing the prototype property to enumerable
7674 // as specified in ECMA262, 15.3.5.2. 7684 // as specified in ECMA262, 15.3.5.2.
7675 HandleScope scope; 7685 HandleScope scope;
7676 ASSERT(args.length() == 1); 7686 ASSERT(args.length() == 1);
(...skipping 2119 matching lines...) Expand 10 before | Expand all | Expand 10 after
9796 // function(arguments,__source__) {return eval(__source__);} 9806 // function(arguments,__source__) {return eval(__source__);}
9797 static const char* source_str = 9807 static const char* source_str =
9798 "(function(arguments,__source__){return eval(__source__);})"; 9808 "(function(arguments,__source__){return eval(__source__);})";
9799 static const int source_str_length = StrLength(source_str); 9809 static const int source_str_length = StrLength(source_str);
9800 Handle<String> function_source = 9810 Handle<String> function_source =
9801 Factory::NewStringFromAscii(Vector<const char>(source_str, 9811 Factory::NewStringFromAscii(Vector<const char>(source_str,
9802 source_str_length)); 9812 source_str_length));
9803 Handle<SharedFunctionInfo> shared = 9813 Handle<SharedFunctionInfo> shared =
9804 Compiler::CompileEval(function_source, 9814 Compiler::CompileEval(function_source,
9805 context, 9815 context,
9806 context->IsGlobalContext()); 9816 context->IsGlobalContext(),
9817 false);
Martin Maly 2011/02/02 05:07:26 Need to follow up with debugger folks what the rig
9807 if (shared.is_null()) return Failure::Exception(); 9818 if (shared.is_null()) return Failure::Exception();
9808 Handle<JSFunction> compiled_function = 9819 Handle<JSFunction> compiled_function =
9809 Factory::NewFunctionFromSharedFunctionInfo(shared, context); 9820 Factory::NewFunctionFromSharedFunctionInfo(shared, context);
9810 9821
9811 // Invoke the result of the compilation to get the evaluation function. 9822 // Invoke the result of the compilation to get the evaluation function.
9812 bool has_pending_exception; 9823 bool has_pending_exception;
9813 Handle<Object> receiver(frame->receiver()); 9824 Handle<Object> receiver(frame->receiver());
9814 Handle<Object> evaluation_function = 9825 Handle<Object> evaluation_function =
9815 Execution::Call(compiled_function, receiver, 0, NULL, 9826 Execution::Call(compiled_function, receiver, 0, NULL,
9816 &has_pending_exception); 9827 &has_pending_exception);
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
9879 Factory::empty_string(), Factory::undefined_value()); 9890 Factory::empty_string(), Factory::undefined_value());
9880 go_between->set_context(*context); 9891 go_between->set_context(*context);
9881 context = 9892 context =
9882 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between); 9893 Factory::NewFunctionContext(Context::MIN_CONTEXT_SLOTS, go_between);
9883 context->set_extension(JSObject::cast(*additional_context)); 9894 context->set_extension(JSObject::cast(*additional_context));
9884 is_global = false; 9895 is_global = false;
9885 } 9896 }
9886 9897
9887 // Compile the source to be evaluated. 9898 // Compile the source to be evaluated.
9888 Handle<SharedFunctionInfo> shared = 9899 Handle<SharedFunctionInfo> shared =
9889 Compiler::CompileEval(source, 9900 Compiler::CompileEval(source, context, is_global, false);
Martin Maly 2011/02/02 05:07:26 ditto, follow up with debugger folks what the righ
9890 context,
9891 is_global);
9892 if (shared.is_null()) return Failure::Exception(); 9901 if (shared.is_null()) return Failure::Exception();
9893 Handle<JSFunction> compiled_function = 9902 Handle<JSFunction> compiled_function =
9894 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared, 9903 Handle<JSFunction>(Factory::NewFunctionFromSharedFunctionInfo(shared,
9895 context)); 9904 context));
9896 9905
9897 // Invoke the result of the compilation to get the evaluation function. 9906 // Invoke the result of the compilation to get the evaluation function.
9898 bool has_pending_exception; 9907 bool has_pending_exception;
9899 Handle<Object> receiver = Top::global(); 9908 Handle<Object> receiver = Top::global();
9900 Handle<Object> result = 9909 Handle<Object> result =
9901 Execution::Call(compiled_function, receiver, 0, NULL, 9910 Execution::Call(compiled_function, receiver, 0, NULL,
(...skipping 968 matching lines...) Expand 10 before | Expand all | Expand 10 after
10870 } else { 10879 } else {
10871 // Handle last resort GC and make sure to allow future allocations 10880 // Handle last resort GC and make sure to allow future allocations
10872 // to grow the heap without causing GCs (if possible). 10881 // to grow the heap without causing GCs (if possible).
10873 Counters::gc_last_resort_from_js.Increment(); 10882 Counters::gc_last_resort_from_js.Increment();
10874 Heap::CollectAllGarbage(false); 10883 Heap::CollectAllGarbage(false);
10875 } 10884 }
10876 } 10885 }
10877 10886
10878 10887
10879 } } // namespace v8::internal 10888 } } // namespace v8::internal
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698