| Index: src/compiler.cc
|
| diff --git a/src/compiler.cc b/src/compiler.cc
|
| index 67b8ab9aa0680324fcd41246aae0d934a44b6be8..426752e4bffdab40c0bef8a0df58be1f20184a68 100644
|
| --- a/src/compiler.cc
|
| +++ b/src/compiler.cc
|
| @@ -1468,6 +1468,52 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
|
| return result;
|
| }
|
|
|
| +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::GetFunctionFromString(
|
| + Handle<Context> context, 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);
|
| +}
|
| +
|
| Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
|
| Handle<String> source, Handle<Object> script_name, int line_offset,
|
| int column_offset, ScriptOriginOptions resource_options,
|
|
|