OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 3346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3357 | 3357 |
3358 static Object* Runtime_EvalReceiver(Arguments args) { | 3358 static Object* Runtime_EvalReceiver(Arguments args) { |
3359 StackFrameLocator locator; | 3359 StackFrameLocator locator; |
3360 return locator.FindJavaScriptFrame(1)->receiver(); | 3360 return locator.FindJavaScriptFrame(1)->receiver(); |
3361 } | 3361 } |
3362 | 3362 |
3363 | 3363 |
3364 static Object* Runtime_CompileString(Arguments args) { | 3364 static Object* Runtime_CompileString(Arguments args) { |
3365 HandleScope scope; | 3365 HandleScope scope; |
3366 ASSERT(args.length() == 2); | 3366 ASSERT(args.length() == 2); |
| 3367 CONVERT_ARG_CHECKED(String, source, 0); |
3367 bool contextual = args[1]->IsTrue(); | 3368 bool contextual = args[1]->IsTrue(); |
3368 RUNTIME_ASSERT(contextual || args[1]->IsFalse()); | 3369 RUNTIME_ASSERT(contextual || args[1]->IsFalse()); |
3369 | 3370 |
3370 // Compute the eval context. | 3371 // Compute the eval context. |
3371 Handle<Context> context; | 3372 Handle<Context> context; |
3372 if (contextual) { | 3373 if (contextual) { |
3373 // Get eval context. May not be available if we are calling eval | 3374 // Get eval context. May not be available if we are calling eval |
3374 // through an alias, and the corresponding frame doesn't have a | 3375 // through an alias, and the corresponding frame doesn't have a |
3375 // proper eval context set up. | 3376 // proper eval context set up. |
3376 Object* eval_context = EvalContext(); | 3377 Object* eval_context = EvalContext(); |
3377 if (eval_context->IsFailure()) return eval_context; | 3378 if (eval_context->IsFailure()) return eval_context; |
3378 context = Handle<Context>(Context::cast(eval_context)); | 3379 context = Handle<Context>(Context::cast(eval_context)); |
3379 } else { | 3380 } else { |
3380 context = Handle<Context>(Top::context()->global_context()); | 3381 context = Handle<Context>(Top::context()->global_context()); |
3381 } | 3382 } |
3382 | 3383 |
3383 // Compile eval() source. | |
3384 bool is_global_context = context->IsGlobalContext(); | |
3385 Handle<String> source(String::cast(args[0])); | |
3386 Object* obj = Heap::LookupEvalCache(is_global_context, *source); | |
3387 if (obj->IsFailure()) return obj; | |
3388 | 3384 |
3389 Handle<JSFunction> boilerplate; | 3385 // Compile source string. |
3390 if (!obj->IsJSFunction()) { | 3386 bool is_global = context->IsGlobalContext(); |
3391 Counters::eval_cache_misses.Increment(); | 3387 Handle<JSFunction> boilerplate = |
3392 boilerplate = Compiler::CompileEval(is_global_context, source); | 3388 Compiler::CompileEval(is_global, source); |
3393 if (boilerplate.is_null()) return Failure::Exception(); | 3389 if (boilerplate.is_null()) return Failure::Exception(); |
3394 | |
3395 Object* obj = | |
3396 Heap::PutInEvalCache(is_global_context, *source, *boilerplate); | |
3397 if (obj->IsFailure()) return obj; | |
3398 | |
3399 } else { | |
3400 Counters::eval_cache_hits.Increment(); | |
3401 boilerplate = Handle<JSFunction>(JSFunction::cast(obj)); | |
3402 } | |
3403 | |
3404 Handle<JSFunction> fun = | 3390 Handle<JSFunction> fun = |
3405 Factory::NewFunctionFromBoilerplate(boilerplate, context); | 3391 Factory::NewFunctionFromBoilerplate(boilerplate, context); |
3406 return *fun; | 3392 return *fun; |
3407 } | 3393 } |
3408 | 3394 |
3409 | 3395 |
3410 static Object* Runtime_CompileScript(Arguments args) { | 3396 static Object* Runtime_CompileScript(Arguments args) { |
3411 HandleScope scope; | 3397 HandleScope scope; |
3412 ASSERT(args.length() == 4); | 3398 ASSERT(args.length() == 4); |
3413 | 3399 |
(...skipping 1578 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4992 | 4978 |
4993 void Runtime::PerformGC(Object* result) { | 4979 void Runtime::PerformGC(Object* result) { |
4994 Failure* failure = Failure::cast(result); | 4980 Failure* failure = Failure::cast(result); |
4995 // Try to do a garbage collection; ignore it if it fails. The C | 4981 // Try to do a garbage collection; ignore it if it fails. The C |
4996 // entry stub will throw an out-of-memory exception in that case. | 4982 // entry stub will throw an out-of-memory exception in that case. |
4997 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); | 4983 Heap::CollectGarbage(failure->requested(), failure->allocation_space()); |
4998 } | 4984 } |
4999 | 4985 |
5000 | 4986 |
5001 } } // namespace v8::internal | 4987 } } // namespace v8::internal |
OLD | NEW |