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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/runtime.h ('k') | test/mjsunit/eval.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/runtime.cc
===================================================================
--- src/runtime.cc (revision 4792)
+++ src/runtime.cc (working copy)
@@ -7245,6 +7245,24 @@
}
+static ObjectPair CompileGlobalEval(Handle<String> source,
+ Handle<Object> receiver) {
+ // Deal with a normal eval call with a string argument. Compile it
+ // and return the compiled function bound in the local context.
+ Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
+ source,
+ Handle<Context>(Top::context()),
+ Top::context()->IsGlobalContext(),
+ Compiler::DONT_VALIDATE_JSON);
+ if (shared.is_null()) return MakePair(Failure::Exception(), NULL);
+ Handle<JSFunction> compiled = Factory::NewFunctionFromSharedFunctionInfo(
+ shared,
+ Handle<Context>(Top::context()),
+ NOT_TENURED);
+ return MakePair(*compiled, *receiver);
+}
+
+
static ObjectPair Runtime_ResolvePossiblyDirectEval(Arguments args) {
ASSERT(args.length() == 3);
if (!args[0]->IsJSFunction()) {
@@ -7310,23 +7328,30 @@
return MakePair(*callee, Top::context()->global()->global_receiver());
}
- // Deal with a normal eval call with a string argument. Compile it
- // and return the compiled function bound in the local context.
- Handle<String> source = args.at<String>(1);
- Handle<SharedFunctionInfo> shared = Compiler::CompileEval(
- source,
- Handle<Context>(Top::context()),
- Top::context()->IsGlobalContext(),
- Compiler::DONT_VALIDATE_JSON);
- if (shared.is_null()) return MakePair(Failure::Exception(), NULL);
- callee = Factory::NewFunctionFromSharedFunctionInfo(
- shared,
- Handle<Context>(Top::context()),
- NOT_TENURED);
- return MakePair(*callee, args[2]);
+ return CompileGlobalEval(args.at<String>(1), args.at<Object>(2));
}
+static ObjectPair Runtime_ResolvePossiblyDirectEvalNoLookup(Arguments args) {
+ ASSERT(args.length() == 3);
+ if (!args[0]->IsJSFunction()) {
+ return MakePair(Top::ThrowIllegalOperation(), NULL);
+ }
+
+ HandleScope scope;
+ Handle<JSFunction> callee = args.at<JSFunction>(0);
+
+ // 'eval' is bound in the global context, but it may have been overwritten.
+ // Compare it to the builtin 'GlobalEval' function to make sure.
+ if (*callee != Top::global_context()->global_eval_fun() ||
+ !args[1]->IsString()) {
+ return MakePair(*callee, Top::context()->global()->global_receiver());
+ }
+
+ return CompileGlobalEval(args.at<String>(1), args.at<Object>(2));
+}
+
+
static Object* Runtime_SetNewFunctionAttributes(Arguments args) {
// This utility adjusts the property attributes for newly created Function
// object ("new Function(...)") by changing the map.
« 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