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

Side by Side Diff: src/runtime.cc

Issue 2666001: Optimize calls to evals. Most of the time there is no reason to... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: Created 10 years, 6 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
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/eval.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 7227 matching lines...) Expand 10 before | Expand all | Expand 10 after
7238 context, 7238 context,
7239 true, 7239 true,
7240 validate); 7240 validate);
7241 if (shared.is_null()) return Failure::Exception(); 7241 if (shared.is_null()) return Failure::Exception();
7242 Handle<JSFunction> fun = 7242 Handle<JSFunction> fun =
7243 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED); 7243 Factory::NewFunctionFromSharedFunctionInfo(shared, context, NOT_TENURED);
7244 return *fun; 7244 return *fun;
7245 } 7245 }
7246 7246
7247 7247
7248 static ObjectPair CompileGlobalEval(Handle<String> source,
7249 Handle<Object> receiver) {
7250 // Deal with a normal eval call with a string argument. Compile it
7251 // and return the compiled function bound in the local context.
7252 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
7253 source,
7254 Handle<Context>(Top::context()),
7255 Top::context()->IsGlobalContext(),
7256 Compiler::DONT_VALIDATE_JSON);
7257 if (shared.is_null()) return MakePair(Failure::Exception(), NULL);
7258 Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo(
7259 shared,
7260 Handle<Context>(Top::context()),
7261 NOT_TENURED);
7262 return MakePair(*compiled, *receiver);
7263 }
7264
7265
7248 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) { 7266 static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) {
7249 ASSERT(args.length() == 3); 7267 ASSERT(args.length() == 3);
7250 if (!args[0]->IsJSFunction()) { 7268 if (!args[0]->IsJSFunction()) {
7251 return MakePair(Top::ThrowIllegalOperation(), NULL); 7269 return MakePair(Top::ThrowIllegalOperation(), NULL);
7252 } 7270 }
7253 7271
7254 HandleScope scope; 7272 HandleScope scope;
7255 Handle<JSFunction> callee = args.at<JSFunction>(0); 7273 Handle<JSFunction> callee = args.at<JSFunction>(0);
7256 Handle<Object> receiver; // Will be overwritten. 7274 Handle<Object> receiver; // Will be overwritten.
7257 7275
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
7303 return MakePair(*callee, *receiver); 7321 return MakePair(*callee, *receiver);
7304 } 7322 }
7305 7323
7306 // 'eval' is bound in the global context, but it may have been overwritten. 7324 // 'eval' is bound in the global context, but it may have been overwritten.
7307 // Compare it to the builtin 'GlobalEval' function to make sure. 7325 // Compare it to the builtin 'GlobalEval' function to make sure.
7308 if (*callee != Top::global_context()->global_eval_fun() || 7326 if (*callee != Top::global_context()->global_eval_fun() ||
7309 !args[1]->IsString()) { 7327 !args[1]->IsString()) {
7310 return MakePair(*callee, Top::context()->global()->global_receiver()); 7328 return MakePair(*callee, Top::context()->global()->global_receiver());
7311 } 7329 }
7312 7330
7313 // Deal with a normal eval call with a string argument. Compile it 7331 return CompileGlobalEval(args.at<String>(1), args.at<Object>(2));
7314 // and return the compiled function bound in the local context. 7332 }
7315 Handle<String> source = args.at<String>(1); 7333
7316 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( 7334
7317 source, 7335 static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) {
7318 Handle<Context>(Top::context()), 7336 ASSERT(args.length() == 3);
7319 Top::context()->IsGlobalContext(), 7337 if (!args[0]->IsJSFunction()) {
7320 Compiler::DONT_VALIDATE_JSON); 7338 return MakePair(Top::ThrowIllegalOperation(), NULL);
7321 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); 7339 }
7322 callee = Factory::NewFunctionFromSharedFunctionInfo( 7340
7323 shared, 7341 HandleScope scope;
7324 Handle<Context>(Top::context()), 7342 Handle<JSFunction> callee = args.at<JSFunction>(0);
7325 NOT_TENURED); 7343
7326 return MakePair(*callee, args[2]); 7344 // 'eval' is bound in the global context, but it may have been overwritten.
7345 // Compare it to the builtin 'GlobalEval' function to make sure.
7346 if (*callee != Top::global_context()->global_eval_fun() ||
7347 !args[1]->IsString()) {
7348 return MakePair(*callee, Top::context()->global()->global_receiver());
7349 }
7350
7351 return CompileGlobalEval(args.at<String>(1), args.at<Object>(2));
7327 } 7352 }
7328 7353
7329 7354
7330 static Object* Runtime_SetNewFunctionAttributes(Arguments args) { 7355 static Object* Runtime_SetNewFunctionAttributes(Arguments args) {
7331 // This utility adjusts the property attributes for newly created Function 7356 // This utility adjusts the property attributes for newly created Function
7332 // object ("new Function(...)") by changing the map. 7357 // object ("new Function(...)") by changing the map.
7333 // All it does is changing the prototype property to enumerable 7358 // All it does is changing the prototype property to enumerable
7334 // as specified in ECMA262, 15.3.5.2. 7359 // as specified in ECMA262, 15.3.5.2.
7335 HandleScope scope; 7360 HandleScope scope;
7336 ASSERT(args.length() == 1); 7361 ASSERT(args.length() == 1);
(...skipping 2967 matching lines...) Expand 10 before | Expand all | Expand 10 after
10304 } else { 10329 } else {
10305 // Handle last resort GC and make sure to allow future allocations 10330 // Handle last resort GC and make sure to allow future allocations
10306 // to grow the heap without causing GCs (if possible). 10331 // to grow the heap without causing GCs (if possible).
10307 Counters::gc_last_resort_from_js.Increment(); 10332 Counters::gc_last_resort_from_js.Increment();
10308 Heap::CollectAllGarbage(false); 10333 Heap::CollectAllGarbage(false);
10309 } 10334 }
10310 } 10335 }
10311 10336
10312 10337
10313 } } // namespace v8::internal 10338 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/eval.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698