@@ -233,7 +233,7 @@ abstract static class PolyglotExportNode extends JSBuiltinNode {
233233
234234 @ Specialization
235235 protected Object doString (TruffleString identifier , Object value ,
236- @ Shared ( "interop" ) @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ) {
236+ @ Shared @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ) {
237237 Object polyglotBindings ;
238238 try {
239239 polyglotBindings = getRealm ().getEnv ().getPolyglotBindings ();
@@ -247,14 +247,10 @@ protected Object doString(TruffleString identifier, Object value,
247247 @ InliningCutoff
248248 @ Specialization (guards = {"!isString(identifier)" })
249249 protected Object doMaybeUnbox (TruffleObject identifier , Object value ,
250- @ Shared ("interop" ) @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ) {
250+ @ Shared @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
251+ @ Cached TruffleString .SwitchEncodingNode switchEncoding ) {
251252 if (interop .isString (identifier )) {
252- TruffleString unboxed ;
253- try {
254- unboxed = interop .asTruffleString (identifier );
255- } catch (UnsupportedMessageException e ) {
256- throw Errors .createTypeErrorUnboxException (identifier , e , this );
257- }
253+ TruffleString unboxed = Strings .interopAsTruffleString (identifier , interop , switchEncoding );
258254 return doString (unboxed , value , interop );
259255 }
260256 return doInvalid (identifier , value );
@@ -275,16 +271,17 @@ abstract static class PolyglotImportNode extends JSBuiltinNode {
275271
276272 @ Specialization
277273 protected Object doString (TruffleString identifier ,
278- @ Shared ("interop" ) @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
279- @ Shared ("importValue" ) @ Cached ImportValueNode importValueNode ) {
274+ @ Shared @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
275+ @ Shared @ Cached ImportValueNode importValueNode ,
276+ @ Shared @ Cached TruffleString .ToJavaStringNode toJavaStringNode ) {
280277 Object polyglotBindings ;
281278 try {
282279 polyglotBindings = getRealm ().getEnv ().getPolyglotBindings ();
283280 } catch (SecurityException e ) {
284281 throw Errors .createErrorFromException (e );
285282 }
286283 try {
287- return importValueNode .executeWithTarget (interop .readMember (polyglotBindings , Strings .toJavaString (identifier )));
284+ return importValueNode .executeWithTarget (interop .readMember (polyglotBindings , Strings .toJavaString (toJavaStringNode , identifier )));
288285 } catch (UnknownIdentifierException e ) {
289286 return Undefined .instance ;
290287 } catch (UnsupportedMessageException e ) {
@@ -295,16 +292,13 @@ protected Object doString(TruffleString identifier,
295292 @ InliningCutoff
296293 @ Specialization (guards = {"!isString(identifier)" })
297294 protected Object doMaybeUnbox (TruffleObject identifier ,
298- @ Shared ("interop" ) @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
299- @ Shared ("importValue" ) @ Cached ImportValueNode importValueNode ) {
295+ @ Shared @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
296+ @ Shared @ Cached ImportValueNode importValueNode ,
297+ @ Shared @ Cached TruffleString .ToJavaStringNode toJavaStringNode ,
298+ @ Cached TruffleString .SwitchEncodingNode switchEncoding ) {
300299 if (interop .isString (identifier )) {
301- TruffleString unboxed ;
302- try {
303- unboxed = interop .asTruffleString (identifier );
304- } catch (UnsupportedMessageException e ) {
305- throw Errors .createTypeErrorUnboxException (identifier , e , this );
306- }
307- return doString (unboxed , interop , importValueNode );
300+ TruffleString unboxed = Strings .interopAsTruffleString (identifier , interop , switchEncoding );
301+ return doString (unboxed , interop , importValueNode , toJavaStringNode );
308302 }
309303 return doInvalid (identifier );
310304 }
@@ -450,10 +444,11 @@ protected Object arrayElement(TruffleObject obj, Number index,
450444 protected Object unsupportedKey (TruffleObject obj , Object key ,
451445 @ Shared ("importValue" ) @ Cached ImportValueNode foreignConvert ,
452446 @ Shared ("interop" ) @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
453- @ Exclusive @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary keyInterop ) {
447+ @ Exclusive @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary keyInterop ,
448+ @ Cached TruffleString .SwitchEncodingNode switchEncoding ) {
454449 try {
455450 if (keyInterop .isString (key )) {
456- return member (obj , keyInterop . asTruffleString (key ), foreignConvert , interop );
451+ return member (obj , Strings . interopAsTruffleString (key , keyInterop , switchEncoding ), foreignConvert , interop );
457452 } else if (keyInterop .fitsInInt (key )) {
458453 return arrayElement (obj , keyInterop .asInt (key ), foreignConvert , interop );
459454 }
@@ -530,10 +525,11 @@ protected Object unsupportedKey(TruffleObject obj, Object key, Object value,
530525 @ Shared ("exportValue" ) @ Cached ExportValueNode exportValue ,
531526 @ Shared ("interop" ) @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
532527 @ Exclusive @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary keyInterop ,
533- @ Shared ("toJavaString" ) @ Cached TruffleString .ToJavaStringNode toJavaStringNode ) {
528+ @ Shared ("toJavaString" ) @ Cached TruffleString .ToJavaStringNode toJavaStringNode ,
529+ @ Cached TruffleString .SwitchEncodingNode switchEncoding ) {
534530 try {
535531 if (keyInterop .isString (key )) {
536- return member (obj , keyInterop . asTruffleString (key ), value , exportValue , interop , toJavaStringNode );
532+ return member (obj , Strings . interopAsTruffleString (key , keyInterop , switchEncoding ), value , exportValue , interop , toJavaStringNode );
537533 } else if (keyInterop .fitsInInt (key )) {
538534 return arrayElement (obj , keyInterop .asInt (key ), value , exportValue , interop );
539535 }
@@ -603,10 +599,11 @@ protected boolean arrayElement(TruffleObject obj, Number index,
603599 protected Object unsupportedKey (TruffleObject obj , Object key ,
604600 @ Shared ("interop" ) @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary interop ,
605601 @ Exclusive @ CachedLibrary (limit = "InteropLibraryLimit" ) InteropLibrary keyInterop ,
606- @ Shared ("toJavaString" ) @ Cached TruffleString .ToJavaStringNode toJavaStringNode ) {
602+ @ Shared ("toJavaString" ) @ Cached TruffleString .ToJavaStringNode toJavaStringNode ,
603+ @ Cached TruffleString .SwitchEncodingNode switchEncoding ) {
607604 try {
608605 if (keyInterop .isString (key )) {
609- return member (obj , keyInterop . asTruffleString (key ), interop , toJavaStringNode );
606+ return member (obj , Strings . interopAsTruffleString (key , keyInterop , switchEncoding ), interop , toJavaStringNode );
610607 } else if (keyInterop .fitsInInt (key )) {
611608 return arrayElementInt (obj , keyInterop .asInt (key ), interop );
612609 }
0 commit comments