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

Side by Side Diff: src/runtime.cc

Issue 6591075: Allow eval to be overridden with a callable non-function object. (Closed)
Patch Set: Created 9 years, 9 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
« no previous file with comments | « no previous file | test/mjsunit/override-eval-with-non-function.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 7854 matching lines...) Expand 10 before | Expand all | Expand 10 after
7865 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo( 7865 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo(
7866 shared, 7866 shared,
7867 Handle<Context>(Top::context()), 7867 Handle<Context>(Top::context()),
7868 NOT_TENURED); 7868 NOT_TENURED);
7869 return MakePair(*compiled, *receiver); 7869 return MakePair(*compiled, *receiver);
7870 } 7870 }
7871 7871
7872 7872
7873 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { 7873 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) {
7874 ASSERT(args.length() == 4); 7874 ASSERT(args.length() == 4);
7875 if (!args[0]->IsJSFunction()) {
7876 return MakePair(Top::ThrowIllegalOperation(), NULL);
7877 }
7878 7875
7879 HandleScope scope; 7876 HandleScope scope;
7880 Handle<JSFunction> callee = args.at<JSFunction>(0); 7877 Handle<Object> callee = args.at<Object>(0);
7881 Handle<Object> receiver; // Will be overwritten. 7878 Handle<Object> receiver; // Will be overwritten.
7882 7879
7883 // Compute the calling context. 7880 // Compute the calling context.
7884 Handle<Context> context = Handle<Context>(Top::context()); 7881 Handle<Context> context = Handle<Context>(Top::context());
7885 #ifdef DEBUG 7882 #ifdef DEBUG
7886 // Make sure Top::context() agrees with the old code that traversed 7883 // Make sure Top::context() agrees with the old code that traversed
7887 // the stack frames to compute the context. 7884 // the stack frames to compute the context.
7888 StackFrameLocator locator; 7885 StackFrameLocator locator;
7889 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); 7886 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
7890 ASSERT(Context::cast(frame->context()) == *context); 7887 ASSERT(Context::cast(frame->context()) == *context);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
7938 ASSERT(args[3]->IsSmi()); 7935 ASSERT(args[3]->IsSmi());
7939 return CompileGlobalEval(args.at<String>(1), 7936 return CompileGlobalEval(args.at<String>(1),
7940 args.at<Object>(2), 7937 args.at<Object>(2),
7941 static_cast<StrictModeFlag>( 7938 static_cast<StrictModeFlag>(
7942 Smi::cast(args[3])->value())); 7939 Smi::cast(args[3])->value()));
7943 } 7940 }
7944 7941
7945 7942
7946 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) { 7943 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) {
7947 ASSERT(args.length() == 4); 7944 ASSERT(args.length() == 4);
7948 if (!args[0]->IsJSFunction()) {
7949 return MakePair(Top::ThrowIllegalOperation(), NULL);
7950 }
7951 7945
7952 HandleScope scope; 7946 HandleScope scope;
7953 Handle<JSFunction> callee = args.at<JSFunction>(0); 7947 Handle<Object> callee = args.at<Object>(0);
7954 7948
7955 // 'eval' is bound in the global context, but it may have been overwritten. 7949 // 'eval' is bound in the global context, but it may have been overwritten.
7956 // Compare it to the builtin 'GlobalEval' function to make sure. 7950 // Compare it to the builtin 'GlobalEval' function to make sure.
7957 if (*callee != Top::global_context()->global_eval_fun() || 7951 if (*callee != Top::global_context()->global_eval_fun() ||
7958 !args[1]->IsString()) { 7952 !args[1]->IsString()) {
7959 return MakePair(*callee, Top::context()->global()->global_receiver()); 7953 return MakePair(*callee, Top::context()->global()->global_receiver());
7960 } 7954 }
7961 7955
7962 ASSERT(args[3]->IsSmi()); 7956 ASSERT(args[3]->IsSmi());
7963 return CompileGlobalEval(args.at<String>(1), 7957 return CompileGlobalEval(args.at<String>(1),
(...skipping 3359 matching lines...) Expand 10 before | Expand all | Expand 10 after
11323 } else { 11317 } else {
11324 // Handle last resort GC and make sure to allow future allocations 11318 // Handle last resort GC and make sure to allow future allocations
11325 // to grow the heap without causing GCs (if possible). 11319 // to grow the heap without causing GCs (if possible).
11326 Counters::gc_last_resort_from_js.Increment(); 11320 Counters::gc_last_resort_from_js.Increment();
11327 Heap::CollectAllGarbage(false); 11321 Heap::CollectAllGarbage(false);
11328 } 11322 }
11329 } 11323 }
11330 11324
11331 11325
11332 } } // namespace v8::internal 11326 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | test/mjsunit/override-eval-with-non-function.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698