Commit 52e2b5aa authored by Dan Elphick's avatar Dan Elphick Committed by Commit Bot

[explicit isolates] Replace every Handle(T*) in parsing/

Replace all but one Handle<T*>(T*) calls with ones that explicitly pass
in an Isolate.

Requires plumbing Isolate* through several Parser functions which
previously avoided it because of worries about accessing the heap off
the main thread. In all off-main-thread cases, isolate will be nullptr
and every such function asserts with:
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);

Also deletes unused function ParseInfo::ReopenHandlesInNewHandleScope.

Bug: v8:7786
Change-Id: I3dd9c49dcde49fdbcb684ba73f47a30d00fc495e
Reviewed-on: https://chromium-review.googlesource.com/1087272
Commit-Queue: Dan Elphick <delphick@chromium.org>
Reviewed-by: 's avatarToon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53820}
parent 2c1e4aa9
......@@ -58,7 +58,7 @@ ParseInfo::ParseInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared)
set_language_mode(shared->language_mode());
set_asm_wasm_broken(shared->is_asm_wasm_broken());
Handle<Script> script(Script::cast(shared->script()));
Handle<Script> script(Script::cast(shared->script()), isolate);
set_script(script);
set_native(script->type() == Script::TYPE_NATIVE);
set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL);
......
......@@ -223,16 +223,6 @@ class V8_EXPORT_PRIVATE ParseInfo {
set_strict_mode(is_strict(language_mode));
}
void ReopenHandlesInNewHandleScope() {
if (!script_.is_null()) {
script_ = Handle<Script>(*script_);
}
Handle<ScopeInfo> outer_scope_info;
if (maybe_outer_scope_info_.ToHandle(&outer_scope_info)) {
maybe_outer_scope_info_ = Handle<ScopeInfo>(*outer_scope_info);
}
}
void EmitBackgroundParseStatisticsOnBackgroundThread();
void UpdateBackgroundParseStatisticsOnMainThread(Isolate* isolate);
......
......@@ -507,7 +507,7 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
DeserializeScopeChain(isolate, info, info->maybe_outer_scope_info());
scanner_.Initialize(info->character_stream(), info->is_module());
FunctionLiteral* result = DoParseProgram(info);
FunctionLiteral* result = DoParseProgram(isolate, info);
MaybeResetCharacterStream(info, result);
HandleSourceURLComments(isolate, info->script());
......@@ -528,11 +528,12 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
return result;
}
FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
// Note that this function can be called from the main thread or from a
// background thread. We should not access anything Isolate / heap dependent
// via ParseInfo, and also not pass it forward.
// via ParseInfo, and also not pass it forward. If not on the main thread
// isolate will be nullptr.
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
DCHECK_NULL(scope_);
DCHECK_NULL(target_stack_);
......@@ -583,7 +584,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
ok = ok && module()->Validate(this->scope()->AsModuleScope(),
pending_error_handler(), zone());
} else if (info->is_wrapped_as_function()) {
ParseWrapped(info, body, scope, zone(), &ok);
ParseWrapped(isolate, info, body, scope, zone(), &ok);
} else {
// Don't count the mode in the use counters--give the program a chance
// to enable script-wide strict mode below.
......@@ -637,23 +638,27 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
return result;
}
ZoneList<const AstRawString*>* Parser::PrepareWrappedArguments(ParseInfo* info,
ZoneList<const AstRawString*>* Parser::PrepareWrappedArguments(Isolate* isolate,
ParseInfo* info,
Zone* zone) {
DCHECK(parsing_on_main_thread_);
Handle<FixedArray> arguments(info->script()->wrapped_arguments());
DCHECK_NOT_NULL(isolate);
Handle<FixedArray> arguments(info->script()->wrapped_arguments(), isolate);
int arguments_length = arguments->length();
ZoneList<const AstRawString*>* arguments_for_wrapped_function =
new (zone) ZoneList<const AstRawString*>(arguments_length, zone);
for (int i = 0; i < arguments_length; i++) {
const AstRawString* argument_string = ast_value_factory()->GetString(
Handle<String>(String::cast(arguments->get(i))));
Handle<String>(String::cast(arguments->get(i)), isolate));
arguments_for_wrapped_function->Add(argument_string, zone);
}
return arguments_for_wrapped_function;
}
void Parser::ParseWrapped(ParseInfo* info, ZoneList<Statement*>* body,
void Parser::ParseWrapped(Isolate* isolate, ParseInfo* info,
ZoneList<Statement*>* body,
DeclarationScope* outer_scope, Zone* zone, bool* ok) {
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
DCHECK(info->is_wrapped_as_function());
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
......@@ -665,7 +670,7 @@ void Parser::ParseWrapped(ParseInfo* info, ZoneList<Statement*>* body,
Scanner::Location location(0, 0);
ZoneList<const AstRawString*>* arguments_for_wrapped_function =
PrepareWrappedArguments(info, zone);
PrepareWrappedArguments(isolate, info, zone);
FunctionLiteral* function_literal = ParseFunctionLiteral(
function_name, location, kSkipFunctionNameCheck, kNormalFunction,
......@@ -692,14 +697,15 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info,
DCHECK_EQ(factory()->zone(), info->zone());
// Initialize parser state.
Handle<String> name(shared_info->Name());
Handle<String> name(shared_info->Name(), isolate);
info->set_function_name(ast_value_factory()->GetString(name));
scanner_.Initialize(info->character_stream(), info->is_module());
FunctionLiteral* result = DoParseFunction(info, info->function_name());
FunctionLiteral* result =
DoParseFunction(isolate, info, info->function_name());
MaybeResetCharacterStream(info, result);
if (result != nullptr) {
Handle<String> inferred_name(shared_info->inferred_name());
Handle<String> inferred_name(shared_info->inferred_name(), isolate);
result->set_inferred_name(inferred_name);
}
......@@ -733,8 +739,9 @@ static FunctionLiteral::FunctionType ComputeFunctionType(ParseInfo* info) {
return FunctionLiteral::kAnonymousExpression;
}
FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
const AstRawString* raw_name) {
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
DCHECK_NOT_NULL(raw_name);
DCHECK_NULL(scope_);
DCHECK_NULL(target_stack_);
......@@ -857,8 +864,9 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
info->start_position(), info->end_position());
} else {
ZoneList<const AstRawString*>* arguments_for_wrapped_function =
info->is_wrapped_as_function() ? PrepareWrappedArguments(info, zone())
: nullptr;
info->is_wrapped_as_function()
? PrepareWrappedArguments(isolate, info, zone())
: nullptr;
result = ParseFunctionLiteral(
raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind,
kNoSourcePosition, function_type, info->language_mode(),
......@@ -3448,9 +3456,10 @@ void Parser::ParseOnBackground(ParseInfo* info) {
// scopes) and set their end position after we know the script length.
if (info->is_toplevel()) {
fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
result = DoParseProgram(info);
result = DoParseProgram(/* isolate = */ nullptr, info);
} else {
result = DoParseFunction(info, info->function_name());
result =
DoParseFunction(/* isolate = */ nullptr, info, info->function_name());
}
MaybeResetCharacterStream(info, result);
......
......@@ -216,19 +216,21 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
FunctionLiteral* ParseFunction(Isolate* isolate, ParseInfo* info,
Handle<SharedFunctionInfo> shared_info);
FunctionLiteral* DoParseFunction(ParseInfo* info,
FunctionLiteral* DoParseFunction(Isolate* isolate, ParseInfo* info,
const AstRawString* raw_name);
// Called by ParseProgram after setting up the scanner.
FunctionLiteral* DoParseProgram(ParseInfo* info);
FunctionLiteral* DoParseProgram(Isolate* isolate, ParseInfo* info);
// Parse with the script as if the source is implicitly wrapped in a function.
// We manually construct the AST and scopes for a top-level function and the
// function wrapper.
void ParseWrapped(ParseInfo* info, ZoneList<Statement*>* body,
DeclarationScope* scope, Zone* zone, bool* ok);
void ParseWrapped(Isolate* isolate, ParseInfo* info,
ZoneList<Statement*>* body, DeclarationScope* scope,
Zone* zone, bool* ok);
ZoneList<const AstRawString*>* PrepareWrappedArguments(ParseInfo* info,
ZoneList<const AstRawString*>* PrepareWrappedArguments(Isolate* isolate,
ParseInfo* info,
Zone* zone);
void StitchAst(ParseInfo* top_level_parse_info, Isolate* isolate);
......
......@@ -24,7 +24,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()));
Handle<String> source(String::cast(info->script()->source()), isolate);
source = String::Flatten(source);
isolate->counters()->total_parse_size()->Increment(source->length());
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(source));
......@@ -59,7 +59,7 @@ 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()));
Handle<String> source(String::cast(info->script()->source()), isolate);
source = String::Flatten(source);
isolate->counters()->total_parse_size()->Increment(source->length());
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(
......
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