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

Side by Side Diff: src/runtime.cc

Issue 8343054: Make eval consider anything on the form eval(args...) a potential direct cal (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 years, 1 month 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') | src/v8natives.js » ('j') | src/v8natives.js » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 9412 matching lines...) Expand 10 before | Expand all | Expand 10 after
9423 shared, context, NOT_TENURED); 9423 shared, context, NOT_TENURED);
9424 return MakePair(*compiled, *receiver); 9424 return MakePair(*compiled, *receiver);
9425 } 9425 }
9426 9426
9427 9427
9428 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { 9428 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) {
9429 ASSERT(args.length() == 4); 9429 ASSERT(args.length() == 4);
9430 9430
9431 HandleScope scope(isolate); 9431 HandleScope scope(isolate);
9432 Handle<Object> callee = args.at<Object>(0); 9432 Handle<Object> callee = args.at<Object>(0);
9433 Handle<Object> receiver; // Will be overwritten.
9434
9435 // Compute the calling context.
9436 Handle<Context> context = Handle<Context>(isolate->context(), isolate);
9437 #ifdef DEBUG
9438 // Make sure Isolate::context() agrees with the old code that traversed
9439 // the stack frames to compute the context.
9440 StackFrameLocator locator;
9441 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0);
9442 ASSERT(Context::cast(frame->context()) == *context);
9443 #endif
9444
9445 // Find where the 'eval' symbol is bound. It is unaliased only if
9446 // it is bound in the global context.
9447 int index = -1;
9448 PropertyAttributes attributes = ABSENT;
9449 BindingFlags binding_flags;
9450 while (true) {
9451 // Don't follow context chains in Context::Lookup and implement the loop
9452 // up the context chain here, so that we can know the context where eval
9453 // was found.
9454 receiver = context->Lookup(isolate->factory()->eval_symbol(),
9455 FOLLOW_PROTOTYPE_CHAIN,
9456 &index,
9457 &attributes,
9458 &binding_flags);
9459 // Stop search when eval is found or when the global context is
9460 // reached.
9461 if (attributes != ABSENT || context->IsGlobalContext()) break;
9462 context = Handle<Context>(context->previous(), isolate);
9463 }
9464
9465 // If eval could not be resolved, it has been deleted and we need to
9466 // throw a reference error.
9467 if (attributes == ABSENT) {
9468 Handle<Object> name = isolate->factory()->eval_symbol();
9469 Handle<Object> reference_error =
9470 isolate->factory()->NewReferenceError("not_defined",
9471 HandleVector(&name, 1));
9472 return MakePair(isolate->Throw(*reference_error), NULL);
9473 }
9474
9475 if (!context->IsGlobalContext()) {
9476 // 'eval' is not bound in the global context. Just call the function
9477 // with the given arguments. This is not necessarily the global eval.
9478 if (receiver->IsContext() || receiver->IsJSContextExtensionObject()) {
9479 receiver = isolate->factory()->the_hole_value();
9480 }
9481 return MakePair(*callee, *receiver);
9482 }
9483
9484 // 'eval' is bound in the global context, but it may have been overwritten.
9485 // Compare it to the builtin 'GlobalEval' function to make sure.
9486 if (*callee != isolate->global_context()->global_eval_fun() ||
9487 !args[1]->IsString()) {
9488 return MakePair(*callee, isolate->heap()->the_hole_value());
9489 }
9490
9491 ASSERT(args[3]->IsSmi());
9492 return CompileGlobalEval(isolate,
9493 args.at<String>(1),
9494 args.at<Object>(2),
9495 static_cast<StrictModeFlag>(args.smi_at(3)));
9496 }
9497
9498
9499 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEvalNoLookup) {
9500 ASSERT(args.length() == 4);
9501
9502 HandleScope scope(isolate);
9503 Handle<Object> callee = args.at<Object>(0);
9504 9433
9505 // 'eval' is bound in the global context, but it may have been overwritten. 9434 // If "eval" didn't refer to the original GlobalEval, it's not a
9506 // Compare it to the builtin 'GlobalEval' function to make sure. 9435 // direct call to eval.
9436 // (And even if it is, but the first argument isn't a string, just let
9437 // execution default to an indirect call to eval, which will also return
9438 // the first argument without doing anything).
9507 if (*callee != isolate->global_context()->global_eval_fun() || 9439 if (*callee != isolate->global_context()->global_eval_fun() ||
9508 !args[1]->IsString()) { 9440 !args[1]->IsString()) {
9509 return MakePair(*callee, isolate->heap()->the_hole_value()); 9441 return MakePair(*callee, isolate->heap()->the_hole_value());
9510 } 9442 }
9511 9443
9512 ASSERT(args[3]->IsSmi()); 9444 ASSERT(args[3]->IsSmi());
9513 return CompileGlobalEval(isolate, 9445 return CompileGlobalEval(isolate,
9514 args.at<String>(1), 9446 args.at<String>(1),
9515 args.at<Object>(2), 9447 args.at<Object>(2),
9516 static_cast<StrictModeFlag>(args.smi_at(3))); 9448 static_cast<StrictModeFlag>(args.smi_at(3)));
(...skipping 4009 matching lines...) Expand 10 before | Expand all | Expand 10 after
13526 } else { 13458 } else {
13527 // Handle last resort GC and make sure to allow future allocations 13459 // Handle last resort GC and make sure to allow future allocations
13528 // to grow the heap without causing GCs (if possible). 13460 // to grow the heap without causing GCs (if possible).
13529 isolate->counters()->gc_last_resort_from_js()->Increment(); 13461 isolate->counters()->gc_last_resort_from_js()->Increment();
13530 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); 13462 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags);
13531 } 13463 }
13532 } 13464 }
13533 13465
13534 13466
13535 } } // namespace v8::internal 13467 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/v8natives.js » ('j') | src/v8natives.js » ('J')

Powered by Google App Engine
This is Rietveld 408576698