Line data Source code
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
3 : // found in the LICENSE file.
4 :
5 : #include "src/parsing/parsing.h"
6 :
7 : #include <memory>
8 :
9 : #include "src/ast/ast.h"
10 : #include "src/objects-inl.h"
11 : #include "src/parsing/parse-info.h"
12 : #include "src/parsing/parser.h"
13 :
14 : namespace v8 {
15 : namespace internal {
16 : namespace parsing {
17 :
18 4526695 : bool ParseProgram(ParseInfo* info, Isolate* isolate, bool internalize) {
19 : DCHECK(info->is_toplevel());
20 : DCHECK_NULL(info->literal());
21 :
22 2263340 : Parser parser(info);
23 :
24 : FunctionLiteral* result = nullptr;
25 : // Ok to use Isolate here; this function is only called in the main thread.
26 : DCHECK(parser.parsing_on_main_thread_);
27 :
28 2263354 : parser.SetCachedData(info);
29 2263353 : result = parser.ParseProgram(isolate, info);
30 : info->set_literal(result);
31 2263351 : if (result == nullptr) {
32 379652 : parser.ReportErrors(isolate, info->script());
33 : } else {
34 1883699 : info->set_language_mode(info->literal()->language_mode());
35 : }
36 2263353 : parser.UpdateStatistics(isolate, info->script());
37 2263355 : if (internalize) {
38 2263355 : info->ast_value_factory()->Internalize(isolate);
39 : }
40 2263354 : return (result != nullptr);
41 : }
42 :
43 2608437 : bool ParseFunction(ParseInfo* info, Isolate* isolate, bool internalize) {
44 : DCHECK(!info->is_toplevel());
45 : DCHECK_NULL(info->literal());
46 :
47 1304218 : Parser parser(info);
48 :
49 : FunctionLiteral* result = nullptr;
50 : // Ok to use Isolate here; this function is only called in the main thread.
51 : DCHECK(parser.parsing_on_main_thread_);
52 :
53 1304219 : result = parser.ParseFunction(isolate, info);
54 : info->set_literal(result);
55 1304219 : if (result == nullptr) {
56 6628 : parser.ReportErrors(isolate, info->script());
57 : }
58 1304219 : parser.UpdateStatistics(isolate, info->script());
59 1304219 : if (internalize) {
60 1304219 : info->ast_value_factory()->Internalize(isolate);
61 : }
62 1304219 : return (result != nullptr);
63 : }
64 :
65 1504168 : bool ParseAny(ParseInfo* info, Isolate* isolate, bool internalize) {
66 209707 : return info->is_toplevel() ? ParseProgram(info, isolate, internalize)
67 1713875 : : ParseFunction(info, isolate, internalize);
68 : }
69 :
70 : } // namespace parsing
71 : } // namespace internal
72 : } // namespace v8
|