121
121
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
122
122
import com .oracle .truffle .api .RootCallTarget ;
123
123
import com .oracle .truffle .api .TruffleFile ;
124
- import com .oracle .truffle .api .TruffleLanguage ;
125
124
import com .oracle .truffle .api .TruffleLanguage .Env ;
126
125
import com .oracle .truffle .api .TruffleLogger ;
127
126
import com .oracle .truffle .api .dsl .Cached ;
@@ -768,7 +767,8 @@ private void validate(HashingStorage dictStorage) {
768
767
@ GenerateNodeFactory
769
768
public abstract static class JavaExtendNode extends PythonUnaryBuiltinNode {
770
769
@ Specialization
771
- Object doIt (Object value ) {
770
+ Object doIt (Object value ,
771
+ @ CachedLibrary (limit = "3" ) InteropLibrary lib ) {
772
772
if (ImageInfo .inImageBuildtimeCode ()) {
773
773
CompilerDirectives .transferToInterpreterAndInvalidate ();
774
774
throw new UnsupportedOperationException (ErrorMessages .CANT_EXTEND_JAVA_CLASS_NOT_JVM );
@@ -779,21 +779,19 @@ Object doIt(Object value) {
779
779
}
780
780
781
781
Env env = getContext ().getEnv ();
782
- if (!isType (value , env )) {
782
+ if (!isType (value , env , lib )) {
783
783
throw raise (TypeError , ErrorMessages .CANT_EXTEND_JAVA_CLASS_NOT_TYPE , value );
784
784
}
785
785
786
- final Class <?>[] types = new Class <?>[1 ];
787
- types [0 ] = (Class <?>) env .asHostObject (value );
788
786
try {
789
- return env .createHostAdapterClass ( types );
787
+ return env .createHostAdapter ( new Object []{ value } );
790
788
} catch (Exception ex ) {
791
789
throw raise (TypeError , ex .getMessage (), ex );
792
790
}
793
791
}
794
792
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 )) ;
797
795
}
798
796
799
797
}
0 commit comments