Skip to content

Commit 52e2b5a

Browse files
danelphickCommit Bot
authored andcommitted
[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 <[email protected]> Reviewed-by: Toon Verwaest <[email protected]> Cr-Commit-Position: refs/heads/master@{#53820}
1 parent 2c1e4aa commit 52e2b5a

File tree

5 files changed

+37
-36
lines changed

5 files changed

+37
-36
lines changed

src/parsing/parse-info.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ParseInfo::ParseInfo(Isolate* isolate, Handle<SharedFunctionInfo> shared)
5858
set_language_mode(shared->language_mode());
5959
set_asm_wasm_broken(shared->is_asm_wasm_broken());
6060

61-
Handle<Script> script(Script::cast(shared->script()));
61+
Handle<Script> script(Script::cast(shared->script()), isolate);
6262
set_script(script);
6363
set_native(script->type() == Script::TYPE_NATIVE);
6464
set_eval(script->compilation_type() == Script::COMPILATION_TYPE_EVAL);

src/parsing/parse-info.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,16 +223,6 @@ class V8_EXPORT_PRIVATE ParseInfo {
223223
set_strict_mode(is_strict(language_mode));
224224
}
225225

226-
void ReopenHandlesInNewHandleScope() {
227-
if (!script_.is_null()) {
228-
script_ = Handle<Script>(*script_);
229-
}
230-
Handle<ScopeInfo> outer_scope_info;
231-
if (maybe_outer_scope_info_.ToHandle(&outer_scope_info)) {
232-
maybe_outer_scope_info_ = Handle<ScopeInfo>(*outer_scope_info);
233-
}
234-
}
235-
236226
void EmitBackgroundParseStatisticsOnBackgroundThread();
237227
void UpdateBackgroundParseStatisticsOnMainThread(Isolate* isolate);
238228

src/parsing/parser.cc

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -507,7 +507,7 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
507507
DeserializeScopeChain(isolate, info, info->maybe_outer_scope_info());
508508

509509
scanner_.Initialize(info->character_stream(), info->is_module());
510-
FunctionLiteral* result = DoParseProgram(info);
510+
FunctionLiteral* result = DoParseProgram(isolate, info);
511511
MaybeResetCharacterStream(info, result);
512512

513513
HandleSourceURLComments(isolate, info->script());
@@ -528,11 +528,12 @@ FunctionLiteral* Parser::ParseProgram(Isolate* isolate, ParseInfo* info) {
528528
return result;
529529
}
530530

531-
532-
FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
531+
FunctionLiteral* Parser::DoParseProgram(Isolate* isolate, ParseInfo* info) {
533532
// Note that this function can be called from the main thread or from a
534533
// background thread. We should not access anything Isolate / heap dependent
535-
// via ParseInfo, and also not pass it forward.
534+
// via ParseInfo, and also not pass it forward. If not on the main thread
535+
// isolate will be nullptr.
536+
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
536537
DCHECK_NULL(scope_);
537538
DCHECK_NULL(target_stack_);
538539

@@ -583,7 +584,7 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
583584
ok = ok && module()->Validate(this->scope()->AsModuleScope(),
584585
pending_error_handler(), zone());
585586
} else if (info->is_wrapped_as_function()) {
586-
ParseWrapped(info, body, scope, zone(), &ok);
587+
ParseWrapped(isolate, info, body, scope, zone(), &ok);
587588
} else {
588589
// Don't count the mode in the use counters--give the program a chance
589590
// to enable script-wide strict mode below.
@@ -637,23 +638,27 @@ FunctionLiteral* Parser::DoParseProgram(ParseInfo* info) {
637638
return result;
638639
}
639640

640-
ZoneList<const AstRawString*>* Parser::PrepareWrappedArguments(ParseInfo* info,
641+
ZoneList<const AstRawString*>* Parser::PrepareWrappedArguments(Isolate* isolate,
642+
ParseInfo* info,
641643
Zone* zone) {
642644
DCHECK(parsing_on_main_thread_);
643-
Handle<FixedArray> arguments(info->script()->wrapped_arguments());
645+
DCHECK_NOT_NULL(isolate);
646+
Handle<FixedArray> arguments(info->script()->wrapped_arguments(), isolate);
644647
int arguments_length = arguments->length();
645648
ZoneList<const AstRawString*>* arguments_for_wrapped_function =
646649
new (zone) ZoneList<const AstRawString*>(arguments_length, zone);
647650
for (int i = 0; i < arguments_length; i++) {
648651
const AstRawString* argument_string = ast_value_factory()->GetString(
649-
Handle<String>(String::cast(arguments->get(i))));
652+
Handle<String>(String::cast(arguments->get(i)), isolate));
650653
arguments_for_wrapped_function->Add(argument_string, zone);
651654
}
652655
return arguments_for_wrapped_function;
653656
}
654657

655-
void Parser::ParseWrapped(ParseInfo* info, ZoneList<Statement*>* body,
658+
void Parser::ParseWrapped(Isolate* isolate, ParseInfo* info,
659+
ZoneList<Statement*>* body,
656660
DeclarationScope* outer_scope, Zone* zone, bool* ok) {
661+
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
657662
DCHECK(info->is_wrapped_as_function());
658663
ParsingModeScope parsing_mode(this, PARSE_EAGERLY);
659664

@@ -665,7 +670,7 @@ void Parser::ParseWrapped(ParseInfo* info, ZoneList<Statement*>* body,
665670
Scanner::Location location(0, 0);
666671

667672
ZoneList<const AstRawString*>* arguments_for_wrapped_function =
668-
PrepareWrappedArguments(info, zone);
673+
PrepareWrappedArguments(isolate, info, zone);
669674

670675
FunctionLiteral* function_literal = ParseFunctionLiteral(
671676
function_name, location, kSkipFunctionNameCheck, kNormalFunction,
@@ -692,14 +697,15 @@ FunctionLiteral* Parser::ParseFunction(Isolate* isolate, ParseInfo* info,
692697
DCHECK_EQ(factory()->zone(), info->zone());
693698

694699
// Initialize parser state.
695-
Handle<String> name(shared_info->Name());
700+
Handle<String> name(shared_info->Name(), isolate);
696701
info->set_function_name(ast_value_factory()->GetString(name));
697702
scanner_.Initialize(info->character_stream(), info->is_module());
698703

699-
FunctionLiteral* result = DoParseFunction(info, info->function_name());
704+
FunctionLiteral* result =
705+
DoParseFunction(isolate, info, info->function_name());
700706
MaybeResetCharacterStream(info, result);
701707
if (result != nullptr) {
702-
Handle<String> inferred_name(shared_info->inferred_name());
708+
Handle<String> inferred_name(shared_info->inferred_name(), isolate);
703709
result->set_inferred_name(inferred_name);
704710
}
705711

@@ -733,8 +739,9 @@ static FunctionLiteral::FunctionType ComputeFunctionType(ParseInfo* info) {
733739
return FunctionLiteral::kAnonymousExpression;
734740
}
735741

736-
FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
742+
FunctionLiteral* Parser::DoParseFunction(Isolate* isolate, ParseInfo* info,
737743
const AstRawString* raw_name) {
744+
DCHECK_EQ(parsing_on_main_thread_, isolate != nullptr);
738745
DCHECK_NOT_NULL(raw_name);
739746
DCHECK_NULL(scope_);
740747
DCHECK_NULL(target_stack_);
@@ -857,8 +864,9 @@ FunctionLiteral* Parser::DoParseFunction(ParseInfo* info,
857864
info->start_position(), info->end_position());
858865
} else {
859866
ZoneList<const AstRawString*>* arguments_for_wrapped_function =
860-
info->is_wrapped_as_function() ? PrepareWrappedArguments(info, zone())
861-
: nullptr;
867+
info->is_wrapped_as_function()
868+
? PrepareWrappedArguments(isolate, info, zone())
869+
: nullptr;
862870
result = ParseFunctionLiteral(
863871
raw_name, Scanner::Location::invalid(), kSkipFunctionNameCheck, kind,
864872
kNoSourcePosition, function_type, info->language_mode(),
@@ -3448,9 +3456,10 @@ void Parser::ParseOnBackground(ParseInfo* info) {
34483456
// scopes) and set their end position after we know the script length.
34493457
if (info->is_toplevel()) {
34503458
fni_ = new (zone()) FuncNameInferrer(ast_value_factory(), zone());
3451-
result = DoParseProgram(info);
3459+
result = DoParseProgram(/* isolate = */ nullptr, info);
34523460
} else {
3453-
result = DoParseFunction(info, info->function_name());
3461+
result =
3462+
DoParseFunction(/* isolate = */ nullptr, info, info->function_name());
34543463
}
34553464
MaybeResetCharacterStream(info, result);
34563465

src/parsing/parser.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,19 +216,21 @@ class V8_EXPORT_PRIVATE Parser : public NON_EXPORTED_BASE(ParserBase<Parser>) {
216216

217217
FunctionLiteral* ParseFunction(Isolate* isolate, ParseInfo* info,
218218
Handle<SharedFunctionInfo> shared_info);
219-
FunctionLiteral* DoParseFunction(ParseInfo* info,
219+
FunctionLiteral* DoParseFunction(Isolate* isolate, ParseInfo* info,
220220
const AstRawString* raw_name);
221221

222222
// Called by ParseProgram after setting up the scanner.
223-
FunctionLiteral* DoParseProgram(ParseInfo* info);
223+
FunctionLiteral* DoParseProgram(Isolate* isolate, ParseInfo* info);
224224

225225
// Parse with the script as if the source is implicitly wrapped in a function.
226226
// We manually construct the AST and scopes for a top-level function and the
227227
// function wrapper.
228-
void ParseWrapped(ParseInfo* info, ZoneList<Statement*>* body,
229-
DeclarationScope* scope, Zone* zone, bool* ok);
228+
void ParseWrapped(Isolate* isolate, ParseInfo* info,
229+
ZoneList<Statement*>* body, DeclarationScope* scope,
230+
Zone* zone, bool* ok);
230231

231-
ZoneList<const AstRawString*>* PrepareWrappedArguments(ParseInfo* info,
232+
ZoneList<const AstRawString*>* PrepareWrappedArguments(Isolate* isolate,
233+
ParseInfo* info,
232234
Zone* zone);
233235

234236
void StitchAst(ParseInfo* top_level_parse_info, Isolate* isolate);

src/parsing/parsing.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool ParseProgram(ParseInfo* info, Isolate* isolate) {
2424
VMState<PARSER> state(isolate);
2525

2626
// Create a character stream for the parser.
27-
Handle<String> source(String::cast(info->script()->source()));
27+
Handle<String> source(String::cast(info->script()->source()), isolate);
2828
source = String::Flatten(source);
2929
isolate->counters()->total_parse_size()->Increment(source->length());
3030
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(source));
@@ -59,7 +59,7 @@ bool ParseFunction(ParseInfo* info, Handle<SharedFunctionInfo> shared_info,
5959
DCHECK_NULL(info->literal());
6060

6161
// Create a character stream for the parser.
62-
Handle<String> source(String::cast(info->script()->source()));
62+
Handle<String> source(String::cast(info->script()->source()), isolate);
6363
source = String::Flatten(source);
6464
isolate->counters()->total_parse_size()->Increment(source->length());
6565
std::unique_ptr<Utf16CharacterStream> stream(ScannerStream::For(

0 commit comments

Comments
 (0)