OLD | NEW |
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 9434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
9445 shared, context, NOT_TENURED); | 9445 shared, context, NOT_TENURED); |
9446 return MakePair(*compiled, *receiver); | 9446 return MakePair(*compiled, *receiver); |
9447 } | 9447 } |
9448 | 9448 |
9449 | 9449 |
9450 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { | 9450 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { |
9451 ASSERT(args.length() == 4); | 9451 ASSERT(args.length() == 4); |
9452 | 9452 |
9453 HandleScope scope(isolate); | 9453 HandleScope scope(isolate); |
9454 Handle<Object> callee = args.at<Object>(0); | 9454 Handle<Object> callee = args.at<Object>(0); |
9455 Handle<Object> receiver; // Will be overwritten. | |
9456 | |
9457 // Compute the calling context. | |
9458 Handle<Context> context = Handle<Context>(isolate->context(), isolate); | |
9459 #ifdef DEBUG | |
9460 // Make sure Isolate::context() agrees with the old code that traversed | |
9461 // the stack frames to compute the context. | |
9462 StackFrameLocator locator; | |
9463 JavaScriptFrame* frame = locator.FindJavaScriptFrame(0); | |
9464 ASSERT(Context::cast(frame->context()) == *context); | |
9465 #endif | |
9466 | |
9467 // Find where the 'eval' symbol is bound. It is unaliased only if | |
9468 // it is bound in the global context. | |
9469 int index = -1; | |
9470 PropertyAttributes attributes = ABSENT; | |
9471 BindingFlags binding_flags; | |
9472 while (true) { | |
9473 // Don't follow context chains in Context::Lookup and implement the loop | |
9474 // up the context chain here, so that we can know the context where eval | |
9475 // was found. | |
9476 receiver = context->Lookup(isolate->factory()->eval_symbol(), | |
9477 FOLLOW_PROTOTYPE_CHAIN, | |
9478 &index, | |
9479 &attributes, | |
9480 &binding_flags); | |
9481 // Stop search when eval is found or when the global context is | |
9482 // reached. | |
9483 if (attributes != ABSENT || context->IsGlobalContext()) break; | |
9484 context = Handle<Context>(context->previous(), isolate); | |
9485 } | |
9486 | |
9487 // If eval could not be resolved, it has been deleted and we need to | |
9488 // throw a reference error. | |
9489 if (attributes == ABSENT) { | |
9490 Handle<Object> name = isolate->factory()->eval_symbol(); | |
9491 Handle<Object> reference_error = | |
9492 isolate->factory()->NewReferenceError("not_defined", | |
9493 HandleVector(&name, 1)); | |
9494 return MakePair(isolate->Throw(*reference_error), NULL); | |
9495 } | |
9496 | |
9497 if (!context->IsGlobalContext()) { | |
9498 // 'eval' is not bound in the global context. Just call the function | |
9499 // with the given arguments. This is not necessarily the global eval. | |
9500 if (receiver->IsContext() || receiver->IsJSContextExtensionObject()) { | |
9501 receiver = isolate->factory()->the_hole_value(); | |
9502 } | |
9503 return MakePair(*callee, *receiver); | |
9504 } | |
9505 | |
9506 // 'eval' is bound in the global context, but it may have been overwritten. | |
9507 // Compare it to the builtin 'GlobalEval' function to make sure. | |
9508 if (*callee != isolate->global_context()->global_eval_fun() || | |
9509 !args[1]->IsString()) { | |
9510 return MakePair(*callee, isolate->heap()->the_hole_value()); | |
9511 } | |
9512 | |
9513 CONVERT_STRICT_MODE_ARG(strict_mode, 3); | |
9514 return CompileGlobalEval(isolate, | |
9515 args.at<String>(1), | |
9516 args.at<Object>(2), | |
9517 strict_mode); | |
9518 } | |
9519 | |
9520 | |
9521 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEvalNoLookup) { | |
9522 ASSERT(args.length() == 4); | |
9523 | |
9524 HandleScope scope(isolate); | |
9525 Handle<Object> callee = args.at<Object>(0); | |
9526 | 9455 |
9527 // 'eval' is bound in the global context, but it may have been overwritten. | 9456 // If "eval" didn't refer to the original GlobalEval, it's not a |
9528 // Compare it to the builtin 'GlobalEval' function to make sure. | 9457 // direct call to eval. |
| 9458 // (And even if it is, but the first argument isn't a string, just let |
| 9459 // execution default to an indirect call to eval, which will also return |
| 9460 // the first argument without doing anything). |
9529 if (*callee != isolate->global_context()->global_eval_fun() || | 9461 if (*callee != isolate->global_context()->global_eval_fun() || |
9530 !args[1]->IsString()) { | 9462 !args[1]->IsString()) { |
9531 return MakePair(*callee, isolate->heap()->the_hole_value()); | 9463 return MakePair(*callee, isolate->heap()->the_hole_value()); |
9532 } | 9464 } |
9533 | 9465 |
9534 CONVERT_STRICT_MODE_ARG(strict_mode, 3); | 9466 CONVERT_STRICT_MODE_ARG(strict_mode, 3); |
9535 return CompileGlobalEval(isolate, | 9467 return CompileGlobalEval(isolate, |
9536 args.at<String>(1), | 9468 args.at<String>(1), |
9537 args.at<Object>(2), | 9469 args.at<Object>(2), |
9538 strict_mode); | 9470 strict_mode); |
(...skipping 4014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13553 } else { | 13485 } else { |
13554 // Handle last resort GC and make sure to allow future allocations | 13486 // Handle last resort GC and make sure to allow future allocations |
13555 // to grow the heap without causing GCs (if possible). | 13487 // to grow the heap without causing GCs (if possible). |
13556 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13488 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13557 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13489 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
13558 } | 13490 } |
13559 } | 13491 } |
13560 | 13492 |
13561 | 13493 |
13562 } } // namespace v8::internal | 13494 } } // namespace v8::internal |
OLD | NEW |