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, bool internalize) { | 18 bool ParseProgram(ParseInfo* info) { |
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 if (result == nullptr) { | 32 parser.Internalize(isolate, info->script(), result == nullptr); |
33 parser.ReportErrors(isolate, info->script()); | 33 if (result != nullptr) { |
34 } else { | |
35 info->set_language_mode(info->literal()->language_mode()); | 34 info->set_language_mode(info->literal()->language_mode()); |
36 } | 35 } |
37 parser.UpdateStatistics(isolate, info->script()); | |
38 if (internalize) { | |
39 info->ast_value_factory()->Internalize(isolate); | |
40 } | |
41 return (result != nullptr); | 36 return (result != nullptr); |
42 } | 37 } |
43 | 38 |
44 bool ParseFunction(ParseInfo* info, bool internalize) { | 39 bool ParseFunction(ParseInfo* info) { |
45 DCHECK(!info->is_toplevel()); | 40 DCHECK(!info->is_toplevel()); |
46 DCHECK_NULL(info->literal()); | 41 DCHECK_NULL(info->literal()); |
47 | 42 |
48 Parser parser(info); | 43 Parser parser(info); |
49 | 44 |
50 FunctionLiteral* result = nullptr; | 45 FunctionLiteral* result = nullptr; |
51 // Ok to use Isolate here; this function is only called in the main thread. | 46 // Ok to use Isolate here; this function is only called in the main thread. |
52 DCHECK(parser.parsing_on_main_thread_); | 47 DCHECK(parser.parsing_on_main_thread_); |
53 Isolate* isolate = info->isolate(); | 48 Isolate* isolate = info->isolate(); |
54 | 49 |
55 result = parser.ParseFunction(isolate, info); | 50 result = parser.ParseFunction(isolate, info); |
56 info->set_literal(result); | 51 info->set_literal(result); |
57 if (result == nullptr) { | 52 parser.Internalize(isolate, info->script(), 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 } | |
64 return (result != nullptr); | 53 return (result != nullptr); |
65 } | 54 } |
66 | 55 |
67 bool ParseAny(ParseInfo* info, bool internalize) { | 56 bool ParseAny(ParseInfo* info) { |
68 return info->is_toplevel() ? ParseProgram(info, internalize) | 57 return info->is_toplevel() ? ParseProgram(info) : ParseFunction(info); |
69 : ParseFunction(info, internalize); | |
70 } | 58 } |
71 | 59 |
72 } // namespace parsing | 60 } // namespace parsing |
73 } // namespace internal | 61 } // namespace internal |
74 } // namespace v8 | 62 } // namespace v8 |
OLD | NEW |