|
32 | 32 | import org.truffleruby.core.string.StringOperations;
|
33 | 33 | import org.truffleruby.core.string.StringUtils;
|
34 | 34 | import org.truffleruby.language.RubyGuards;
|
| 35 | +import org.truffleruby.language.control.RaiseException; |
35 | 36 | import org.truffleruby.language.dispatch.CallDispatchHeadNode;
|
36 | 37 | import org.truffleruby.language.dispatch.DoesRespondDispatchHeadNode;
|
37 | 38 |
|
@@ -219,9 +220,28 @@ protected Object access(VirtualFrame frame, DynamicObject object) {
|
219 | 220 | public static abstract class ReadNode extends Node {
|
220 | 221 |
|
221 | 222 | @Child private ForeignReadStringCachingHelperNode helperNode = ForeignReadStringCachingHelperNodeGen.create();
|
| 223 | + private final ConditionProfile whichErrorProfile = ConditionProfile.createBinaryProfile(); |
222 | 224 |
|
223 | 225 | protected Object access(VirtualFrame frame, DynamicObject object, Object name) {
|
224 |
| - return helperNode.executeStringCachingHelper(frame, object, name); |
| 226 | + try { |
| 227 | + return helperNode.executeStringCachingHelper(frame, object, name); |
| 228 | + } catch (RaiseException ex) { |
| 229 | + if (whichErrorProfile.profile(Layouts.NAME_ERROR.isNameError(ex.getException()))) { |
| 230 | + try { |
| 231 | + return UnknownIdentifierException.raise(toString(name)); |
| 232 | + } catch (Throwable unknownIdentifier) { |
| 233 | + unknownIdentifier.initCause(ex); |
| 234 | + throw unknownIdentifier; |
| 235 | + } |
| 236 | + } else { |
| 237 | + throw ex; |
| 238 | + } |
| 239 | + } |
| 240 | + } |
| 241 | + |
| 242 | + @TruffleBoundary |
| 243 | + private static String toString(Object name) { |
| 244 | + return name.toString(); |
225 | 245 | }
|
226 | 246 |
|
227 | 247 | }
|
|
0 commit comments