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;
......
......@@ -195,8 +195,9 @@ void UnoptimizedCompilationJob::RecordFunctionCompilation(
double time_taken_ms = time_taken_to_execute_.InMillisecondsF() +
time_taken_to_finalize_.InMillisecondsF();
LogFunctionCompilation(tag, shared, parse_info()->script(), abstract_code,
false, time_taken_ms, isolate);
Handle<Script> script(Script::cast(shared->script()), isolate);
LogFunctionCompilation(tag, shared, script, abstract_code, false,
time_taken_ms, isolate);
}
// ----------------------------------------------------------------------------
......@@ -382,7 +383,7 @@ void InstallBytecodeArray(Handle<BytecodeArray> bytecode_array,
shared_info->set_interpreter_data(*interpreter_data);
Handle<Script> script = parse_info->script();
Handle<Script> script(Script::cast(shared_info->script()), isolate);
Handle<AbstractCode> abstract_code = Handle<AbstractCode>::cast(code);
int line_num =
Script::GetLineNumber(script, shared_info->StartPosition()) + 1;
......@@ -441,18 +442,18 @@ void InstallUnoptimizedCode(UnoptimizedCompilationInfo* compilation_info,
}
}
void EnsureSharedFunctionInfosArrayOnScript(ParseInfo* parse_info,
void EnsureSharedFunctionInfosArrayOnScript(Handle<Script> script,
ParseInfo* parse_info,
Isolate* isolate) {
DCHECK(parse_info->is_toplevel());
DCHECK(!parse_info->script().is_null());
if (parse_info->script()->shared_function_infos().length() > 0) {
DCHECK_EQ(parse_info->script()->shared_function_infos().length(),
if (script->shared_function_infos().length() > 0) {
DCHECK_EQ(script->shared_function_infos().length(),
parse_info->max_function_literal_id() + 1);
return;
}
Handle<WeakFixedArray> infos(isolate->factory()->NewWeakFixedArray(
parse_info->max_function_literal_id() + 1));
parse_info->script()->set_shared_function_infos(*infos);
script->set_shared_function_infos(*infos);
}
void SetSharedFunctionFlagsFromLiteral(FunctionLiteral* literal,
......@@ -560,9 +561,9 @@ std::unique_ptr<UnoptimizedCompilationJob> GenerateUnoptimizedCode(
}
MaybeHandle<SharedFunctionInfo> GenerateUnoptimizedCodeForToplevel(
Isolate* isolate, ParseInfo* parse_info, AccountingAllocator* allocator,
IsCompiledScope* is_compiled_scope) {
EnsureSharedFunctionInfosArrayOnScript(parse_info, isolate);
Isolate* isolate, Handle<Script> script, ParseInfo* parse_info,
AccountingAllocator* allocator, IsCompiledScope* is_compiled_scope) {
EnsureSharedFunctionInfosArrayOnScript(script, parse_info, isolate);
parse_info->ast_value_factory()->Internalize(isolate);
if (!Compiler::Analyze(parse_info)) return MaybeHandle<SharedFunctionInfo>();
......@@ -570,7 +571,6 @@ MaybeHandle<SharedFunctionInfo> GenerateUnoptimizedCodeForToplevel(
// Prepare and execute compilation of the outer-most function.
// Create the SharedFunctionInfo and add it to the script's list.
Handle<Script> script = parse_info->script();
Handle<SharedFunctionInfo> top_level =
isolate->factory()->NewSharedFunctionInfoForLiteral(parse_info->literal(),
script, true);
......@@ -648,12 +648,13 @@ bool FinalizeUnoptimizedCode(
return false;
}
Handle<Script> script(Script::cast(shared_info->script()), isolate);
// Finalize the inner functions' compilation jobs.
for (auto&& inner_job : *inner_function_jobs) {
Handle<SharedFunctionInfo> inner_shared_info =
Compiler::GetSharedFunctionInfo(
inner_job->compilation_info()->literal(), parse_info->script(),
isolate);
inner_job->compilation_info()->literal(), script, isolate);
// The inner function might be compiled already if compiling for debug.
if (inner_shared_info->is_compiled()) continue;
if (FinalizeUnoptimizedCompilationJob(inner_job.get(), inner_shared_info,
......@@ -665,8 +666,7 @@ bool FinalizeUnoptimizedCode(
// Report any warnings generated during compilation.
if (parse_info->pending_error_handler()->has_pending_warnings()) {
parse_info->pending_error_handler()->ReportWarnings(isolate,
parse_info->script());
parse_info->pending_error_handler()->ReportWarnings(isolate, script);
}
return true;
......@@ -917,14 +917,15 @@ MaybeHandle<Code> GetOptimizedCode(Handle<JSFunction> function,
return MaybeHandle<Code>();
}
bool FailWithPendingException(Isolate* isolate, ParseInfo* parse_info,
bool FailWithPendingException(Isolate* isolate, Handle<Script> script,
ParseInfo* parse_info,
Compiler::ClearExceptionFlag flag) {
if (flag == Compiler::CLEAR_EXCEPTION) {
isolate->clear_pending_exception();
} else if (!isolate->has_pending_exception()) {
if (parse_info->pending_error_handler()->has_pending_error()) {
parse_info->pending_error_handler()->ReportErrors(
isolate, parse_info->script(), parse_info->ast_value_factory());
isolate, script, parse_info->ast_value_factory());
} else {
isolate->StackOverflow();
}
......@@ -932,8 +933,8 @@ bool FailWithPendingException(Isolate* isolate, ParseInfo* parse_info,
return false;
}
void FinalizeScriptCompilation(Isolate* isolate, ParseInfo* parse_info) {
Handle<Script> script = parse_info->script();
void FinalizeScriptCompilation(Isolate* isolate, Handle<Script> script,
ParseInfo* parse_info) {
script->set_compilation_state(Script::COMPILATION_STATE_COMPILED);
// Register any pending parallel tasks with the associated SFI.
......@@ -955,7 +956,7 @@ void FinalizeScriptCompilation(Isolate* isolate, ParseInfo* parse_info) {
}
MaybeHandle<SharedFunctionInfo> FinalizeTopLevel(
ParseInfo* parse_info, Isolate* isolate,
ParseInfo* parse_info, Handle<Script> script, Isolate* isolate,
UnoptimizedCompilationJob* outer_function_job,
UnoptimizedCompilationJobList* inner_function_jobs) {
// Internalize ast values onto the heap.
......@@ -963,28 +964,28 @@ MaybeHandle<SharedFunctionInfo> FinalizeTopLevel(
// Create shared function infos for top level and shared function infos array
// for inner functions.
EnsureSharedFunctionInfosArrayOnScript(parse_info, isolate);
EnsureSharedFunctionInfosArrayOnScript(script, parse_info, isolate);
DCHECK_EQ(kNoSourcePosition,
parse_info->literal()->function_token_position());
Handle<SharedFunctionInfo> shared_info =
isolate->factory()->NewSharedFunctionInfoForLiteral(
parse_info->literal(), parse_info->script(), true);
isolate->factory()->NewSharedFunctionInfoForLiteral(parse_info->literal(),
script, true);
// Finalize compilation of the unoptimized bytecode or asm-js data.
if (!FinalizeUnoptimizedCode(parse_info, isolate, shared_info,
outer_function_job, inner_function_jobs)) {
FailWithPendingException(isolate, parse_info,
FailWithPendingException(isolate, script, parse_info,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
return MaybeHandle<SharedFunctionInfo>();
}
FinalizeScriptCompilation(isolate, parse_info);
FinalizeScriptCompilation(isolate, script, parse_info);
return shared_info;
}
MaybeHandle<SharedFunctionInfo> CompileToplevel(
ParseInfo* parse_info, Isolate* isolate,
ParseInfo* parse_info, Handle<Script> script, Isolate* isolate,
IsCompiledScope* is_compiled_scope) {
TimerEventScope<TimerEventCompileCode> top_level_timer(isolate);
TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode");
......@@ -997,7 +998,7 @@ MaybeHandle<SharedFunctionInfo> CompileToplevel(
: RuntimeCallCounterId::kCompileScript);
VMState<BYTECODE_COMPILER> state(isolate);
if (parse_info->literal() == nullptr &&
!parsing::ParseProgram(parse_info, isolate)) {
!parsing::ParseProgram(parse_info, script, isolate)) {
return MaybeHandle<SharedFunctionInfo>();
}
// Measure how long it takes to do the compilation; only take the
......@@ -1013,14 +1014,14 @@ MaybeHandle<SharedFunctionInfo> CompileToplevel(
// Generate the unoptimized bytecode or asm-js data.
MaybeHandle<SharedFunctionInfo> shared_info =
GenerateUnoptimizedCodeForToplevel(
isolate, parse_info, isolate->allocator(), is_compiled_scope);
isolate, script, parse_info, isolate->allocator(), is_compiled_scope);
if (shared_info.is_null()) {
FailWithPendingException(isolate, parse_info,
FailWithPendingException(isolate, script, parse_info,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
return MaybeHandle<SharedFunctionInfo>();
}
FinalizeScriptCompilation(isolate, parse_info);
FinalizeScriptCompilation(isolate, script, parse_info);
return shared_info;
}
......@@ -1231,7 +1232,7 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
HistogramTimerScope timer(isolate->counters()->collect_source_positions());
// Set up parse info.
ParseInfo parse_info(isolate, shared_info);
ParseInfo parse_info(isolate, *shared_info);
parse_info.set_lazy_compile();
parse_info.set_collect_source_positions();
if (FLAG_allow_natives_syntax) parse_info.set_allow_natives_syntax();
......@@ -1243,7 +1244,8 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
// Parsing failed probably as a result of stack exhaustion.
bytecode->SetSourcePositionsFailedToCollect();
return FailWithPendingException(
isolate, &parse_info, Compiler::ClearExceptionFlag::CLEAR_EXCEPTION);
isolate, handle(Script::cast(shared_info->script()), isolate),
&parse_info, Compiler::ClearExceptionFlag::CLEAR_EXCEPTION);
}
// Character stream shouldn't be used again.
......@@ -1258,7 +1260,8 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
// Recompiling failed probably as a result of stack exhaustion.
bytecode->SetSourcePositionsFailedToCollect();
return FailWithPendingException(
isolate, &parse_info, Compiler::ClearExceptionFlag::CLEAR_EXCEPTION);
isolate, handle(Script::cast(shared_info->script()), isolate),
&parse_info, Compiler::ClearExceptionFlag::CLEAR_EXCEPTION);
}
job = interpreter::Interpreter::NewSourcePositionCollectionJob(
......@@ -1269,7 +1272,8 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
// Recompiling failed probably as a result of stack exhaustion.
bytecode->SetSourcePositionsFailedToCollect();
return FailWithPendingException(
isolate, &parse_info, Compiler::ClearExceptionFlag::CLEAR_EXCEPTION);
isolate, handle(Script::cast(shared_info->script()), isolate),
&parse_info, Compiler::ClearExceptionFlag::CLEAR_EXCEPTION);
}
}
......@@ -1311,14 +1315,16 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy());
// Set up parse info.
ParseInfo parse_info(isolate, shared_info);
ParseInfo parse_info(isolate, *shared_info);
parse_info.set_lazy_compile();
// Check if the compiler dispatcher has shared_info enqueued for compile.
CompilerDispatcher* dispatcher = isolate->compiler_dispatcher();
if (dispatcher->IsEnqueued(shared_info)) {
if (!dispatcher->FinishNow(shared_info)) {
return FailWithPendingException(isolate, &parse_info, flag);
return FailWithPendingException(
isolate, handle(Script::cast(shared_info->script()), isolate),
&parse_info, flag);
}
*is_compiled_scope = shared_info->is_compiled_scope();
DCHECK(is_compiled_scope->is_compiled());
......@@ -1335,7 +1341,9 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
// Parse and update ParseInfo with the results.
if (!parsing::ParseAny(&parse_info, shared_info, isolate)) {
return FailWithPendingException(isolate, &parse_info, flag);
return FailWithPendingException(
isolate, handle(Script::cast(shared_info->script()), isolate),
&parse_info, flag);
}
// Generate the unoptimized bytecode or asm-js data.
......@@ -1344,7 +1352,9 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
GenerateUnoptimizedCode(&parse_info, isolate->allocator(),
&inner_function_jobs));
if (!outer_function_job) {
return FailWithPendingException(isolate, &parse_info, flag);
return FailWithPendingException(
isolate, handle(Script::cast(shared_info->script()), isolate),
&parse_info, flag);
}
// Internalize ast values onto the heap.
......@@ -1354,7 +1364,9 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
if (!FinalizeUnoptimizedCode(&parse_info, isolate, shared_info,
outer_function_job.get(),
&inner_function_jobs)) {
return FailWithPendingException(isolate, &parse_info, flag);
return FailWithPendingException(
isolate, handle(Script::cast(shared_info->script()), isolate),
&parse_info, flag);
}
DCHECK(!isolate->has_pending_exception());
......@@ -1366,12 +1378,13 @@ bool Compiler::Compile(Handle<SharedFunctionInfo> shared_info,
// mismatches.
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate, shared_info);
Handle<Script> script(Script::cast(shared_info->script()), isolate);
// Do the same for eagerly compiled inner functions.
for (auto&& inner_job : inner_function_jobs) {
Handle<SharedFunctionInfo> inner_shared_info =
Compiler::GetSharedFunctionInfo(
inner_job->compilation_info()->literal(), parse_info.script(),
isolate);
inner_job->compilation_info()->literal(), script, isolate);
SharedFunctionInfo::EnsureSourcePositionsAvailable(isolate,
inner_shared_info);
}
......@@ -1444,14 +1457,16 @@ bool Compiler::FinalizeBackgroundCompileTask(
DCHECK(!shared_info->is_compiled());
Handle<Script> script(Script::cast(shared_info->script()), isolate);
parse_info->set_script(script);
// TODO(leszeks): We can probably remove this, the parse_info flags should
// already match the script's.
parse_info->SetFlagsFromScript(isolate, *script);
task->parser()->UpdateStatistics(isolate, script);
task->parser()->HandleSourceURLComments(isolate, script);
if (parse_info->literal() == nullptr || !task->outer_function_job()) {
// Parsing or compile failed on background thread - report error messages.
return FailWithPendingException(isolate, parse_info, flag);
return FailWithPendingException(isolate, script, parse_info, flag);
}
// Parsing has succeeded - finalize compilation.
......@@ -1460,7 +1475,7 @@ bool Compiler::FinalizeBackgroundCompileTask(
task->outer_function_job(),
task->inner_function_jobs())) {
// Finalization failed - throw an exception.
return FailWithPendingException(isolate, parse_info, flag);
return FailWithPendingException(isolate, script, parse_info, flag);
}
DCHECK(!isolate->has_pending_exception());
......@@ -1502,9 +1517,9 @@ bool Compiler::CompileOptimized(Handle<JSFunction> function,
}
MaybeHandle<SharedFunctionInfo> Compiler::CompileForLiveEdit(
ParseInfo* parse_info, Isolate* isolate) {
ParseInfo* parse_info, Handle<Script> script, Isolate* isolate) {
IsCompiledScope is_compiled_scope;
return CompileToplevel(parse_info, isolate, &is_compiled_scope);
return CompileToplevel(parse_info, script, isolate, &is_compiled_scope);
}
MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
......@@ -1581,7 +1596,7 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
}
DCHECK(!parse_info.is_module());
if (!CompileToplevel(&parse_info, isolate, &is_compiled_scope)
if (!CompileToplevel(&parse_info, script, isolate, &is_compiled_scope)
.ToHandle(&shared_info)) {
return MaybeHandle<JSFunction>();
}
......@@ -2065,9 +2080,9 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
if (maybe_result.is_null()) {
ParseInfo parse_info(isolate);
// No cache entry found compile the script.
NewScript(isolate, &parse_info, source, script_details, origin_options,
natives);
DCHECK_EQ(parse_info.is_repl_mode(), parse_info.script()->is_repl_mode());
Handle<Script> script = NewScript(isolate, &parse_info, source,
script_details, origin_options, natives);
DCHECK_EQ(parse_info.is_repl_mode(), script->is_repl_mode());
// Compile the function and add it to the isolate cache.
if (origin_options.IsModule()) parse_info.set_module();
......@@ -2076,7 +2091,8 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
parse_info.set_language_mode(
stricter_language_mode(parse_info.language_mode(), language_mode));
maybe_result = CompileToplevel(&parse_info, isolate, &is_compiled_scope);
maybe_result =
CompileToplevel(&parse_info, script, isolate, &is_compiled_scope);
Handle<SharedFunctionInfo> result;
if (extension == nullptr && maybe_result.ToHandle(&result)) {
DCHECK(is_compiled_scope.is_compiled());
......@@ -2142,6 +2158,7 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
parse_info.set_eval(); // Use an eval scope as declaration scope.
parse_info.set_function_syntax_kind(FunctionSyntaxKind::kWrapped);
parse_info.set_wrapped_arguments(arguments);
// TODO(delphick): Remove this and instead make the wrapped and wrapper
// functions fully non-lazy instead thus preventing source positions from
// being omitted.
......@@ -2154,7 +2171,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
stricter_language_mode(parse_info.language_mode(), language_mode));
Handle<SharedFunctionInfo> top_level;
maybe_result = CompileToplevel(&parse_info, isolate, &is_compiled_scope);
maybe_result =
CompileToplevel(&parse_info, script, isolate, &is_compiled_scope);
if (maybe_result.is_null()) isolate->ReportPendingMessages();
ASSIGN_RETURN_ON_EXCEPTION(isolate, top_level, maybe_result, JSFunction);
......@@ -2216,16 +2234,16 @@ Compiler::GetSharedFunctionInfoForStreamedScript(
if (parse_info->literal() == nullptr || !task->outer_function_job()) {
// Parsing has failed - report error messages.
FailWithPendingException(isolate, parse_info,
FailWithPendingException(isolate, script, parse_info,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
} else {
// Parsing has succeeded - finalize compilation.
maybe_result =
FinalizeTopLevel(parse_info, isolate, task->outer_function_job(),
maybe_result = FinalizeTopLevel(parse_info, script, isolate,
task->outer_function_job(),
task->inner_function_jobs());
if (maybe_result.is_null()) {
// Finalization failed - throw an exception.
FailWithPendingException(isolate, parse_info,
FailWithPendingException(isolate, script, parse_info,
Compiler::ClearExceptionFlag::KEEP_EXCEPTION);
}
}
......
......@@ -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,7 +102,10 @@ 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)
return info->is_toplevel()
? ParseProgram(
info, handle(Script::cast(shared_info->script()), isolate),
isolate, mode)
: ParseFunction(info, shared_info, isolate, mode);
}
......
......@@ -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