@@ -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
0 commit comments