4949import java .util .Iterator ;
5050import java .util .List ;
5151import java .util .Objects ;
52- import java .util .function .Consumer ;
5352import java .util .function .Supplier ;
5453import java .util .function .UnaryOperator ;
5554
@@ -223,11 +222,11 @@ public Object execute(VirtualFrame frame) {
223222 protected final List <String > argumentNames ;
224223 protected final int sourceLength ;
225224 protected final int prologLength ;
225+ protected final ScriptOrModule activeScriptOrModule ;
226226 private final boolean isParentStrict ;
227- private Consumer <ScriptOrModule > scriptOrModuleResolver ;
228227
229228 protected GraalJSTranslator (LexicalContext lc , NodeFactory factory , JSContext context , Source source , List <String > argumentNames , int prologLength , Environment environment ,
230- boolean isParentStrict ) {
229+ boolean isParentStrict , ScriptOrModule scriptOrModule ) {
231230 super (lc );
232231 this .context = context ;
233232 this .environment = environment ;
@@ -237,6 +236,7 @@ protected GraalJSTranslator(LexicalContext lc, NodeFactory factory, JSContext co
237236 this .isParentStrict = isParentStrict ;
238237 this .sourceLength = source .getCharacters ().length ();
239238 this .prologLength = prologLength ;
239+ this .activeScriptOrModule = scriptOrModule ;
240240 }
241241
242242 protected final JavaScriptNode transform (com .oracle .js .parser .ir .Node node ) {
@@ -318,12 +318,6 @@ protected final JavaScriptNode transformFunction(FunctionNode functionNode) {
318318
319319 protected abstract GraalJSTranslator newTranslator (Environment env , LexicalContext savedLC );
320320
321- protected final void resolveScriptOrModule (ScriptOrModule scriptOrModule ) {
322- if (scriptOrModuleResolver != null ) {
323- scriptOrModuleResolver .accept (scriptOrModule );
324- }
325- }
326-
327321 // ---
328322
329323 @ Override
@@ -464,6 +458,7 @@ JavaScriptNode translateFunctionBody(FunctionNode functionNode, List<JavaScriptN
464458 if (functionNode .isAsync () && !functionNode .isGenerator ()) {
465459 ensureHasSourceSection (body , functionNode );
466460 body = handleAsyncFunctionBody (body );
461+ ensureHasSourceSection (body , functionNode );
467462 }
468463
469464 if (!declarations .isEmpty ()) {
@@ -514,11 +509,7 @@ private FunctionRootNode createFunctionRoot(FunctionNode functionNode, JSFunctio
514509 SourceSection functionSourceSection = createSourceSection (functionNode );
515510 FunctionBodyNode functionBody = factory .createFunctionBody (body );
516511 FunctionRootNode functionRoot = factory .createFunctionRootNode (functionBody , environment .getFunctionFrameDescriptor ().toFrameDescriptor (), functionData , functionSourceSection ,
517- currentFunction .getInternalFunctionName ());
518-
519- if (currentFunction .isScriptOrModule ()) {
520- scriptOrModuleResolver = currentFunction .getScriptOrModuleResolver ();
521- }
512+ activeScriptOrModule , currentFunction .getInternalFunctionName ());
522513
523514 if (JSConfig .PrintAst ) {
524515 printAST (functionRoot );
@@ -534,8 +525,6 @@ private FunctionRootNode createFunctionRoot(FunctionNode functionNode, JSFunctio
534525 * @see #splitModuleBodyAtYield
535526 */
536527 private FunctionRootNode createModuleRoot (FunctionNode functionNode , JSFunctionData functionData , FunctionEnvironment currentFunction , JavaScriptNode body ) {
537- scriptOrModuleResolver = currentFunction .getScriptOrModuleResolver ();
538-
539528 if (JSConfig .PrintAst ) {
540529 printAST (body );
541530 }
@@ -562,7 +551,7 @@ private FunctionRootNode createModuleRoot(FunctionNode functionNode, JSFunctionD
562551 FunctionBodyNode linkBody = factory .createFunctionBody (linkBlock );
563552 FunctionBodyNode evalBody = factory .createFunctionBody (evalBlock );
564553 return factory .createModuleRootNode (linkBody , evalBody , environment .getFunctionFrameDescriptor ().toFrameDescriptor (), functionData ,
565- moduleSourceSection , internalFunctionName );
554+ moduleSourceSection , activeScriptOrModule , internalFunctionName );
566555 }
567556 }
568557 }
@@ -571,7 +560,7 @@ private FunctionRootNode createModuleRoot(FunctionNode functionNode, JSFunctionD
571560 currentFunction .addYield (); // yield has not been added yet.
572561 FunctionBodyNode generatorBody = factory .createFunctionBody (handleModuleBody (body ));
573562 return factory .createModuleRootNode (generatorBody , generatorBody , environment .getFunctionFrameDescriptor ().toFrameDescriptor (), functionData ,
574- moduleSourceSection , internalFunctionName );
563+ moduleSourceSection , activeScriptOrModule , internalFunctionName );
575564 }
576565
577566 private static void printAST (Node functionRoot ) {
@@ -600,7 +589,8 @@ private JavaScriptNode handleAsyncFunctionBody(JavaScriptNode body) {
600589 JSWriteFrameSlotNode writeContextNode = (JSWriteFrameSlotNode ) asyncContextVar .createWriteNode (null );
601590 JSReadFrameSlotNode readContextNode = (JSReadFrameSlotNode ) asyncContextVar .createReadNode ();
602591 JavaScriptNode instrumentedBody = instrumentSuspendNodes (body );
603- return factory .createAsyncFunctionBody (context , instrumentedBody , writeContextNode , readContextNode , writeResultNode );
592+ return factory .createAsyncFunctionBody (context , instrumentedBody , writeContextNode , readContextNode , writeResultNode ,
593+ createSourceSection (lc .getCurrentFunction ()), currentFunction ().getExplicitOrInternalFunctionName (), activeScriptOrModule );
604594 }
605595
606596 /**
@@ -625,7 +615,8 @@ private JavaScriptNode handleGeneratorBody(JavaScriptNode body) {
625615 VarRef yieldVar = environment .findYieldValueVar ();
626616 JSWriteFrameSlotNode writeYieldValueNode = (JSWriteFrameSlotNode ) yieldVar .createWriteNode (null );
627617 JSReadFrameSlotNode readYieldResultNode = JSConfig .YieldResultInFrame ? (JSReadFrameSlotNode ) environment .findTempVar (currentFunction ().getYieldResultSlot ()).createReadNode () : null ;
628- return factory .createGeneratorBody (context , instrumentedBody , writeYieldValueNode , readYieldResultNode );
618+ return factory .createGeneratorBody (context , instrumentedBody , writeYieldValueNode , readYieldResultNode ,
619+ createSourceSection (lc .getCurrentFunction ()), currentFunction ().getExplicitOrInternalFunctionName (), activeScriptOrModule );
629620 }
630621
631622 private JavaScriptNode handleAsyncGeneratorBody (JavaScriptNode body ) {
@@ -637,7 +628,8 @@ private JavaScriptNode handleAsyncGeneratorBody(JavaScriptNode body) {
637628 JSReadFrameSlotNode readAsyncContextNode = (JSReadFrameSlotNode ) asyncContextVar .createReadNode ();
638629 JSWriteFrameSlotNode writeYieldValueNode = (JSWriteFrameSlotNode ) yieldVar .createWriteNode (null );
639630 JSReadFrameSlotNode readYieldResultNode = JSConfig .YieldResultInFrame ? (JSReadFrameSlotNode ) environment .findTempVar (currentFunction ().getYieldResultSlot ()).createReadNode () : null ;
640- return factory .createAsyncGeneratorBody (context , instrumentedBody , writeYieldValueNode , readYieldResultNode , writeAsyncContextNode , readAsyncContextNode );
631+ return factory .createAsyncGeneratorBody (context , instrumentedBody , writeYieldValueNode , readYieldResultNode , writeAsyncContextNode , readAsyncContextNode ,
632+ createSourceSection (lc .getCurrentFunction ()), currentFunction ().getExplicitOrInternalFunctionName (), activeScriptOrModule );
641633 }
642634
643635 private JavaScriptNode handleModuleBody (JavaScriptNode body ) {
@@ -648,7 +640,8 @@ private JavaScriptNode handleModuleBody(JavaScriptNode body) {
648640 VarRef yieldVar = environment .findAsyncResultVar ();
649641 JSWriteFrameSlotNode writeAsyncContextNode = (JSWriteFrameSlotNode ) asyncContextVar .createWriteNode (null );
650642 JSWriteFrameSlotNode writeYieldValueNode = (JSWriteFrameSlotNode ) yieldVar .createWriteNode (null );
651- return factory .createTopLevelAsyncModuleBody (context , instrumentedBody , writeYieldValueNode , writeAsyncContextNode );
643+ return factory .createTopLevelAsyncModuleBody (context , instrumentedBody , writeYieldValueNode , writeAsyncContextNode ,
644+ createSourceSection (lc .getCurrentFunction ()), activeScriptOrModule );
652645 } else {
653646 JavaScriptNode instrumentedBody = instrumentSuspendNodes (body );
654647 return factory .createModuleBody (instrumentedBody );
@@ -1867,10 +1860,6 @@ private JavaScriptNode getActiveModule() {
18671860 return environment .findActiveModule ().createReadNode ();
18681861 }
18691862
1870- private JavaScriptNode getActiveScriptOrModule () {
1871- return environment .findActiveScriptOrModule ().createReadNode ();
1872- }
1873-
18741863 private VarRef findScopeVar (TruffleString name , boolean skipWith ) {
18751864 return environment .findVar (name , skipWith );
18761865 }
@@ -2640,7 +2629,8 @@ private JavaScriptNode initializeInstanceElements(JavaScriptNode thisValueNode)
26402629 private JavaScriptNode createCallEvalNode (JavaScriptNode function , JavaScriptNode [] args ) {
26412630 assert (currentFunction ().isGlobal () || currentFunction ().isStrictMode () || currentFunction ().isDirectEval ()) || currentFunction ().isDynamicallyScoped ();
26422631 currentFunction ().prepareForDirectEval ();
2643- return EvalNode .create (context , function , args , createThisNodeUnchecked (), new DirectEvalContext (lc .getCurrentScope (), environment , lc .getCurrentClass ()),
2632+ return EvalNode .create (context , function , args , createThisNodeUnchecked (),
2633+ new DirectEvalContext (lc .getCurrentScope (), environment , lc .getCurrentClass (), activeScriptOrModule ),
26442634 environment .getCurrentBlockScopeSlot ());
26452635 }
26462636
@@ -2659,7 +2649,6 @@ private JavaScriptNode createCallDirectSuper(JavaScriptNode function, JavaScript
26592649
26602650 private JavaScriptNode createImportCallNode (JavaScriptNode [] args ) {
26612651 assert args .length == 1 || (context .getContextOptions ().isImportAssertions () && args .length == 2 );
2662- JavaScriptNode activeScriptOrModule = getActiveScriptOrModule ();
26632652 if (context .getContextOptions ().isImportAssertions () && args .length == 2 ) {
26642653 return factory .createImportCall (context , args [0 ], activeScriptOrModule , args [1 ]);
26652654 }
0 commit comments