49
49
import java .util .Iterator ;
50
50
import java .util .List ;
51
51
import java .util .Objects ;
52
- import java .util .function .Consumer ;
53
52
import java .util .function .Supplier ;
54
53
import java .util .function .UnaryOperator ;
55
54
@@ -223,11 +222,11 @@ public Object execute(VirtualFrame frame) {
223
222
protected final List <String > argumentNames ;
224
223
protected final int sourceLength ;
225
224
protected final int prologLength ;
225
+ protected final ScriptOrModule activeScriptOrModule ;
226
226
private final boolean isParentStrict ;
227
- private Consumer <ScriptOrModule > scriptOrModuleResolver ;
228
227
229
228
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 ) {
231
230
super (lc );
232
231
this .context = context ;
233
232
this .environment = environment ;
@@ -237,6 +236,7 @@ protected GraalJSTranslator(LexicalContext lc, NodeFactory factory, JSContext co
237
236
this .isParentStrict = isParentStrict ;
238
237
this .sourceLength = source .getCharacters ().length ();
239
238
this .prologLength = prologLength ;
239
+ this .activeScriptOrModule = scriptOrModule ;
240
240
}
241
241
242
242
protected final JavaScriptNode transform (com .oracle .js .parser .ir .Node node ) {
@@ -318,12 +318,6 @@ protected final JavaScriptNode transformFunction(FunctionNode functionNode) {
318
318
319
319
protected abstract GraalJSTranslator newTranslator (Environment env , LexicalContext savedLC );
320
320
321
- protected final void resolveScriptOrModule (ScriptOrModule scriptOrModule ) {
322
- if (scriptOrModuleResolver != null ) {
323
- scriptOrModuleResolver .accept (scriptOrModule );
324
- }
325
- }
326
-
327
321
// ---
328
322
329
323
@ Override
@@ -464,6 +458,7 @@ JavaScriptNode translateFunctionBody(FunctionNode functionNode, List<JavaScriptN
464
458
if (functionNode .isAsync () && !functionNode .isGenerator ()) {
465
459
ensureHasSourceSection (body , functionNode );
466
460
body = handleAsyncFunctionBody (body );
461
+ ensureHasSourceSection (body , functionNode );
467
462
}
468
463
469
464
if (!declarations .isEmpty ()) {
@@ -514,11 +509,7 @@ private FunctionRootNode createFunctionRoot(FunctionNode functionNode, JSFunctio
514
509
SourceSection functionSourceSection = createSourceSection (functionNode );
515
510
FunctionBodyNode functionBody = factory .createFunctionBody (body );
516
511
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 ());
522
513
523
514
if (JSConfig .PrintAst ) {
524
515
printAST (functionRoot );
@@ -534,8 +525,6 @@ private FunctionRootNode createFunctionRoot(FunctionNode functionNode, JSFunctio
534
525
* @see #splitModuleBodyAtYield
535
526
*/
536
527
private FunctionRootNode createModuleRoot (FunctionNode functionNode , JSFunctionData functionData , FunctionEnvironment currentFunction , JavaScriptNode body ) {
537
- scriptOrModuleResolver = currentFunction .getScriptOrModuleResolver ();
538
-
539
528
if (JSConfig .PrintAst ) {
540
529
printAST (body );
541
530
}
@@ -562,7 +551,7 @@ private FunctionRootNode createModuleRoot(FunctionNode functionNode, JSFunctionD
562
551
FunctionBodyNode linkBody = factory .createFunctionBody (linkBlock );
563
552
FunctionBodyNode evalBody = factory .createFunctionBody (evalBlock );
564
553
return factory .createModuleRootNode (linkBody , evalBody , environment .getFunctionFrameDescriptor ().toFrameDescriptor (), functionData ,
565
- moduleSourceSection , internalFunctionName );
554
+ moduleSourceSection , activeScriptOrModule , internalFunctionName );
566
555
}
567
556
}
568
557
}
@@ -571,7 +560,7 @@ private FunctionRootNode createModuleRoot(FunctionNode functionNode, JSFunctionD
571
560
currentFunction .addYield (); // yield has not been added yet.
572
561
FunctionBodyNode generatorBody = factory .createFunctionBody (handleModuleBody (body ));
573
562
return factory .createModuleRootNode (generatorBody , generatorBody , environment .getFunctionFrameDescriptor ().toFrameDescriptor (), functionData ,
574
- moduleSourceSection , internalFunctionName );
563
+ moduleSourceSection , activeScriptOrModule , internalFunctionName );
575
564
}
576
565
577
566
private static void printAST (Node functionRoot ) {
@@ -600,7 +589,8 @@ private JavaScriptNode handleAsyncFunctionBody(JavaScriptNode body) {
600
589
JSWriteFrameSlotNode writeContextNode = (JSWriteFrameSlotNode ) asyncContextVar .createWriteNode (null );
601
590
JSReadFrameSlotNode readContextNode = (JSReadFrameSlotNode ) asyncContextVar .createReadNode ();
602
591
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 );
604
594
}
605
595
606
596
/**
@@ -625,7 +615,8 @@ private JavaScriptNode handleGeneratorBody(JavaScriptNode body) {
625
615
VarRef yieldVar = environment .findYieldValueVar ();
626
616
JSWriteFrameSlotNode writeYieldValueNode = (JSWriteFrameSlotNode ) yieldVar .createWriteNode (null );
627
617
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 );
629
620
}
630
621
631
622
private JavaScriptNode handleAsyncGeneratorBody (JavaScriptNode body ) {
@@ -637,7 +628,8 @@ private JavaScriptNode handleAsyncGeneratorBody(JavaScriptNode body) {
637
628
JSReadFrameSlotNode readAsyncContextNode = (JSReadFrameSlotNode ) asyncContextVar .createReadNode ();
638
629
JSWriteFrameSlotNode writeYieldValueNode = (JSWriteFrameSlotNode ) yieldVar .createWriteNode (null );
639
630
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 );
641
633
}
642
634
643
635
private JavaScriptNode handleModuleBody (JavaScriptNode body ) {
@@ -648,7 +640,8 @@ private JavaScriptNode handleModuleBody(JavaScriptNode body) {
648
640
VarRef yieldVar = environment .findAsyncResultVar ();
649
641
JSWriteFrameSlotNode writeAsyncContextNode = (JSWriteFrameSlotNode ) asyncContextVar .createWriteNode (null );
650
642
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 );
652
645
} else {
653
646
JavaScriptNode instrumentedBody = instrumentSuspendNodes (body );
654
647
return factory .createModuleBody (instrumentedBody );
@@ -1867,10 +1860,6 @@ private JavaScriptNode getActiveModule() {
1867
1860
return environment .findActiveModule ().createReadNode ();
1868
1861
}
1869
1862
1870
- private JavaScriptNode getActiveScriptOrModule () {
1871
- return environment .findActiveScriptOrModule ().createReadNode ();
1872
- }
1873
-
1874
1863
private VarRef findScopeVar (TruffleString name , boolean skipWith ) {
1875
1864
return environment .findVar (name , skipWith );
1876
1865
}
@@ -2640,7 +2629,8 @@ private JavaScriptNode initializeInstanceElements(JavaScriptNode thisValueNode)
2640
2629
private JavaScriptNode createCallEvalNode (JavaScriptNode function , JavaScriptNode [] args ) {
2641
2630
assert (currentFunction ().isGlobal () || currentFunction ().isStrictMode () || currentFunction ().isDirectEval ()) || currentFunction ().isDynamicallyScoped ();
2642
2631
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 ),
2644
2634
environment .getCurrentBlockScopeSlot ());
2645
2635
}
2646
2636
@@ -2659,7 +2649,6 @@ private JavaScriptNode createCallDirectSuper(JavaScriptNode function, JavaScript
2659
2649
2660
2650
private JavaScriptNode createImportCallNode (JavaScriptNode [] args ) {
2661
2651
assert args .length == 1 || (context .getContextOptions ().isImportAssertions () && args .length == 2 );
2662
- JavaScriptNode activeScriptOrModule = getActiveScriptOrModule ();
2663
2652
if (context .getContextOptions ().isImportAssertions () && args .length == 2 ) {
2664
2653
return factory .createImportCall (context , args [0 ], activeScriptOrModule , args [1 ]);
2665
2654
}
0 commit comments