12
12
import com .oracle .truffle .api .CompilerDirectives .TruffleBoundary ;
13
13
import com .oracle .truffle .api .interop .InteropLibrary ;
14
14
import com .oracle .truffle .api .interop .TruffleObject ;
15
- import com .oracle .truffle .api .interop . UnsupportedMessageException ;
15
+ import com .oracle .truffle .api .library . CachedLibrary ;
16
16
import com .oracle .truffle .api .library .ExportLibrary ;
17
17
import com .oracle .truffle .api .library .ExportMessage ;
18
18
import com .oracle .truffle .api .library .Message ;
19
19
import com .oracle .truffle .api .library .ReflectionLibrary ;
20
+ import org .truffleruby .RubyContext ;
21
+ import org .truffleruby .language .control .RaiseException ;
20
22
21
23
@ ExportLibrary (ReflectionLibrary .class )
22
24
public class BoxedValue implements TruffleObject {
@@ -32,11 +34,13 @@ public BoxedValue(Object value) {
32
34
33
35
@ TruffleBoundary
34
36
@ ExportMessage
35
- protected Object send (Message message , Object [] args ) throws Exception {
36
- if (message == READ_MEMBER ) {
37
- throw UnsupportedMessageException .create ();
38
- } else if (message == INVOKE_MEMBER ) {
39
- throw UnsupportedMessageException .create ();
37
+ protected Object send (Message message , Object [] args ,
38
+ @ CachedLibrary ("this" ) ReflectionLibrary node ) throws Exception {
39
+ if (message == READ_MEMBER || message == INVOKE_MEMBER ) {
40
+ RubyContext context = RubyContext .get (node );
41
+ throw new RaiseException (context , context .getCoreExceptions ().unsupportedMessageError (
42
+ "Methods should not be called on a BoxedValue as that would expose the potential Ruby object behind rather than relying on interop messages" ,
43
+ node ));
40
44
}
41
45
ReflectionLibrary reflection = ReflectionLibrary .getFactory ().getUncached ();
42
46
return reflection .send (value , message , args );
0 commit comments