@@ -75,31 +75,9 @@ private LookupConstantNode getLookupConstantNode() {
75
75
return lookupConstantNode ;
76
76
}
77
77
78
- /** Reads the constant value, wrapping any exception occuring during module autoloading in an
79
- * {@link AutoloadException}. */
80
- private Object readConstantWrappingAutoloadExceptions (VirtualFrame frame ) {
81
- final Object moduleObject = moduleNode instanceof ReadConstantNode
82
- ? ((ReadConstantNode ) moduleNode ).readConstantWrappingAutoloadExceptions (frame )
83
- : moduleNode .execute (frame );
84
- final RubyModule module = checkModule (moduleObject );
85
- final RubyConstant constant = getLookupConstantNode ().lookupConstant (LexicalScope .IGNORE , module , name , true );
86
- try {
87
- return getConstant (module , constant );
88
- } catch (RaiseException e ) {
89
- if (constant .isAutoload ()) {
90
- throw new AutoloadException (e );
91
- }
92
- throw e ;
93
- }
94
- }
95
-
96
- /** Returns the evaluated module part, wrapping any exception occuring during module autoloading in an
97
- * {@link AutoloadException}. */
98
- public RubyModule evaluateModuleWrappingAutoloadExceptions (VirtualFrame frame ) {
99
- final Object moduleObject = moduleNode instanceof ReadConstantNode
100
- ? ((ReadConstantNode ) moduleNode ).readConstantWrappingAutoloadExceptions (frame )
101
- : moduleNode .execute (frame );
102
- return checkModule (moduleObject );
78
+ /** Evaluate the module part of the constant read. */
79
+ public RubyModule evaluateModule (VirtualFrame frame ) {
80
+ return checkModule (moduleNode .execute (frame ));
103
81
}
104
82
105
83
/** Whether the module part of this constant read is undefined, without attempting to evaluate it. */
@@ -109,26 +87,16 @@ public boolean isModuleTriviallyUndefined(VirtualFrame frame, RubyLanguage langu
109
87
110
88
@ Override
111
89
public Object isDefined (VirtualFrame frame , RubyLanguage language , RubyContext context ) {
112
- final RubyConstant constant = getConstantIfDefined (frame , language , context );
113
- return constant == null ? nil : coreStrings ().CONSTANT .createInstance (getContext ());
114
- }
115
-
116
- /** Returns the constant, it it is defined. Otherwise returns {@code null}. */
117
- private RubyConstant getConstantIfDefined (VirtualFrame frame , RubyLanguage language , RubyContext context ) {
118
90
if (isModuleTriviallyUndefined (frame , language , context )) {
119
- return null ;
91
+ return nil ;
120
92
}
121
-
122
- final RubyModule module ;
123
93
try {
124
- module = evaluateModuleWrappingAutoloadExceptions ( frame );
125
- } catch ( AutoloadException e ) {
126
- // If autoloading a module raised an exception,
127
- // MRI dictates that we should swallow the exception and return `nil`.
128
- return null ;
94
+ final RubyModule module = checkModule ( moduleNode . execute ( frame ) );
95
+ final RubyConstant constant = getConstantIfDefined ( module );
96
+ return constant == null ? nil : coreStrings (). CONSTANT . createInstance ( getContext ());
97
+ } catch ( RaiseException e ) {
98
+ return nil ; // MRI swallows all exceptions in defined? (MRI Bug#5786)
129
99
}
130
-
131
- return getConstantIfDefined (module );
132
100
}
133
101
134
102
/** Given the module, returns the constant, it it is defined. Otherwise returns {@code null}. */
0 commit comments