Commit 7fcef442 authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[parser] Remove script handle from ParseInfo

Remove the explicit script handle from ParseInfo, and make it either
a Handle that is passed around where needed, or one inferred from the
SharedFunctionInfo.

This will be useful for compilation finalization using the off-thread
factory, which will not generate real Handles since it has no access
to the Isolate.

Bug: chromium:1011762
Change-Id: I5d9564009ec83bb9fc74191b4aa69735d132c2f7
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1977861Reviewed-by: 's avatarClemens Backes <clemensb@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Commit-Queue: Leszek Swirski <leszeks@chromium.org>
Cr-Commit-Position: refs/heads/master@{#65629}
parent 5d913223
......@@ -295,7 +295,7 @@ UnoptimizedCompilationJob::Status AsmJsCompilationJob::FinalizeJobImpl(
compilation_info()->SetAsmWasmData(result);
RecordHistograms(isolate);
ReportCompilationSuccess(parse_info()->script(),
ReportCompilationSuccess(handle(Script::cast(shared_info->script()), isolate),
compilation_info()->literal()->position(),
translate_time_, compile_time_, module_->size());
return SUCCEEDED;
......
This diff is collapsed.
......@@ -73,7 +73,8 @@ class V8_EXPORT_PRIVATE Compiler : public AllStatic {
Handle<SharedFunctionInfo> shared);
V8_WARN_UNUSED_RESULT static MaybeHandle<SharedFunctionInfo>
CompileForLiveEdit(ParseInfo* parse_info, Isolate* isolate);
CompileForLiveEdit(ParseInfo* parse_info, Handle<Script> script,
Isolate* isolate);
// Finalize and install code from previously run background compile task.
static bool FinalizeBackgroundCompileTask(
......
......@@ -512,10 +512,10 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
parse_info.set_allow_lazy_parsing();
parse_info.set_language_mode(
i::construct_language_mode(i::FLAG_use_strict));
parse_info.set_script(
parse_info.CreateScript(i_isolate, str, options.compile_options));
if (!i::parsing::ParseProgram(&parse_info, i_isolate)) {
i::Handle<i::Script> script =
parse_info.CreateScript(i_isolate, str, options.compile_options);
if (!i::parsing::ParseProgram(&parse_info, script, i_isolate)) {
fprintf(stderr, "Failed parsing\n");
return false;
}
......
......@@ -238,9 +238,9 @@ void ScopeIterator::TryParseAndRetrieveScopes(ReparseStrategy strategy) {
Handle<Script> script(Script::cast(shared_info->script()), isolate_);
if (scope_info->scope_type() == FUNCTION_SCOPE &&
strategy == ReparseStrategy::kFunctionLiteral) {
info_ = new ParseInfo(isolate_, shared_info);
info_ = new ParseInfo(isolate_, *shared_info);
} else {
info_ = new ParseInfo(isolate_, script);
info_ = new ParseInfo(isolate_, *script);
info_->set_eager();
}
......@@ -443,7 +443,6 @@ void ScopeIterator::Next() {
UnwrapEvaluationContext();
}
// Return the type of the current scope.
ScopeIterator::ScopeType ScopeIterator::Type() const {
DCHECK(!Done());
......
......@@ -747,18 +747,18 @@ class CollectFunctionLiterals final
std::vector<FunctionLiteral*>* literals_;
};
bool ParseScript(Isolate* isolate, ParseInfo* parse_info, bool compile_as_well,
std::vector<FunctionLiteral*>* literals,
bool ParseScript(Isolate* isolate, Handle<Script> script, ParseInfo* parse_info,
bool compile_as_well, std::vector<FunctionLiteral*>* literals,
debug::LiveEditResult* result) {
parse_info->set_eager();
v8::TryCatch try_catch(reinterpret_cast<v8::Isolate*>(isolate));
Handle<SharedFunctionInfo> shared;
bool success = false;
if (compile_as_well) {
success =
Compiler::CompileForLiveEdit(parse_info, isolate).ToHandle(&shared);
success = Compiler::CompileForLiveEdit(parse_info, script, isolate)
.ToHandle(&shared);
} else {
success = parsing::ParseProgram(parse_info, isolate);
success = parsing::ParseProgram(parse_info, script, isolate);
if (success) {
success = Compiler::Analyze(parse_info);
parse_info->ast_value_factory()->Internalize(isolate);
......@@ -1058,15 +1058,17 @@ void LiveEdit::PatchScript(Isolate* isolate, Handle<Script> script,
return;
}
ParseInfo parse_info(isolate, script);
ParseInfo parse_info(isolate, *script);
std::vector<FunctionLiteral*> literals;
if (!ParseScript(isolate, &parse_info, false, &literals, result)) return;
if (!ParseScript(isolate, script, &parse_info, false, &literals, result))
return;
Handle<Script> new_script = isolate->factory()->CloneScript(script);
new_script->set_source(*new_source);
std::vector<FunctionLiteral*> new_literals;
ParseInfo new_parse_info(isolate, new_script);
if (!ParseScript(isolate, &new_parse_info, true, &new_literals, result)) {
ParseInfo new_parse_info(isolate, *new_script);
if (!ParseScript(isolate, new_script, &new_parse_info, true, &new_literals,
result)) {
return;
}
......
......@@ -1228,7 +1228,7 @@ Handle<String> RenderCallSite(Isolate* isolate, Handle<Object> object,
MessageLocation* location,
CallPrinter::ErrorHint* hint) {
if (ComputeLocation(isolate, location)) {
ParseInfo info(isolate, location->shared());
ParseInfo info(isolate, *location->shared());
if (parsing::ParseAny(&info, location->shared(), isolate)) {
info.ast_value_factory()->Internalize(isolate);
CallPrinter printer(isolate, location->shared()->IsUserJavaScript());
......@@ -1329,7 +1329,7 @@ Object ErrorUtils::ThrowLoadFromNullOrUndefined(Isolate* isolate,
if (ComputeLocation(isolate, &location)) {
location_computed = true;
ParseInfo info(isolate, location.shared());
ParseInfo info(isolate, *location.shared());
if (parsing::ParseAny(&info, location.shared(), isolate)) {
info.ast_value_factory()->Internalize(isolate);
CallPrinter printer(isolate, location.shared()->IsUserJavaScript());
......
......@@ -43,7 +43,7 @@ class InterpreterCompilationJob final : public UnoptimizedCompilationJob {
private:
BytecodeGenerator* generator() { return &generator_; }
void CheckAndPrintBytecodeMismatch(Isolate* isolate,
void CheckAndPrintBytecodeMismatch(Isolate* isolate, Handle<Script> script,
Handle<BytecodeArray> bytecode);
Zone zone_;
......@@ -172,14 +172,14 @@ InterpreterCompilationJob::Status InterpreterCompilationJob::ExecuteJobImpl() {
#ifdef DEBUG
void InterpreterCompilationJob::CheckAndPrintBytecodeMismatch(
Isolate* isolate, Handle<BytecodeArray> bytecode) {
Isolate* isolate, Handle<Script> script, Handle<BytecodeArray> bytecode) {
int first_mismatch = generator()->CheckBytecodeMatches(bytecode);
if (first_mismatch >= 0) {
parse_info()->ast_value_factory()->Internalize(isolate);
DeclarationScope::AllocateScopeInfos(parse_info(), isolate);
Handle<BytecodeArray> new_bytecode =
generator()->FinalizeBytecode(isolate, parse_info()->script());
generator()->FinalizeBytecode(isolate, script);
std::cerr << "Bytecode mismatch";
#ifdef OBJECT_PRINT
......@@ -190,7 +190,7 @@ void InterpreterCompilationJob::CheckAndPrintBytecodeMismatch(
} else {
name->StringPrint(std::cerr);
}
Object script_name = parse_info()->script()->GetNameOrSourceURL();
Object script_name = script->GetNameOrSourceURL();
if (script_name.IsString()) {
std::cerr << " ";
String::cast(script_name).StringPrint(std::cerr);
......@@ -216,7 +216,8 @@ InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl(
Handle<BytecodeArray> bytecodes = compilation_info_.bytecode_array();
if (bytecodes.is_null()) {
bytecodes = generator()->FinalizeBytecode(isolate, parse_info()->script());
bytecodes = generator()->FinalizeBytecode(
isolate, handle(Script::cast(shared_info->script()), isolate));
if (generator()->HasStackOverflow()) {
return FAILED;
}
......@@ -241,7 +242,8 @@ InterpreterCompilationJob::Status InterpreterCompilationJob::FinalizeJobImpl(
}
#ifdef DEBUG
CheckAndPrintBytecodeMismatch(isolate, bytecodes);
CheckAndPrintBytecodeMismatch(
isolate, handle(Script::cast(shared_info->script()), isolate), bytecodes);
#endif
return SUCCEEDED;
......
......@@ -85,45 +85,45 @@ void ParseInfo::SetFunctionInfo(T function) {
set_is_oneshot_iife(function->is_oneshot_iife());
}
ParseInfo::ParseInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared)
ParseInfo::ParseInfo(Isolate* isolate, SharedFunctionInfo shared)
: ParseInfo(isolate, isolate->allocator()) {
// Do not support re-parsing top-level function of a wrapped script.
// TODO(yangguo): consider whether we need a top-level function in a
// wrapped script at all.
DCHECK_IMPLIES(is_toplevel(), !Script::cast(shared->script()).is_wrapped());
DCHECK_IMPLIES(is_toplevel(), !Script::cast(shared.script()).is_wrapped());
set_allow_lazy_parsing(true);
set_asm_wasm_broken(shared->is_asm_wasm_broken());
set_asm_wasm_broken(shared.is_asm_wasm_broken());
set_start_position(shared->StartPosition());
set_end_position(shared->EndPosition());
function_literal_id_ = shared->function_literal_id();
SetFunctionInfo(shared);
set_start_position(shared.StartPosition());
set_end_position(shared.EndPosition());
function_literal_id_ = shared.function_literal_id();
SetFunctionInfo(&shared);
Handle<Script> script(Script::cast(shared->script()), isolate);
set_script(script);
Script script = Script::cast(shared.script());
SetFlagsFromScript(isolate, script);
if (shared->HasOuterScopeInfo()) {
set_outer_scope_info(handle(shared->GetOuterScopeInfo(), isolate));
if (shared.HasOuterScopeInfo()) {
set_outer_scope_info(handle(shared.GetOuterScopeInfo(), isolate));
}
set_repl_mode(shared->is_repl_mode());
set_repl_mode(shared.is_repl_mode());
// CollectTypeProfile uses its own feedback slots. If we have existing
// FeedbackMetadata, we can only collect type profile if the feedback vector
// has the appropriate slots.
set_collect_type_profile(
isolate->is_collecting_type_profile() &&
(shared->HasFeedbackMetadata()
? shared->feedback_metadata().HasTypeProfileSlot()
: script->IsUserJavaScript()));
(shared.HasFeedbackMetadata()
? shared.feedback_metadata().HasTypeProfileSlot()
: script.IsUserJavaScript()));
}
ParseInfo::ParseInfo(Isolate* isolate, Handle<Script> script)
ParseInfo::ParseInfo(Isolate* isolate, Script script)
: ParseInfo(isolate, isolate->allocator()) {
SetScriptForToplevelCompile(isolate, script);
SetFlagsForToplevelCompileFromScript(isolate, script);
set_collect_type_profile(isolate->is_collecting_type_profile() &&
script->IsUserJavaScript());
script.IsUserJavaScript());
}
// static
......@@ -192,7 +192,7 @@ Handle<Script> ParseInfo::CreateScript(Isolate* isolate, Handle<String> source,
script->set_origin_options(origin_options);
script->set_is_repl_mode(repl_mode == REPLMode::kYes);
SetScriptForToplevelCompile(isolate, script);
SetFlagsForToplevelCompileFromScript(isolate, *script);
return script;
}
......@@ -217,31 +217,35 @@ void ParseInfo::set_character_stream(
character_stream_.swap(character_stream);
}
void ParseInfo::SetScriptForToplevelCompile(Isolate* isolate,
Handle<Script> script) {
set_script(script);
void ParseInfo::SetFlagsForToplevelCompileFromScript(Isolate* isolate,
Script script) {
SetFlagsFromScript(isolate, script);
set_allow_lazy_parsing();
set_toplevel();
set_collect_type_profile(isolate->is_collecting_type_profile() &&
script->IsUserJavaScript());
set_repl_mode(script->is_repl_mode());
if (script->is_wrapped()) {
script.IsUserJavaScript());
set_repl_mode(script.is_repl_mode());
if (script.is_wrapped()) {
set_function_syntax_kind(FunctionSyntaxKind::kWrapped);
}
}
void ParseInfo::set_script(Handle<Script> script) {
script_ = script;
DCHECK(script_id_ == -1 || script_id_ == script->id());
script_id_ = script->id();
void ParseInfo::SetFlagsFromScript(Isolate* isolate, Script script) {
DCHECK(script_id_ == -1 || script_id_ == script.id());
script_id_ = script.id();
set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL);
set_module(script->origin_options().IsModule());
set_eval(script.compilation_type() == Script::COMPILATION_TYPE_EVAL);
set_module(script.origin_options().IsModule());
DCHECK(!(is_eval() && is_module()));
if (block_coverage_enabled() && script->IsUserJavaScript()) {
if (block_coverage_enabled() && script.IsUserJavaScript()) {
AllocateSourceRangeMap();
}
if (script.is_wrapped()) {
set_wrapped_arguments(handle(script.wrapped_arguments(), isolate));
}
}
void ParseInfo::ParallelTasks::Enqueue(ParseInfo* outer_parse_info,
......
......@@ -43,8 +43,8 @@ class V8_EXPORT_PRIVATE ParseInfo {
explicit ParseInfo(AccountingAllocator* zone_allocator);
explicit ParseInfo(Isolate*);
ParseInfo(Isolate*, AccountingAllocator* zone_allocator);
ParseInfo(Isolate* isolate, Handle<Script> script);
ParseInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared);
ParseInfo(Isolate* isolate, Script script);
ParseInfo(Isolate* isolate, SharedFunctionInfo shared);
// Creates a new parse info based on parent top-level |outer_parse_info| for
// function |literal|.
......@@ -256,11 +256,15 @@ class V8_EXPORT_PRIVATE ParseInfo {
ParallelTasks* parallel_tasks() { return parallel_tasks_.get(); }
void SetFlagsFromScript(Isolate* isolate, Script script);
//--------------------------------------------------------------------------
// TODO(titzer): these should not be part of ParseInfo.
//--------------------------------------------------------------------------
Handle<Script> script() const { return script_; }
void set_script(Handle<Script> script);
Handle<FixedArray> wrapped_arguments() const { return wrapped_arguments_; }
void set_wrapped_arguments(Handle<FixedArray> wrapped_arguments) {
wrapped_arguments_ = wrapped_arguments;
}
MaybeHandle<ScopeInfo> maybe_outer_scope_info() const {
return maybe_outer_scope_info_;
......@@ -281,7 +285,7 @@ class V8_EXPORT_PRIVATE ParseInfo {
}
private:
void SetScriptForToplevelCompile(Isolate* isolate, Handle<Script> script);
void SetFlagsForToplevelCompileFromScript(Isolate* isolate, Script script);
// Set function info flags based on those in either FunctionLiteral or
// SharedFunctionInfo |function|
......@@ -341,7 +345,7 @@ class V8_EXPORT_PRIVATE ParseInfo {
int max_function_literal_id_;
// TODO(titzer): Move handles out of ParseInfo.
Handle<Script> script_;
Handle<FixedArray> wrapped_arguments_;
MaybeHandle<ScopeInfo> maybe_outer_scope_info_;
//----------- Inputs+Outputs of parsing and scope analysis -----------------
......
......@@ -387,8 +387,7 @@ Parser::Parser(ParseInfo* info)
info->extension(), info->GetOrCreateAstValueFactory(),
info->pending_error_handler(),
info->runtime_call_stats(), info->logger(),
info->script().is_null() ? -1 : info->script()->id(),
info->is_module(), true),
info->script_id(), info->is_module(), true),
info_(info),
scanner_(info->character_stream(), info->is_module()),
preparser_zone_(info->zone()->allocator(), ZONE_NAME),
......@@ -484,9 +483,11 @@ void MaybeProcessSourceRanges(ParseInfo* parse_info, Expression* root,
} // namespace
FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
FunctionLiteral* Parser::ParseProgram(Isolate* isolate, Handle<Script> script,
ParseInfo* info) {
// TODO(bmeurer): We temporarily need to pass allow_nesting = true here,
// see comment for HistogramTimerScope class.
DCHECK_EQ(script->id(), script_id());
// It's OK to use the Isolate & counters here, since this function is only
// called in the main thread.
......@@ -509,20 +510,19 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
MaybeResetCharacterStream(info, result);
MaybeProcessSourceRanges(info, result, stack_limit_);
HandleSourceURLComments(isolate, info->script());
HandleSourceURLComments(isolate, script);
if (V8_UNLIKELY(FLAG_log_function_events) && result != nullptr) {
double ms = timer.Elapsed().InMillisecondsF();
const char* event_name = "parse-eval";
Script script = *info->script();
int start = -1;
int end = -1;
if (!info->is_eval()) {
event_name = "parse-script";
start = 0;
end = String::cast(script.source()).length();
end = String::cast(script->source()).length();
}
LOG(isolate, FunctionEvent(event_name, script.id(), ms, start, end, "", 0));
LOG(isolate, FunctionEvent(event_name, script_id(), ms, start, end, "", 0));
}
return result;
}
......@@ -610,6 +610,7 @@ FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
scanner()->set_parser_error();
}
} else if (info->is_wrapped_as_function()) {
DCHECK(parsing_on_main_thread_);
ParseWrapped(isolate, info, &body, scope, zone());
} else if (info->is_repl_mode()) {
ParseREPLProgram(info, &body, scope);
......@@ -674,7 +675,7 @@ ZonePtrList<const AstRawString>* Parser::PrepareWrappedArguments(
Isolate* isolate, ParseInfo* info, Zone* zone) {
DCHECK(parsing_on_main_thread_);
DCHECK_NOT_NULL(isolate);
Handle<FixedArray> arguments(info->script()->wrapped_arguments(), isolate);
Handle<FixedArray> arguments = info->wrapped_arguments();
int arguments_length = arguments->length();
ZonePtrList<const AstRawString>* arguments_for_wrapped_function =
new (zone) ZonePtrList<const AstRawString>(arguments_length, zone);
......@@ -689,7 +690,7 @@ ZonePtrList<const AstRawString>* Parser::PrepareWrappedArguments(
void Parser::ParseWrapped(Isolate* isolate, ParseInfo* info,
ScopedPtrList<Statement>* body,
DeclarationScope* outer_scope, Zone* zone) {
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
DCHECK(parsing_on_main_thread_);
DCHECK(info->is_wrapped_as_function());
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
......@@ -812,7 +813,7 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info,
DeclarationScope* function_scope = result->scope();
std::unique_ptr<char[]> function_name = result->GetDebugName();
LOG(isolate,
FunctionEvent("parse-function", info->script()->id(), ms,
FunctionEvent("parse-function", script_id(), ms,
function_scope->start_position(),
function_scope->end_position(), function_name.get(),
strlen(function_name.get())));
......
......@@ -167,7 +167,8 @@ 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::ReportErrorsAndStatisticsMode stats_mode);
ParseInfo*, Handle<Script>, Isolate*,
parsing::ReportErrorsAndStatisticsMode stats_mode);
friend bool v8::internal::parsing::ParseFunction(
ParseInfo*, Handle<SharedFunctionInfo> shared_info, Isolate*,
parsing::ReportErrorsAndStatisticsMode stats_mode);
......@@ -208,7 +209,8 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
void PrepareGeneratorVariables();
// Returns nullptr if parsing failed.
FunctionLiteral* ParseProgram(Isolate* isolate, ParseInfo* info);
FunctionLiteral* ParseProgram(Isolate* isolate, Handle<Script> script,
ParseInfo* info);
FunctionLiteral* ParseFunction(Isolate* isolate, ParseInfo* info,
Handle<SharedFunctionInfo> shared_info);
......
......@@ -18,7 +18,7 @@ namespace v8 {
namespace internal {
namespace parsing {
bool ParseProgram(ParseInfo* info, Isolate* isolate,
bool ParseProgram(ParseInfo* info, Handle<Script> script, Isolate* isolate,
ReportErrorsAndStatisticsMode mode) {
DCHECK(info->is_toplevel());
DCHECK_NULL(info->literal());
......@@ -26,7 +26,7 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate,
VMState<PARSER> state(isolate);
// Create a character stream for the parser.
Handle<String> source(String::cast(info->script()->source()), isolate);
Handle<String> source(String::cast(script->source()), isolate);
isolate->counters()->total_parse_size()->Increment(source->length());
std::unique_ptr<Utf16CharacterStream> stream(
ScannerStream::For(isolate, source));
......@@ -38,7 +38,7 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate,
// Ok to use Isolate here; this function is only called in the main thread.
DCHECK(parser.parsing_on_main_thread_);
result = parser.ParseProgram(isolate, info);
result = parser.ParseProgram(isolate, script, info);
info->set_literal(result);
if (result) {
info->set_language_mode(info->literal()->language_mode());
......@@ -49,10 +49,10 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate,
if (mode == ReportErrorsAndStatisticsMode::kYes) {
if (result == nullptr) {
info->pending_error_handler()->ReportErrors(isolate, info->script(),
info->pending_error_handler()->ReportErrors(isolate, script,
info->ast_value_factory());
}
parser.UpdateStatistics(isolate, info->script());
parser.UpdateStatistics(isolate, script);
}
return (result != nullptr);
}
......@@ -64,7 +64,8 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
DCHECK_NULL(info->literal());
// Create a character stream for the parser.
Handle<String> source(String::cast(info->script()->source()), isolate);
Handle<Script> script(Script::cast(shared_info->script()), isolate);
Handle<String> source(String::cast(script->source()), isolate);
isolate->counters()->total_parse_size()->Increment(source->length());
std::unique_ptr<Utf16CharacterStream> stream(
ScannerStream::For(isolate, source, shared_info->StartPosition(),
......@@ -90,10 +91,10 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
if (mode == ReportErrorsAndStatisticsMode::kYes) {
if (result == nullptr) {
info->pending_error_handler()->ReportErrors(isolate, info->script(),
info->pending_error_handler()->ReportErrors(isolate, script,
info->ast_value_factory());
}
parser.UpdateStatistics(isolate, info->script());
parser.UpdateStatistics(isolate, script);
}
return (result != nullptr);
}
......@@ -101,8 +102,11 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
bool ParseAny(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
Isolate* isolate, ReportErrorsAndStatisticsMode mode) {
DCHECK(!shared_info.is_null());
return info->is_toplevel() ? ParseProgram(info, isolate, mode)
: ParseFunction(info, shared_info, isolate, mode);
return info->is_toplevel()
? ParseProgram(
info, handle(Script::cast(shared_info->script()), isolate),
isolate, mode)
: ParseFunction(info, shared_info, isolate, mode);
}
} // namespace parsing
......
......@@ -21,7 +21,7 @@ enum class ReportErrorsAndStatisticsMode { kYes, kNo };
// function literal. Returns false (and deallocates any allocated AST
// nodes) if parsing failed.
V8_EXPORT_PRIVATE bool ParseProgram(
ParseInfo* info, Isolate* isolate,
ParseInfo* info, Handle<Script> script, Isolate* isolate,
ReportErrorsAndStatisticsMode mode = ReportErrorsAndStatisticsMode::kYes);
// Like ParseProgram but for an individual function which already has a
......
......@@ -708,7 +708,7 @@ TEST(PreParserScopeAnalysis) {
isolate);
// Parse the lazy function using the scope data.
i::ParseInfo using_scope_data(isolate, shared);
i::ParseInfo using_scope_data(isolate, *shared);
using_scope_data.set_lazy_compile();
using_scope_data.set_consumed_preparse_data(
i::ConsumedPreparseData::For(isolate, produced_data_on_heap));
......@@ -724,7 +724,7 @@ TEST(PreParserScopeAnalysis) {
CHECK(i::DeclarationScope::Analyze(&using_scope_data));
// Parse the lazy function again eagerly to produce baseline data.
i::ParseInfo not_using_scope_data(isolate, shared);
i::ParseInfo not_using_scope_data(isolate, *shared);
not_using_scope_data.set_lazy_compile();
CHECK(i::parsing::ParseFunction(&not_using_scope_data, shared, isolate));
......@@ -759,11 +759,11 @@ TEST(Regress753896) {
i::Handle<i::String> source = factory->InternalizeUtf8String(
"function lazy() { let v = 0; if (true) { var v = 0; } }");
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
// We don't assert that parsing succeeded or that it failed; currently the
// error is not detected inside lazy functions, but it might be in the future.
i::parsing::ParseProgram(&info, isolate);
i::parsing::ParseProgram(&info, script, isolate);
}
TEST(ProducingAndConsumingByteData) {
......
......@@ -1056,10 +1056,10 @@ TEST(ScopeUsesArgumentsSuperThis) {
factory->NewStringFromUtf8(i::CStrVector(program.begin()))
.ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
// The information we're checking is only produced when eager parsing.
info.set_allow_lazy_parsing(false);
CHECK(i::parsing::ParseProgram(&info, isolate));
CHECK(i::parsing::ParseProgram(&info, script, isolate));
CHECK(i::Rewriter::Rewrite(&info));
info.ast_value_factory()->Internalize(isolate);
CHECK(i::DeclarationScope::Analyze(&info));
......@@ -1121,11 +1121,11 @@ static void CheckParsesToNumber(const char* source) {
i::Handle<i::Script> script = factory->NewScript(source_code);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_allow_lazy_parsing(false);
info.set_toplevel(true);
CHECK(i::parsing::ParseProgram(&info, isolate));
CHECK(i::parsing::ParseProgram(&info, script, isolate));
CHECK_EQ(1, info.scope()->declarations()->LengthForTest());
i::Declaration* decl = info.scope()->declarations()->AtForTest(0);
......@@ -1431,9 +1431,9 @@ TEST(ScopePositions) {
.ToHandleChecked();
CHECK_EQ(source->length(), kProgramSize);
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_language_mode(source_data[i].language_mode);
i::parsing::ParseProgram(&info, isolate);
i::parsing::ParseProgram(&info, script, isolate);
CHECK_NOT_NULL(info.literal());
// Check scope types and positions.
......@@ -1477,8 +1477,8 @@ TEST(DiscardFunctionBody) {
i::Handle<i::String> source_code =
factory->NewStringFromUtf8(i::CStrVector(source)).ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source_code);
i::ParseInfo info(isolate, script);
i::parsing::ParseProgram(&info, isolate);
i::ParseInfo info(isolate, *script);
i::parsing::ParseProgram(&info, script, isolate);
function = info.literal();
CHECK_NOT_NULL(function);
CHECK_EQ(1, function->body()->length());
......@@ -1601,10 +1601,10 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
{
SetGlobalFlags(flags);
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_allow_lazy_parsing(flags.contains(kAllowLazy));
if (is_module) info.set_module();
i::parsing::ParseProgram(&info, isolate);
i::parsing::ParseProgram(&info, script, isolate);
function = info.literal();
}
......@@ -3519,7 +3519,7 @@ TEST(InnerAssignment) {
i::Handle<i::SharedFunctionInfo> shared =
i::handle(f->shared(), isolate);
info =
std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, shared));
std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, *shared));
CHECK(i::parsing::ParseFunction(info.get(), shared, isolate));
} else {
i::Handle<i::String> source =
......@@ -3528,9 +3528,9 @@ TEST(InnerAssignment) {
printf("\n");
i::Handle<i::Script> script = factory->NewScript(source);
info =
std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, script));
std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, *script));
info->set_allow_lazy_parsing(false);
CHECK(i::parsing::ParseProgram(info.get(), isolate));
CHECK(i::parsing::ParseProgram(info.get(), script, isolate));
}
CHECK(i::Compiler::Analyze(info.get()));
CHECK_NOT_NULL(info->literal());
......@@ -3636,7 +3636,7 @@ TEST(MaybeAssignedParameters) {
i::Handle<i::Object> o = v8::Utils::OpenHandle(*v);
i::Handle<i::JSFunction> f = i::Handle<i::JSFunction>::cast(o);
i::Handle<i::SharedFunctionInfo> shared = i::handle(f->shared(), isolate);
info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, shared));
info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, *shared));
info->set_allow_lazy_parsing(allow_lazy);
CHECK(i::parsing::ParseFunction(info.get(), shared, isolate));
CHECK(i::Compiler::Analyze(info.get()));
......@@ -3673,11 +3673,11 @@ static void TestMaybeAssigned(Input input, const char* variable, bool module,
i::Handle<i::Script> script = factory->NewScript(string);
std::unique_ptr<i::ParseInfo> info;
info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, script));
info = std::unique_ptr<i::ParseInfo>(new i::ParseInfo(isolate, *script));
info->set_module(module);
info->set_allow_lazy_parsing(allow_lazy_parsing);
CHECK(i::parsing::ParseProgram(info.get(), isolate));
CHECK(i::parsing::ParseProgram(info.get(), script, isolate));
CHECK(i::Compiler::Analyze(info.get()));
CHECK_NOT_NULL(info->literal());
......@@ -7428,9 +7428,9 @@ TEST(BasicImportExportParsing) {
// Show that parsing as a module works
{
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_module();
if (!i::parsing::ParseProgram(&info, isolate)) {
if (!i::parsing::ParseProgram(&info, script, isolate)) {
i::Handle<i::JSObject> exception_handle(
i::JSObject::cast(isolate->pending_exception()), isolate);
i::Handle<i::String> message_string = i::Handle<i::String>::cast(
......@@ -7451,8 +7451,8 @@ TEST(BasicImportExportParsing) {
// And that parsing a script does not.
{
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
CHECK(!i::parsing::ParseProgram(&info, isolate));
i::ParseInfo info(isolate, *script);
CHECK(!i::parsing::ParseProgram(&info, script, isolate));
isolate->clear_pending_exception();
}
}
......@@ -7488,9 +7488,9 @@ TEST(NamespaceExportParsing) {
i::Handle<i::String> source =
factory->NewStringFromAsciiChecked(kSources[i]);
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_module();
CHECK(i::parsing::ParseProgram(&info, isolate));
CHECK(i::parsing::ParseProgram(&info, script, isolate));
}
}
......@@ -7583,9 +7583,9 @@ TEST(ImportExportParsingErrors) {
factory->NewStringFromAsciiChecked(kErrorSources[i]);
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_module();
CHECK(!i::parsing::ParseProgram(&info, isolate));
CHECK(!i::parsing::ParseProgram(&info, script, isolate));
isolate->clear_pending_exception();
}
}
......@@ -7619,9 +7619,9 @@ TEST(ModuleTopLevelFunctionDecl) {
factory->NewStringFromAsciiChecked(kErrorSources[i]);
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_module();
CHECK(!i::parsing::ParseProgram(&info, isolate));
CHECK(!i::parsing::ParseProgram(&info, script, isolate));
isolate->clear_pending_exception();
}
}
......@@ -7816,9 +7816,9 @@ TEST(ModuleParsingInternals) {
"export {foob};";
i::Handle<i::String> source = factory->NewStringFromAsciiChecked(kSource);
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_module();
CHECK(i::parsing::ParseProgram(&info, isolate));
CHECK(i::parsing::ParseProgram(&info, script, isolate));
CHECK(i::Compiler::Analyze(&info));
i::FunctionLiteral* func = info.literal();
i::ModuleScope* module_scope = func->scope()->AsModuleScope();
......@@ -8059,8 +8059,8 @@ void TestLanguageMode(const char* source,
i::Handle<i::Script> script =
factory->NewScript(factory->NewStringFromAsciiChecked(source));
i::ParseInfo info(isolate, script);
i::parsing::ParseProgram(&info, isolate);
i::ParseInfo info(isolate, *script);
i::parsing::ParseProgram(&info, script, isolate);
CHECK_NOT_NULL(info.literal());
CHECK_EQ(expected_language_mode, info.literal()->language_mode());
}
......@@ -10840,9 +10840,9 @@ TEST(NoPessimisticContextAllocation) {
printf("\n");
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
CHECK(i::parsing::ParseProgram(&info, isolate));
CHECK(i::parsing::ParseProgram(&info, script, isolate));
CHECK(i::Compiler::Analyze(&info));
CHECK_NOT_NULL(info.literal());
......@@ -11400,10 +11400,10 @@ TEST(LexicalLoopVariable) {
i::Handle<i::String> source =
factory->NewStringFromUtf8(i::CStrVector(program)).ToHandleChecked();
i::Handle<i::Script> script = factory->NewScript(source);
i::ParseInfo info(isolate, script);
i::ParseInfo info(isolate, *script);
info.set_allow_lazy_parsing(false);
CHECK(i::parsing::ParseProgram(&info, isolate));
CHECK(i::parsing::ParseProgram(&info, script, isolate));
CHECK(i::Rewriter::Rewrite(&info));
CHECK(i::DeclarationScope::Analyze(&info));
i::DeclarationScope::AllocateScopeInfos(&info, isolate);
......
......@@ -80,8 +80,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
v8::internal::Handle<v8::internal::Script> script =
factory->NewScript(source.ToHandleChecked());
v8::internal::ParseInfo info(i_isolate, script);
if (!v8::internal::parsing::ParseProgram(&info, i_isolate)) {
v8::internal::ParseInfo info(i_isolate, *script);
if (!v8::internal::parsing::ParseProgram(&info, script, i_isolate)) {
i_isolate->OptionalRescheduleException(true);
}
isolate->RequestGarbageCollectionForTesting(
......
......@@ -55,14 +55,13 @@ Handle<SharedFunctionInfo> CreateSharedFunctionInfo(
std::unique_ptr<ParseInfo> OuterParseInfoForShared(
Isolate* isolate, Handle<SharedFunctionInfo> shared) {
Handle<Script> script =
Handle<Script>::cast(handle(shared->script(), isolate));
Script script = Script::cast(shared->script());
std::unique_ptr<ParseInfo> result =
std::make_unique<ParseInfo>(isolate, script);
// Create a character stream to simulate the parser having done so for the
// to-level ParseProgram.
Handle<String> source(String::cast(script->source()), isolate);
Handle<String> source(String::cast(script.source()), isolate);
std::unique_ptr<Utf16CharacterStream> stream(
ScannerStream::For(isolate, source));
result->set_character_stream(std::move(stream));
......
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