| 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 9454 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9465 Handle<Context> context(isolate->context()->global_context()); | 9465 Handle<Context> context(isolate->context()->global_context()); |
| 9466 | 9466 |
| 9467 // Check if global context allows code generation from | 9467 // Check if global context allows code generation from |
| 9468 // strings. Throw an exception if it doesn't. | 9468 // strings. Throw an exception if it doesn't. |
| 9469 if (!CodeGenerationFromStringsAllowed(isolate, context)) { | 9469 if (!CodeGenerationFromStringsAllowed(isolate, context)) { |
| 9470 return isolate->Throw(*isolate->factory()->NewError( | 9470 return isolate->Throw(*isolate->factory()->NewError( |
| 9471 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); | 9471 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); |
| 9472 } | 9472 } |
| 9473 | 9473 |
| 9474 // Compile source string in the global context. | 9474 // Compile source string in the global context. |
| 9475 Handle<SharedFunctionInfo> shared = Compiler::CompileEval(source, | 9475 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
| 9476 context, | 9476 source, context, true, kNonStrictMode, RelocInfo::kNoPosition); |
| 9477 true, | |
| 9478 kNonStrictMode); | |
| 9479 if (shared.is_null()) return Failure::Exception(); | 9477 if (shared.is_null()) return Failure::Exception(); |
| 9480 Handle<JSFunction> fun = | 9478 Handle<JSFunction> fun = |
| 9481 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 9479 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
| 9482 context, | 9480 context, |
| 9483 NOT_TENURED); | 9481 NOT_TENURED); |
| 9484 return *fun; | 9482 return *fun; |
| 9485 } | 9483 } |
| 9486 | 9484 |
| 9487 | 9485 |
| 9488 static ObjectPair CompileGlobalEval(Isolate* isolate, | 9486 static ObjectPair CompileGlobalEval(Isolate* isolate, |
| 9489 Handle<String> source, | 9487 Handle<String> source, |
| 9490 Handle<Object> receiver, | 9488 Handle<Object> receiver, |
| 9491 StrictModeFlag strict_mode) { | 9489 StrictModeFlag strict_mode, |
| 9490 int scope_position) { |
| 9492 Handle<Context> context = Handle<Context>(isolate->context()); | 9491 Handle<Context> context = Handle<Context>(isolate->context()); |
| 9493 Handle<Context> global_context = Handle<Context>(context->global_context()); | 9492 Handle<Context> global_context = Handle<Context>(context->global_context()); |
| 9494 | 9493 |
| 9495 // Check if global context allows code generation from | 9494 // Check if global context allows code generation from |
| 9496 // strings. Throw an exception if it doesn't. | 9495 // strings. Throw an exception if it doesn't. |
| 9497 if (!CodeGenerationFromStringsAllowed(isolate, global_context)) { | 9496 if (!CodeGenerationFromStringsAllowed(isolate, global_context)) { |
| 9498 isolate->Throw(*isolate->factory()->NewError( | 9497 isolate->Throw(*isolate->factory()->NewError( |
| 9499 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); | 9498 "code_gen_from_strings", HandleVector<Object>(NULL, 0))); |
| 9500 return MakePair(Failure::Exception(), NULL); | 9499 return MakePair(Failure::Exception(), NULL); |
| 9501 } | 9500 } |
| 9502 | 9501 |
| 9503 // Deal with a normal eval call with a string argument. Compile it | 9502 // Deal with a normal eval call with a string argument. Compile it |
| 9504 // and return the compiled function bound in the local context. | 9503 // and return the compiled function bound in the local context. |
| 9505 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 9504 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
| 9506 source, | 9505 source, |
| 9507 Handle<Context>(isolate->context()), | 9506 Handle<Context>(isolate->context()), |
| 9508 context->IsGlobalContext(), | 9507 context->IsGlobalContext(), |
| 9509 strict_mode); | 9508 strict_mode, |
| 9509 scope_position); |
| 9510 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); | 9510 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); |
| 9511 Handle<JSFunction> compiled = | 9511 Handle<JSFunction> compiled = |
| 9512 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 9512 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
| 9513 shared, context, NOT_TENURED); | 9513 shared, context, NOT_TENURED); |
| 9514 return MakePair(*compiled, *receiver); | 9514 return MakePair(*compiled, *receiver); |
| 9515 } | 9515 } |
| 9516 | 9516 |
| 9517 | 9517 |
| 9518 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { | 9518 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { |
| 9519 ASSERT(args.length() == 4); | 9519 ASSERT(args.length() == 5); |
| 9520 | 9520 |
| 9521 HandleScope scope(isolate); | 9521 HandleScope scope(isolate); |
| 9522 Handle<Object> callee = args.at<Object>(0); | 9522 Handle<Object> callee = args.at<Object>(0); |
| 9523 | 9523 |
| 9524 // If "eval" didn't refer to the original GlobalEval, it's not a | 9524 // If "eval" didn't refer to the original GlobalEval, it's not a |
| 9525 // direct call to eval. | 9525 // direct call to eval. |
| 9526 // (And even if it is, but the first argument isn't a string, just let | 9526 // (And even if it is, but the first argument isn't a string, just let |
| 9527 // execution default to an indirect call to eval, which will also return | 9527 // execution default to an indirect call to eval, which will also return |
| 9528 // the first argument without doing anything). | 9528 // the first argument without doing anything). |
| 9529 if (*callee != isolate->global_context()->global_eval_fun() || | 9529 if (*callee != isolate->global_context()->global_eval_fun() || |
| 9530 !args[1]->IsString()) { | 9530 !args[1]->IsString()) { |
| 9531 return MakePair(*callee, isolate->heap()->the_hole_value()); | 9531 return MakePair(*callee, isolate->heap()->the_hole_value()); |
| 9532 } | 9532 } |
| 9533 | 9533 |
| 9534 CONVERT_STRICT_MODE_ARG(strict_mode, 3); | 9534 CONVERT_STRICT_MODE_ARG(strict_mode, 3); |
| 9535 ASSERT(args[4]->IsSmi()); |
| 9535 return CompileGlobalEval(isolate, | 9536 return CompileGlobalEval(isolate, |
| 9536 args.at<String>(1), | 9537 args.at<String>(1), |
| 9537 args.at<Object>(2), | 9538 args.at<Object>(2), |
| 9538 strict_mode); | 9539 strict_mode, |
| 9540 args.smi_at(4)); |
| 9539 } | 9541 } |
| 9540 | 9542 |
| 9541 | 9543 |
| 9542 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetNewFunctionAttributes) { | 9544 RUNTIME_FUNCTION(MaybeObject*, Runtime_SetNewFunctionAttributes) { |
| 9543 // This utility adjusts the property attributes for newly created Function | 9545 // This utility adjusts the property attributes for newly created Function |
| 9544 // object ("new Function(...)") by changing the map. | 9546 // object ("new Function(...)") by changing the map. |
| 9545 // All it does is changing the prototype property to enumerable | 9547 // All it does is changing the prototype property to enumerable |
| 9546 // as specified in ECMA262, 15.3.5.2. | 9548 // as specified in ECMA262, 15.3.5.2. |
| 9547 HandleScope scope(isolate); | 9549 HandleScope scope(isolate); |
| 9548 ASSERT(args.length() == 1); | 9550 ASSERT(args.length() == 1); |
| (...skipping 2593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12142 Handle<String> function_source = | 12144 Handle<String> function_source = |
| 12143 isolate->factory()->NewStringFromAscii( | 12145 isolate->factory()->NewStringFromAscii( |
| 12144 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); | 12146 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); |
| 12145 | 12147 |
| 12146 // Currently, the eval code will be executed in non-strict mode, | 12148 // Currently, the eval code will be executed in non-strict mode, |
| 12147 // even in the strict code context. | 12149 // even in the strict code context. |
| 12148 Handle<SharedFunctionInfo> shared = | 12150 Handle<SharedFunctionInfo> shared = |
| 12149 Compiler::CompileEval(function_source, | 12151 Compiler::CompileEval(function_source, |
| 12150 context, | 12152 context, |
| 12151 context->IsGlobalContext(), | 12153 context->IsGlobalContext(), |
| 12152 kNonStrictMode); | 12154 kNonStrictMode, |
| 12155 RelocInfo::kNoPosition); |
| 12153 if (shared.is_null()) return Failure::Exception(); | 12156 if (shared.is_null()) return Failure::Exception(); |
| 12154 Handle<JSFunction> compiled_function = | 12157 Handle<JSFunction> compiled_function = |
| 12155 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); | 12158 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); |
| 12156 | 12159 |
| 12157 // Invoke the result of the compilation to get the evaluation function. | 12160 // Invoke the result of the compilation to get the evaluation function. |
| 12158 bool has_pending_exception; | 12161 bool has_pending_exception; |
| 12159 Handle<Object> receiver(frame->receiver(), isolate); | 12162 Handle<Object> receiver(frame->receiver(), isolate); |
| 12160 Handle<Object> evaluation_function = | 12163 Handle<Object> evaluation_function = |
| 12161 Execution::Call(compiled_function, receiver, 0, NULL, | 12164 Execution::Call(compiled_function, receiver, 0, NULL, |
| 12162 &has_pending_exception); | 12165 &has_pending_exception); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 12235 isolate->factory()->NewFunctionContext( | 12238 isolate->factory()->NewFunctionContext( |
| 12236 Context::MIN_CONTEXT_SLOTS, go_between); | 12239 Context::MIN_CONTEXT_SLOTS, go_between); |
| 12237 context->set_extension(JSObject::cast(*additional_context)); | 12240 context->set_extension(JSObject::cast(*additional_context)); |
| 12238 is_global = false; | 12241 is_global = false; |
| 12239 } | 12242 } |
| 12240 | 12243 |
| 12241 // Compile the source to be evaluated. | 12244 // Compile the source to be evaluated. |
| 12242 // Currently, the eval code will be executed in non-strict mode, | 12245 // Currently, the eval code will be executed in non-strict mode, |
| 12243 // even in the strict code context. | 12246 // even in the strict code context. |
| 12244 Handle<SharedFunctionInfo> shared = | 12247 Handle<SharedFunctionInfo> shared = |
| 12245 Compiler::CompileEval(source, context, is_global, kNonStrictMode); | 12248 Compiler::CompileEval(source, |
| 12249 context, |
| 12250 is_global, |
| 12251 kNonStrictMode, |
| 12252 RelocInfo::kNoPosition); |
| 12246 if (shared.is_null()) return Failure::Exception(); | 12253 if (shared.is_null()) return Failure::Exception(); |
| 12247 Handle<JSFunction> compiled_function = | 12254 Handle<JSFunction> compiled_function = |
| 12248 Handle<JSFunction>( | 12255 Handle<JSFunction>( |
| 12249 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 12256 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
| 12250 context)); | 12257 context)); |
| 12251 | 12258 |
| 12252 // Invoke the result of the compilation to get the evaluation function. | 12259 // Invoke the result of the compilation to get the evaluation function. |
| 12253 bool has_pending_exception; | 12260 bool has_pending_exception; |
| 12254 Handle<Object> receiver = isolate->global(); | 12261 Handle<Object> receiver = isolate->global(); |
| 12255 Handle<Object> result = | 12262 Handle<Object> result = |
| (...skipping 1315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 13571 } else { | 13578 } else { |
| 13572 // Handle last resort GC and make sure to allow future allocations | 13579 // Handle last resort GC and make sure to allow future allocations |
| 13573 // to grow the heap without causing GCs (if possible). | 13580 // to grow the heap without causing GCs (if possible). |
| 13574 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13581 isolate->counters()->gc_last_resort_from_js()->Increment(); |
| 13575 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); | 13582 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags); |
| 13576 } | 13583 } |
| 13577 } | 13584 } |
| 13578 | 13585 |
| 13579 | 13586 |
| 13580 } } // namespace v8::internal | 13587 } } // namespace v8::internal |
| OLD | NEW |