v8/src/parsing/parsing.cc
rmcilroy 0a9d4a3b0c Reland: [Compiler] Enable handles created during parsing and scope analysis to be deferred.
In order to compile eager inner functions on a background thread we need to
keep the handles created during parsing and scope analysis alive until the
background compilation is complete. In order to do that, we allocate the
handles in a deferred handle scope and keep the deferred handles alive with
a shared_ptr in the ParseInfo and CompileInfo respectively.

BUG=v8:5203

Review-Url: https://codereview.chromium.org/2650883002
Cr-Commit-Position: refs/heads/master@{#43107}
2017-02-10 15:01:29 +00:00

75 lines
2.0 KiB
C++

// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "src/parsing/parsing.h"
#include <memory>
#include "src/ast/ast.h"
#include "src/objects-inl.h"
#include "src/parsing/parse-info.h"
#include "src/parsing/parser.h"
namespace v8 {
namespace internal {
namespace parsing {
bool ParseProgram(ParseInfo* info, bool internalize) {
DCHECK(info->is_toplevel());
DCHECK_NULL(info->literal());
Parser parser(info);
FunctionLiteral* result = nullptr;
// Ok to use Isolate here; this function is only called in the main thread.
DCHECK(parser.parsing_on_main_thread_);
Isolate* isolate = info->isolate();
parser.SetCachedData(info);
result = parser.ParseProgram(isolate, info);
info->set_literal(result);
if (result == nullptr) {
parser.ReportErrors(isolate, info->script());
} else {
info->set_language_mode(info->literal()->language_mode());
}
parser.UpdateStatistics(isolate, info->script());
if (internalize) {
info->ast_value_factory()->Internalize(isolate);
}
return (result != nullptr);
}
bool ParseFunction(ParseInfo* info, bool internalize) {
DCHECK(!info->is_toplevel());
DCHECK_NULL(info->literal());
Parser parser(info);
FunctionLiteral* result = nullptr;
// Ok to use Isolate here; this function is only called in the main thread.
DCHECK(parser.parsing_on_main_thread_);
Isolate* isolate = info->isolate();
result = parser.ParseFunction(isolate, info);
info->set_literal(result);
if (result == nullptr) {
parser.ReportErrors(isolate, info->script());
}
parser.UpdateStatistics(isolate, info->script());
if (internalize) {
info->ast_value_factory()->Internalize(isolate);
}
return (result != nullptr);
}
bool ParseAny(ParseInfo* info, bool internalize) {
return info->is_toplevel() ? ParseProgram(info, internalize)
: ParseFunction(info, internalize);
}
} // namespace parsing
} // namespace internal
} // namespace v8