Index: src/compiler.cc |
diff --git a/src/compiler.cc b/src/compiler.cc |
index 67b8ab9aa0680324fcd41246aae0d934a44b6be8..ea65bce9d6f914b829226e9af7d9893081777a37 100644 |
--- a/src/compiler.cc |
+++ b/src/compiler.cc |
@@ -1760,6 +1760,52 @@ Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( |
return shared; |
} |
+namespace { |
+ |
+bool CodeGenerationFromStringsAllowed(Isolate* isolate, |
+ Handle<Context> context) { |
+ DCHECK(context->allow_code_gen_from_strings()->IsFalse(isolate)); |
+ // Check with callback if set. |
+ AllowCodeGenerationFromStringsCallback callback = |
+ isolate->allow_code_gen_callback(); |
+ if (callback == NULL) { |
+ // No callback set and code generation disallowed. |
+ return false; |
+ } else { |
+ // Callback set. Let it decide if code generation is allowed. |
+ VMState<EXTERNAL> state(isolate); |
+ return callback(v8::Utils::ToLocal(context)); |
+ } |
+} |
+ |
+} // namespace |
+ |
+MaybeHandle<JSFunction> Compiler::CompileString(Handle<Context> context, |
Michael Starzinger
2016/07/20 12:03:35
Likewise, please move this to after GetFunctionFro
jgruber
2016/07/20 12:42:11
Done.
|
+ Handle<String> source, |
+ ParseRestriction restriction) { |
+ Isolate* const isolate = context->GetIsolate(); |
+ Handle<Context> native_context(context->native_context(), isolate); |
+ |
+ // Check if native context allows code generation from |
+ // strings. Throw an exception if it doesn't. |
+ if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) && |
+ !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
+ Handle<Object> error_message = |
+ native_context->ErrorMessageForCodeGenerationFromStrings(); |
+ THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings, |
+ error_message), |
+ JSFunction); |
+ } |
+ |
+ // Compile source string in the native context. |
+ int eval_scope_position = 0; |
+ int eval_position = kNoSourcePosition; |
+ Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); |
+ return Compiler::GetFunctionFromEval(source, outer_info, native_context, |
+ SLOPPY, restriction, eval_scope_position, |
+ eval_position); |
+} |
+ |
MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, |
BailoutId osr_ast_id, |
JavaScriptFrame* osr_frame) { |