@@ -1510,38 +1510,31 @@ void ContextifyContext::ContainsModuleSyntax(
15101510 if (!should_retry_as_esm) {
15111511 for (const auto & error_message : throws_only_in_cjs_error_messages) {
15121512 if (message.find (error_message) != std::string_view::npos) {
1513- // Try parsing again where the user's code is wrapped within an async
1514- // function. If the new parse succeeds, then the error was caused by
1515- // either a top-level declaration of one of the CommonJS module
1516- // variables, or a top-level `await`.
1513+ // Try parsing again where the CommonJS wrapper is replaced by an
1514+ // async function wrapper . If the new parse succeeds, then the error
1515+ // was caused by either a top-level declaration of one of the CommonJS
1516+ // module variables, or a top-level `await`.
15171517 TryCatchScope second_parse_try_catch (env);
1518- Local<String> wrapped_code =
1518+ code =
15191519 String::Concat (isolate,
15201520 String::NewFromUtf8 (isolate, " (async function() {" )
15211521 .ToLocalChecked (),
15221522 code);
1523- wrapped_code = String::Concat (
1523+ code = String::Concat (
15241524 isolate,
1525- wrapped_code ,
1525+ code ,
15261526 String::NewFromUtf8 (isolate, " })();" ).ToLocalChecked ());
1527- ScriptCompiler::Source wrapped_source =
1528- GetCommonJSSourceInstance (isolate,
1529- wrapped_code,
1530- filename,
1531- 0 ,
1532- 0 ,
1533- host_defined_options,
1534- nullptr );
1535- ContextifyContext::CompileFunctionAndCacheResult (
1536- env,
1527+ ScriptCompiler::Source wrapped_source = GetCommonJSSourceInstance (
1528+ isolate, code, filename, 0 , 0 , host_defined_options, nullptr );
1529+ std::ignore = ScriptCompiler::CompileFunction (
15371530 context,
15381531 &wrapped_source,
1539- std::move (params),
1540- std::vector<Local<Object>>(),
1532+ params.size (),
1533+ params.data (),
1534+ 0 ,
1535+ nullptr ,
15411536 options,
1542- true ,
1543- id_symbol,
1544- second_parse_try_catch);
1537+ v8::ScriptCompiler::NoCacheReason::kNoCacheNoReason );
15451538 if (!second_parse_try_catch.HasTerminated ()) {
15461539 if (second_parse_try_catch.HasCaught ()) {
15471540 // If on the second parse an error is thrown by ESM syntax, then
0 commit comments