121121import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
122122import com .oracle .truffle .api .RootCallTarget ;
123123import com .oracle .truffle .api .TruffleFile ;
124- import com .oracle .truffle .api .TruffleLanguage ;
125124import com .oracle .truffle .api .TruffleLanguage .Env ;
126125import com .oracle .truffle .api .TruffleLogger ;
127126import com .oracle .truffle .api .dsl .Cached ;
@@ -768,7 +767,8 @@ private void validate(HashingStorage dictStorage) {
768767 @ GenerateNodeFactory
769768 public abstract static class JavaExtendNode extends PythonUnaryBuiltinNode {
770769 @ Specialization
771- Object doIt (Object value ) {
770+ Object doIt (Object value ,
771+ @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
772772 if (ImageInfo .inImageBuildtimeCode ()) {
773773 CompilerDirectives .transferToInterpreterAndInvalidate ();
774774 throw new UnsupportedOperationException (ErrorMessages .CANT_EXTEND_JAVA_CLASS_NOT_JVM );
@@ -779,21 +779,19 @@ Object doIt(Object value) {
779779 }
780780
781781 Env env = getContext ().getEnv ();
782- if (!isType (value , env )) {
782+ if (!isType (value , env , lib )) {
783783 throw raise (TypeError , ErrorMessages .CANT_EXTEND_JAVA_CLASS_NOT_TYPE , value );
784784 }
785785
786- final Class <?>[] types = new Class <?>[1 ];
787- types [0 ] = (Class <?>) env .asHostObject (value );
788786 try {
789- return env .createHostAdapterClass ( types );
787+ return env .createHostAdapter ( new Object []{ value } );
790788 } catch (Exception ex ) {
791789 throw raise (TypeError , ex .getMessage (), ex );
792790 }
793791 }
794792
795- protected static boolean isType (Object obj , TruffleLanguage . Env env ) {
796- return env .isHostObject (obj ) && env .asHostObject (obj ) instanceof Class <?> ;
793+ protected static boolean isType (Object obj , Env env , InteropLibrary lib ) {
794+ return env .isHostObject (obj ) && ( env .isHostSymbol (obj ) || lib . isMetaObject ( obj )) ;
797795 }
798796
799797 }
0 commit comments