4141package com .oracle .truffle .js .builtins ;
4242
4343import java .util .EnumSet ;
44+ import java .util .Objects ;
4445import java .util .concurrent .atomic .AtomicReference ;
4546
4647import com .oracle .truffle .api .Assumption ;
@@ -2139,7 +2140,7 @@ protected final JSFunctionObject doCached(String paramList, String body, String
21392140 @ Specialization (replaces = "doCached" )
21402141 protected final JSFunctionObject doUncached (String paramList , String body , String sourceName , ScriptOrModule activeScriptOrModule ,
21412142 @ Cached ("createCache()" ) LRUCache <CachedSourceKey , ScriptNode > cache ) {
2142- ScriptNode cached = cacheLookup (cache , new CachedSourceKey ( paramList , body , sourceName , activeScriptOrModule ) );
2143+ ScriptNode cached = cacheLookup (cache , paramList , body , sourceName , activeScriptOrModule );
21432144 JSRealm realm = getRealm ();
21442145 if (cached == null ) {
21452146 return parseAndEvalFunction (cache , realm , paramList , body , sourceName , activeScriptOrModule );
@@ -2149,9 +2150,9 @@ protected final JSFunctionObject doUncached(String paramList, String body, Strin
21492150 }
21502151
21512152 @ TruffleBoundary
2152- protected ScriptNode cacheLookup (LRUCache <CachedSourceKey , ScriptNode > cache , CachedSourceKey sourceKey ) {
2153+ protected ScriptNode cacheLookup (LRUCache <CachedSourceKey , ScriptNode > cache , String paramList , String body , String sourceName , ScriptOrModule activeScriptOrModule ) {
21532154 synchronized (cache ) {
2154- return cache .get (sourceKey );
2155+ return cache .get (new CachedSourceKey ( paramList , body , sourceName , activeScriptOrModule ) );
21552156 }
21562157 }
21572158
@@ -2180,7 +2181,48 @@ AssumedValue<ScriptNode> createAssumedValue() {
21802181 return new AssumedValue <>("parsedFunction" , null );
21812182 }
21822183
2183- protected record CachedSourceKey (String paramList , String body , String sourceName , ScriptOrModule activeScriptOrModule ) {
2184+ protected static final class CachedSourceKey {
2185+ private final String paramList ;
2186+ private final String body ;
2187+ private final String sourceName ;
2188+ private final ScriptOrModule activeScriptOrModule ;
2189+
2190+ protected CachedSourceKey (String paramList , String body , String sourceName , ScriptOrModule activeScriptOrModule ) {
2191+ this .paramList = paramList ;
2192+ this .body = body ;
2193+ this .sourceName = sourceName ;
2194+ this .activeScriptOrModule = activeScriptOrModule ;
2195+ }
2196+
2197+ public String paramList () {
2198+ return paramList ;
2199+ }
2200+
2201+ public String body () {
2202+ return body ;
2203+ }
2204+
2205+ public String sourceName () {
2206+ return sourceName ;
2207+ }
2208+
2209+ public ScriptOrModule activeScriptOrModule () {
2210+ return activeScriptOrModule ;
2211+ }
2212+
2213+ @ Override
2214+ public boolean equals (Object obj ) {
2215+ return this == obj || (obj instanceof CachedSourceKey that &&
2216+ Objects .equals (this .paramList , that .paramList ) &&
2217+ Objects .equals (this .body , that .body ) &&
2218+ Objects .equals (this .sourceName , that .sourceName ) &&
2219+ Objects .equals (this .activeScriptOrModule , that .activeScriptOrModule ));
2220+ }
2221+
2222+ @ Override
2223+ public int hashCode () {
2224+ return Objects .hash (paramList , body , sourceName , activeScriptOrModule );
2225+ }
21842226 }
21852227 }
21862228
0 commit comments