Skip to content

Commit

Permalink
Showing 3 changed files with 11 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1599,7 +1599,7 @@ public boolean requireRelative(DynamicObject feature) {

if (sourcePath == null) {
CompilerDirectives.transferToInterpreter();
throw new RaiseException(getContext().getCoreLibrary().loadError("cannot infer basepath", this));
throw new RaiseException(getContext().getCoreLibrary().loadError("cannot infer basepath", featureString, this));
}

featurePath = dirname(sourcePath) + "/" + featureString;
Original file line number Diff line number Diff line change
@@ -744,16 +744,13 @@ public RubyContext context() {
@CoreMethod(names = "load", isModuleFunction = true, required = 1, optional = 1)
public abstract static class LoadNode extends CoreMethodArrayArgumentsNode {

@Child private CallDispatchHeadNode pathCall;

public LoadNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
pathCall = DispatchHeadNodeFactory.createMethodCall(getContext());
}

@TruffleBoundary
@Specialization(guards = "isRubyString(file)")
public boolean load(VirtualFrame frame, DynamicObject file, boolean wrap) {
public boolean load(DynamicObject file, boolean wrap) {
if (wrap) {
throw new UnsupportedOperationException();
}
@@ -762,18 +759,15 @@ public boolean load(VirtualFrame frame, DynamicObject file, boolean wrap) {
getContext().loadFile(StringOperations.getString(getContext(), file), this);
} catch (IOException e) {
CompilerDirectives.transferToInterpreter();
final DynamicObject rubyException = getContext().getCoreLibrary().loadErrorCannotLoad(file.toString(), this);
pathCall.call(frame, rubyException, "path=", null, file);

throw new RaiseException(rubyException);
throw new RaiseException(getContext().getCoreLibrary().loadErrorCannotLoad(file.toString(), this));
}

return true;
}

@Specialization(guards = "isRubyString(file)")
public boolean load(VirtualFrame frame, DynamicObject file, NotProvided wrap) {
return load(frame, file, false);
public boolean load(DynamicObject file, NotProvided wrap) {
return load(file, false);
}
}

Original file line number Diff line number Diff line change
@@ -1192,14 +1192,17 @@ public DynamicObject privateMethodError(String name, Object self, Node currentNo
return noMethodError(String.format("private method `%s' called for %s", name, className), name, currentNode);
}

public DynamicObject loadError(String message, Node currentNode) {
public DynamicObject loadError(String message, String path, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return ExceptionNodes.createRubyException(context.getCoreLibrary().getLoadErrorClass(), StringOperations.createString(context, StringOperations.encodeByteList(message, UTF8Encoding.INSTANCE)), RubyCallStack.getBacktrace(currentNode));
DynamicObject messageString = StringOperations.createString(context, StringOperations.encodeByteList(message, UTF8Encoding.INSTANCE));
DynamicObject loadError = ExceptionNodes.createRubyException(context.getCoreLibrary().getLoadErrorClass(), messageString, RubyCallStack.getBacktrace(currentNode));
loadError.define("@path", StringOperations.createString(context, StringOperations.encodeByteList(path, UTF8Encoding.INSTANCE)));
return loadError;
}

public DynamicObject loadErrorCannotLoad(String name, Node currentNode) {
CompilerAsserts.neverPartOfCompilation();
return loadError(String.format("cannot load such file -- %s", name), currentNode);
return loadError(String.format("cannot load such file -- %s", name), name, currentNode);
}

public DynamicObject zeroDivisionError(Node currentNode) {

0 comments on commit 43ba917

Please sign in to comment.