OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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/parsing/parsing.h" | 5 #include "src/parsing/parsing.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "src/ast/ast.h" | 9 #include "src/ast/ast.h" |
10 #include "src/objects-inl.h" | 10 #include "src/objects-inl.h" |
11 #include "src/parsing/parse-info.h" | 11 #include "src/parsing/parse-info.h" |
12 #include "src/parsing/parser.h" | 12 #include "src/parsing/parser.h" |
13 | 13 |
14 namespace v8 { | 14 namespace v8 { |
15 namespace internal { | 15 namespace internal { |
16 namespace parsing { | 16 namespace parsing { |
17 | 17 |
18 bool ParseProgram(ParseInfo* info) { | 18 bool ParseProgram(ParseInfo* info, bool internalize) { |
19 DCHECK(info->is_toplevel()); | 19 DCHECK(info->is_toplevel()); |
20 DCHECK_NULL(info->literal()); | 20 DCHECK_NULL(info->literal()); |
21 | 21 |
22 Parser parser(info); | 22 Parser parser(info); |
23 | 23 |
24 FunctionLiteral* result = nullptr; | 24 FunctionLiteral* result = nullptr; |
25 // Ok to use Isolate here; this function is only called in the main thread. | 25 // Ok to use Isolate here; this function is only called in the main thread. |
26 DCHECK(parser.parsing_on_main_thread_); | 26 DCHECK(parser.parsing_on_main_thread_); |
27 Isolate* isolate = info->isolate(); | 27 Isolate* isolate = info->isolate(); |
28 | 28 |
29 parser.SetCachedData(info); | 29 parser.SetCachedData(info); |
30 result = parser.ParseProgram(isolate, info); | 30 result = parser.ParseProgram(isolate, info); |
31 info->set_literal(result); | 31 info->set_literal(result); |
32 parser.Internalize(isolate, info->script(), result == nullptr); | 32 if (result == nullptr) { |
33 if (result != nullptr) { | 33 parser.ReportErrors(isolate, info->script()); |
| 34 } else { |
34 info->set_language_mode(info->literal()->language_mode()); | 35 info->set_language_mode(info->literal()->language_mode()); |
35 } | 36 } |
| 37 parser.UpdateStatistics(isolate, info->script()); |
| 38 if (internalize) { |
| 39 info->ast_value_factory()->Internalize(isolate); |
| 40 } |
36 return (result != nullptr); | 41 return (result != nullptr); |
37 } | 42 } |
38 | 43 |
39 bool ParseFunction(ParseInfo* info) { | 44 bool ParseFunction(ParseInfo* info, bool internalize) { |
40 DCHECK(!info->is_toplevel()); | 45 DCHECK(!info->is_toplevel()); |
41 DCHECK_NULL(info->literal()); | 46 DCHECK_NULL(info->literal()); |
42 | 47 |
43 Parser parser(info); | 48 Parser parser(info); |
44 | 49 |
45 FunctionLiteral* result = nullptr; | 50 FunctionLiteral* result = nullptr; |
46 // Ok to use Isolate here; this function is only called in the main thread. | 51 // Ok to use Isolate here; this function is only called in the main thread. |
47 DCHECK(parser.parsing_on_main_thread_); | 52 DCHECK(parser.parsing_on_main_thread_); |
48 Isolate* isolate = info->isolate(); | 53 Isolate* isolate = info->isolate(); |
49 | 54 |
50 result = parser.ParseFunction(isolate, info); | 55 result = parser.ParseFunction(isolate, info); |
51 info->set_literal(result); | 56 info->set_literal(result); |
52 parser.Internalize(isolate, info->script(), result == nullptr); | 57 if (result == nullptr) { |
| 58 parser.ReportErrors(isolate, info->script()); |
| 59 } |
| 60 parser.UpdateStatistics(isolate, info->script()); |
| 61 if (internalize) { |
| 62 info->ast_value_factory()->Internalize(isolate); |
| 63 } |
53 return (result != nullptr); | 64 return (result != nullptr); |
54 } | 65 } |
55 | 66 |
56 bool ParseAny(ParseInfo* info) { | 67 bool ParseAny(ParseInfo* info, bool internalize) { |
57 return info->is_toplevel() ? ParseProgram(info) : ParseFunction(info); | 68 return info->is_toplevel() ? ParseProgram(info, internalize) |
| 69 : ParseFunction(info, internalize); |
58 } | 70 } |
59 | 71 |
60 } // namespace parsing | 72 } // namespace parsing |
61 } // namespace internal | 73 } // namespace internal |
62 } // namespace v8 | 74 } // namespace v8 |
OLD | NEW |