12
12
import com .oracle .truffle .api .dsl .NeverDefault ;
13
13
import org .truffleruby .core .array .RubyArray ;
14
14
import org .truffleruby .language .RubyBaseNodeWithExecute ;
15
- import org .truffleruby .language .control .RaiseException ;
16
- import org .truffleruby .language .dispatch .DispatchNode ;
17
15
18
16
import com .oracle .truffle .api .dsl .Cached ;
19
17
import com .oracle .truffle .api .dsl .NodeChild ;
20
18
import com .oracle .truffle .api .dsl .Specialization ;
21
- import com . oracle . truffle . api . profiles . BranchProfile ;
19
+ import org . truffleruby . language . dispatch . DispatchNode ;
22
20
23
21
@ NodeChild (value = "childNode" , type = RubyBaseNodeWithExecute .class )
24
22
public abstract class ToAryNode extends RubyBaseNodeWithExecute {
@@ -43,30 +41,13 @@ protected RubyArray coerceRubyArray(RubyArray array) {
43
41
44
42
@ Specialization (guards = "!isRubyArray(object)" )
45
43
protected RubyArray coerceObject (Object object ,
46
- @ Cached BranchProfile errorProfile ,
47
44
@ Cached DispatchNode toAryNode ) {
48
- final Object coerced ;
49
- try {
50
- coerced = toAryNode .call (object , "to_ary" );
51
- } catch (RaiseException e ) {
52
- errorProfile .enter ();
53
- if (e .getException ().getLogicalClass () == coreLibrary ().noMethodErrorClass ) {
54
- throw new RaiseException (
55
- getContext (),
56
- coreExceptions ().typeErrorNoImplicitConversion (object , "Array" , this ));
57
- } else {
58
- throw e ;
59
- }
60
- }
61
-
62
- if (coerced instanceof RubyArray ) {
63
- return (RubyArray ) coerced ;
64
- } else {
65
- errorProfile .enter ();
66
- throw new RaiseException (
67
- getContext (),
68
- coreExceptions ().typeErrorBadCoercion (object , "Array" , "to_ary" , coerced , this ));
69
- }
45
+ return (RubyArray ) toAryNode .call (
46
+ coreLibrary ().truffleTypeModule ,
47
+ "rb_convert_type" ,
48
+ object ,
49
+ coreLibrary ().arrayClass ,
50
+ coreSymbols ().TO_ARY );
70
51
}
71
52
72
53
@ Override
0 commit comments