OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/compiler.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "src/asmjs/asm-js.h" | 9 #include "src/asmjs/asm-js.h" |
10 #include "src/asmjs/asm-typer.h" | 10 #include "src/asmjs/asm-typer.h" |
(...skipping 1450 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 shared_info, context, NOT_TENURED); | 1461 shared_info, context, NOT_TENURED); |
1462 | 1462 |
1463 // OnAfterCompile has to be called after we create the JSFunction, which we | 1463 // OnAfterCompile has to be called after we create the JSFunction, which we |
1464 // may require to recompile the eval for debugging, if we find a function | 1464 // may require to recompile the eval for debugging, if we find a function |
1465 // that contains break points in the eval script. | 1465 // that contains break points in the eval script. |
1466 isolate->debug()->OnAfterCompile(script); | 1466 isolate->debug()->OnAfterCompile(script); |
1467 | 1467 |
1468 return result; | 1468 return result; |
1469 } | 1469 } |
1470 | 1470 |
| 1471 namespace { |
| 1472 |
| 1473 bool CodeGenerationFromStringsAllowed(Isolate* isolate, |
| 1474 Handle<Context> context) { |
| 1475 DCHECK(context->allow_code_gen_from_strings()->IsFalse(isolate)); |
| 1476 // Check with callback if set. |
| 1477 AllowCodeGenerationFromStringsCallback callback = |
| 1478 isolate->allow_code_gen_callback(); |
| 1479 if (callback == NULL) { |
| 1480 // No callback set and code generation disallowed. |
| 1481 return false; |
| 1482 } else { |
| 1483 // Callback set. Let it decide if code generation is allowed. |
| 1484 VMState<EXTERNAL> state(isolate); |
| 1485 return callback(v8::Utils::ToLocal(context)); |
| 1486 } |
| 1487 } |
| 1488 |
| 1489 } // namespace |
| 1490 |
| 1491 MaybeHandle<JSFunction> Compiler::GetFunctionFromString( |
| 1492 Handle<Context> context, Handle<String> source, |
| 1493 ParseRestriction restriction) { |
| 1494 Isolate* const isolate = context->GetIsolate(); |
| 1495 Handle<Context> native_context(context->native_context(), isolate); |
| 1496 |
| 1497 // Check if native context allows code generation from |
| 1498 // strings. Throw an exception if it doesn't. |
| 1499 if (native_context->allow_code_gen_from_strings()->IsFalse(isolate) && |
| 1500 !CodeGenerationFromStringsAllowed(isolate, native_context)) { |
| 1501 Handle<Object> error_message = |
| 1502 native_context->ErrorMessageForCodeGenerationFromStrings(); |
| 1503 THROW_NEW_ERROR(isolate, NewEvalError(MessageTemplate::kCodeGenFromStrings, |
| 1504 error_message), |
| 1505 JSFunction); |
| 1506 } |
| 1507 |
| 1508 // Compile source string in the native context. |
| 1509 int eval_scope_position = 0; |
| 1510 int eval_position = kNoSourcePosition; |
| 1511 Handle<SharedFunctionInfo> outer_info(native_context->closure()->shared()); |
| 1512 return Compiler::GetFunctionFromEval(source, outer_info, native_context, |
| 1513 SLOPPY, restriction, eval_scope_position, |
| 1514 eval_position); |
| 1515 } |
| 1516 |
1471 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript( | 1517 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript( |
1472 Handle<String> source, Handle<Object> script_name, int line_offset, | 1518 Handle<String> source, Handle<Object> script_name, int line_offset, |
1473 int column_offset, ScriptOriginOptions resource_options, | 1519 int column_offset, ScriptOriginOptions resource_options, |
1474 Handle<Object> source_map_url, Handle<Context> context, | 1520 Handle<Object> source_map_url, Handle<Context> context, |
1475 v8::Extension* extension, ScriptData** cached_data, | 1521 v8::Extension* extension, ScriptData** cached_data, |
1476 ScriptCompiler::CompileOptions compile_options, NativesFlag natives, | 1522 ScriptCompiler::CompileOptions compile_options, NativesFlag natives, |
1477 bool is_module) { | 1523 bool is_module) { |
1478 Isolate* isolate = source->GetIsolate(); | 1524 Isolate* isolate = source->GetIsolate(); |
1479 if (compile_options == ScriptCompiler::kNoCompileOptions) { | 1525 if (compile_options == ScriptCompiler::kNoCompileOptions) { |
1480 cached_data = NULL; | 1526 cached_data = NULL; |
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1843 DCHECK(shared->is_compiled()); | 1889 DCHECK(shared->is_compiled()); |
1844 function->set_literals(cached.literals); | 1890 function->set_literals(cached.literals); |
1845 } else if (shared->is_compiled()) { | 1891 } else if (shared->is_compiled()) { |
1846 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1892 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
1847 JSFunction::EnsureLiterals(function); | 1893 JSFunction::EnsureLiterals(function); |
1848 } | 1894 } |
1849 } | 1895 } |
1850 | 1896 |
1851 } // namespace internal | 1897 } // namespace internal |
1852 } // namespace v8 | 1898 } // namespace v8 |
OLD | NEW |