OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 8939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8950 } else { | 8950 } else { |
8951 // Callback set. Let it decide if code generation is allowed. | 8951 // Callback set. Let it decide if code generation is allowed. |
8952 VMState state(isolate, EXTERNAL); | 8952 VMState state(isolate, EXTERNAL); |
8953 return callback(v8::Utils::ToLocal(context)); | 8953 return callback(v8::Utils::ToLocal(context)); |
8954 } | 8954 } |
8955 } | 8955 } |
8956 | 8956 |
8957 | 8957 |
8958 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { | 8958 RUNTIME_FUNCTION(MaybeObject*, Runtime_CompileString) { |
8959 HandleScope scope(isolate); | 8959 HandleScope scope(isolate); |
8960 ASSERT_EQ(1, args.length()); | 8960 ASSERT_EQ(2, args.length()); |
8961 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); | 8961 CONVERT_ARG_HANDLE_CHECKED(String, source, 0); |
| 8962 CONVERT_BOOLEAN_ARG_CHECKED(function_literal_only, 1); |
8962 | 8963 |
8963 // Extract native context. | 8964 // Extract native context. |
8964 Handle<Context> context(isolate->context()->native_context()); | 8965 Handle<Context> context(isolate->context()->native_context()); |
8965 | 8966 |
8966 // Check if native context allows code generation from | 8967 // Check if native context allows code generation from |
8967 // strings. Throw an exception if it doesn't. | 8968 // strings. Throw an exception if it doesn't. |
8968 if (context->allow_code_gen_from_strings()->IsFalse() && | 8969 if (context->allow_code_gen_from_strings()->IsFalse() && |
8969 !CodeGenerationFromStringsAllowed(isolate, context)) { | 8970 !CodeGenerationFromStringsAllowed(isolate, context)) { |
8970 Handle<Object> error_message = | 8971 Handle<Object> error_message = |
8971 context->ErrorMessageForCodeGenerationFromStrings(); | 8972 context->ErrorMessageForCodeGenerationFromStrings(); |
8972 return isolate->Throw(*isolate->factory()->NewEvalError( | 8973 return isolate->Throw(*isolate->factory()->NewEvalError( |
8973 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); | 8974 "code_gen_from_strings", HandleVector<Object>(&error_message, 1))); |
8974 } | 8975 } |
8975 | 8976 |
8976 // Compile source string in the native context. | 8977 // Compile source string in the native context. |
| 8978 ParseRestriction restriction = function_literal_only |
| 8979 ? ONLY_SINGLE_FUNCTION_LITERAL : NO_PARSE_RESTRICTION; |
8977 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 8980 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
8978 source, context, true, CLASSIC_MODE, RelocInfo::kNoPosition); | 8981 source, context, true, CLASSIC_MODE, restriction, RelocInfo::kNoPosition); |
8979 if (shared.is_null()) return Failure::Exception(); | 8982 if (shared.is_null()) return Failure::Exception(); |
8980 Handle<JSFunction> fun = | 8983 Handle<JSFunction> fun = |
8981 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 8984 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
8982 context, | 8985 context, |
8983 NOT_TENURED); | 8986 NOT_TENURED); |
8984 return *fun; | 8987 return *fun; |
8985 } | 8988 } |
8986 | 8989 |
8987 | 8990 |
8988 static ObjectPair CompileGlobalEval(Isolate* isolate, | 8991 static ObjectPair CompileGlobalEval(Isolate* isolate, |
(...skipping 15 matching lines...) Expand all Loading... |
9004 return MakePair(Failure::Exception(), NULL); | 9007 return MakePair(Failure::Exception(), NULL); |
9005 } | 9008 } |
9006 | 9009 |
9007 // Deal with a normal eval call with a string argument. Compile it | 9010 // Deal with a normal eval call with a string argument. Compile it |
9008 // and return the compiled function bound in the local context. | 9011 // and return the compiled function bound in the local context. |
9009 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( | 9012 Handle<SharedFunctionInfo> shared = Compiler::CompileEval( |
9010 source, | 9013 source, |
9011 Handle<Context>(isolate->context()), | 9014 Handle<Context>(isolate->context()), |
9012 context->IsNativeContext(), | 9015 context->IsNativeContext(), |
9013 language_mode, | 9016 language_mode, |
| 9017 NO_PARSE_RESTRICTION, |
9014 scope_position); | 9018 scope_position); |
9015 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); | 9019 if (shared.is_null()) return MakePair(Failure::Exception(), NULL); |
9016 Handle<JSFunction> compiled = | 9020 Handle<JSFunction> compiled = |
9017 isolate->factory()->NewFunctionFromSharedFunctionInfo( | 9021 isolate->factory()->NewFunctionFromSharedFunctionInfo( |
9018 shared, context, NOT_TENURED); | 9022 shared, context, NOT_TENURED); |
9019 return MakePair(*compiled, *receiver); | 9023 return MakePair(*compiled, *receiver); |
9020 } | 9024 } |
9021 | 9025 |
9022 | 9026 |
9023 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { | 9027 RUNTIME_FUNCTION(ObjectPair, Runtime_ResolvePossiblyDirectEval) { |
(...skipping 2972 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11996 isolate->factory()->NewStringFromAscii( | 12000 isolate->factory()->NewStringFromAscii( |
11997 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); | 12001 Vector<const char>(kSourceStr, sizeof(kSourceStr) - 1)); |
11998 | 12002 |
11999 // Currently, the eval code will be executed in non-strict mode, | 12003 // Currently, the eval code will be executed in non-strict mode, |
12000 // even in the strict code context. | 12004 // even in the strict code context. |
12001 Handle<SharedFunctionInfo> shared = | 12005 Handle<SharedFunctionInfo> shared = |
12002 Compiler::CompileEval(function_source, | 12006 Compiler::CompileEval(function_source, |
12003 context, | 12007 context, |
12004 context->IsNativeContext(), | 12008 context->IsNativeContext(), |
12005 CLASSIC_MODE, | 12009 CLASSIC_MODE, |
| 12010 NO_PARSE_RESTRICTION, |
12006 RelocInfo::kNoPosition); | 12011 RelocInfo::kNoPosition); |
12007 if (shared.is_null()) return Failure::Exception(); | 12012 if (shared.is_null()) return Failure::Exception(); |
12008 Handle<JSFunction> compiled_function = | 12013 Handle<JSFunction> compiled_function = |
12009 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); | 12014 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, context); |
12010 | 12015 |
12011 // Invoke the result of the compilation to get the evaluation function. | 12016 // Invoke the result of the compilation to get the evaluation function. |
12012 bool has_pending_exception; | 12017 bool has_pending_exception; |
12013 Handle<Object> receiver(frame->receiver(), isolate); | 12018 Handle<Object> receiver(frame->receiver(), isolate); |
12014 Handle<Object> evaluation_function = | 12019 Handle<Object> evaluation_function = |
12015 Execution::Call(compiled_function, receiver, 0, NULL, | 12020 Execution::Call(compiled_function, receiver, 0, NULL, |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12102 } | 12107 } |
12103 | 12108 |
12104 // Compile the source to be evaluated. | 12109 // Compile the source to be evaluated. |
12105 // Currently, the eval code will be executed in non-strict mode, | 12110 // Currently, the eval code will be executed in non-strict mode, |
12106 // even in the strict code context. | 12111 // even in the strict code context. |
12107 Handle<SharedFunctionInfo> shared = | 12112 Handle<SharedFunctionInfo> shared = |
12108 Compiler::CompileEval(source, | 12113 Compiler::CompileEval(source, |
12109 context, | 12114 context, |
12110 is_global, | 12115 is_global, |
12111 CLASSIC_MODE, | 12116 CLASSIC_MODE, |
| 12117 NO_PARSE_RESTRICTION, |
12112 RelocInfo::kNoPosition); | 12118 RelocInfo::kNoPosition); |
12113 if (shared.is_null()) return Failure::Exception(); | 12119 if (shared.is_null()) return Failure::Exception(); |
12114 Handle<JSFunction> compiled_function = | 12120 Handle<JSFunction> compiled_function = |
12115 Handle<JSFunction>( | 12121 Handle<JSFunction>( |
12116 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, | 12122 isolate->factory()->NewFunctionFromSharedFunctionInfo(shared, |
12117 context)); | 12123 context)); |
12118 | 12124 |
12119 // Invoke the result of the compilation to get the evaluation function. | 12125 // Invoke the result of the compilation to get the evaluation function. |
12120 bool has_pending_exception; | 12126 bool has_pending_exception; |
12121 Handle<Object> receiver = isolate->global_object(); | 12127 Handle<Object> receiver = isolate->global_object(); |
(...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13345 // Handle last resort GC and make sure to allow future allocations | 13351 // Handle last resort GC and make sure to allow future allocations |
13346 // to grow the heap without causing GCs (if possible). | 13352 // to grow the heap without causing GCs (if possible). |
13347 isolate->counters()->gc_last_resort_from_js()->Increment(); | 13353 isolate->counters()->gc_last_resort_from_js()->Increment(); |
13348 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, | 13354 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, |
13349 "Runtime::PerformGC"); | 13355 "Runtime::PerformGC"); |
13350 } | 13356 } |
13351 } | 13357 } |
13352 | 13358 |
13353 | 13359 |
13354 } } // namespace v8::internal | 13360 } } // namespace v8::internal |
OLD | NEW |