Commit 2021b171 authored by Ross McIlroy's avatar Ross McIlroy Committed by Commit Bot

[Parsing] Don't report errors when collecting source positions

This requires a native context which might not be available when
collecting source positions, and errors are cleared in any case.

BUG=chromium:992063

Change-Id: Ie0b81f60debaaf9a7810a42f56de0c005a7fbe18
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1745338
Commit-Queue: Ross McIlroy <rmcilroy@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#63175}
parent 3bd4ac9d
......@@ -1218,7 +1218,7 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
// Parse and update ParseInfo with the results. Don't update parsing
// statistics since we've already parsed the code before.
if (!parsing::ParseAny(&parse_info, shared_info, isolate,
parsing::UpdateStatisticsMode::kNo)) {
parsing::ReportErrorsAndStatisticsMode::kNo)) {
// Parsing failed probably as a result of stack exhaustion.
bytecode->SetSourcePositionsFailedToCollect();
return FailWithPendingException(
......
......@@ -166,10 +166,10 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
friend class i::ParameterDeclarationParsingScope<ParserTypes<Parser>>;
friend class i::ArrowHeadParsingScope<ParserTypes<Parser>>;
friend bool v8::internal::parsing::ParseProgram(
ParseInfo*, Isolate*, parsing::UpdateStatisticsMode stats_mode);
ParseInfo*, Isolate*, parsing::ReportErrorsAndStatisticsMode stats_mode);
friend bool v8::internal::parsing::ParseFunction(
ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*,
parsing::UpdateStatisticsMode stats_mode);
parsing::ReportErrorsAndStatisticsMode stats_mode);
bool AllowsLazyParsingWithoutUnresolvedVariables() const {
return scope()->AllowsLazyParsingWithoutUnresolvedVariables(
......
......@@ -19,7 +19,7 @@ namespace internal {
namespace parsing {
bool ParseProgram(ParseInfo* info, Isolate* isolate,
UpdateStatisticsMode stats_mode) {
ReportErrorsAndStatisticsMode mode) {
DCHECK(info->is_toplevel());
DCHECK_NULL(info->literal());
......@@ -40,23 +40,25 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate,
result = parser.ParseProgram(isolate, info);
info->set_literal(result);
if (result == nullptr) {
info->pending_error_handler()->ReportErrors(isolate, info->script(),
info->ast_value_factory());
} else {
if (result) {
info->set_language_mode(info->literal()->language_mode());
if (info->is_eval()) {
info->set_allow_eval_cache(parser.allow_eval_cache());
}
}
if (stats_mode == UpdateStatisticsMode::kYes) {
if (mode == ReportErrorsAndStatisticsMode::kYes) {
if (result == nullptr) {
info->pending_error_handler()->ReportErrors(isolate, info->script(),
info->ast_value_factory());
}
parser.UpdateStatistics(isolate, info->script());
}
return (result != nullptr);
}
bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate, UpdateStatisticsMode stats_mode) {
Isolate* isolate, ReportErrorsAndStatisticsMode mode) {
DCHECK(!info->is_toplevel());
DCHECK(!shared_info.is_null());
DCHECK_NULL(info->literal());
......@@ -79,27 +81,28 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
result = parser.ParseFunction(isolate, info, shared_info);
info->set_literal(result);
if (result == nullptr) {
info->pending_error_handler()->ReportErrors(isolate, info->script(),
info->ast_value_factory());
} else {
if (result) {
info->ast_value_factory()->Internalize(isolate);
if (info->is_eval()) {
info->set_allow_eval_cache(parser.allow_eval_cache());
}
}
if (stats_mode == UpdateStatisticsMode::kYes) {
if (mode == ReportErrorsAndStatisticsMode::kYes) {
if (result == nullptr) {
info->pending_error_handler()->ReportErrors(isolate, info->script(),
info->ast_value_factory());
}
parser.UpdateStatistics(isolate, info->script());
}
return (result != nullptr);
}
bool ParseAny(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate, UpdateStatisticsMode stats_mode) {
Isolate* isolate, ReportErrorsAndStatisticsMode mode) {
DCHECK(!shared_info.is_null());
return info->is_toplevel()
? ParseProgram(info, isolate, stats_mode)
: ParseFunction(info, shared_info, isolate, stats_mode);
return info->is_toplevel() ? ParseProgram(info, isolate, mode)
: ParseFunction(info, shared_info, isolate, mode);
}
} // namespace parsing
......
......@@ -15,27 +15,27 @@ class SharedFunctionInfo;
namespace parsing {
enum class UpdateStatisticsMode { kYes, kNo };
enum class ReportErrorsAndStatisticsMode { kYes, kNo };
// Parses the top-level source code represented by the parse info and sets its
// function literal. Returns false (and deallocates any allocated AST
// nodes) if parsing failed.
V8_EXPORT_PRIVATE bool ParseProgram(
ParseInfo* info, Isolate* isolate,
UpdateStatisticsMode stats_mode = UpdateStatisticsMode::kYes);
ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes);
// Like ParseProgram but for an individual function which already has a
// allocated shared function info.
V8_EXPORT_PRIVATE bool ParseFunction(
ParseInfo* info, Handle<SharedFunctionInfo> shared_info, Isolate* isolate,
UpdateStatisticsMode stats_mode = UpdateStatisticsMode::kYes);
ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes);
// If you don't know whether info->is_toplevel() is true or not, use this method
// to dispatch to either of the above functions. Prefer to use the above methods
// whenever possible.
V8_EXPORT_PRIVATE bool ParseAny(
ParseInfo* info, Handle<SharedFunctionInfo> shared_info, Isolate* isolate,
UpdateStatisticsMode stats_mode = UpdateStatisticsMode::kYes);
ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes);
} // namespace parsing
} // namespace internal
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment