Skip to content

Commit

Permalink
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 0 additions & 1 deletion spec/truffle/tags/core/string/encode_tags.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
fails:String#encode when passed no options transcodes to Encoding.default_internal when set
fails:String#encode when passed no options transcodes a 7-bit String despite no generic converting being available
fails:String#encode when passed no options raises an Encoding::ConverterNotFoundError when no conversion is possible
fails:String#encode when passed to encoding calls #to_str to convert the object to an Encoding
fails:String#encode when passed to encoding transcodes a 7-bit String despite no generic converting being available
fails:String#encode when passed to encoding raises an Encoding::ConverterNotFoundError when no conversion is possible
fails:String#encode when passed to encoding raises an Encoding::ConverterNotFoundError for an invalid encoding
Original file line number Diff line number Diff line change
@@ -796,6 +796,8 @@ public boolean empty(RubyString string) {
@CoreMethod(names = "encode", required = 1)
public abstract static class EncodeNode extends CoreMethodNode {

@Child private ToStrNode toStrNode;

public EncodeNode(RubyContext context, SourceSection sourceSection) {
super(context, sourceSection);
}
@@ -825,6 +827,18 @@ public RubyString encode(RubyString string, RubyEncoding encoding) {

return getContext().toTruffle(jrubyTranscoded);
}

@Specialization(guards = { "!isRubyString(arguments[1])", "!isRubyEncoding(arguments[1])" })
public RubyString encode(VirtualFrame frame, RubyString string, Object encoding) {
notDesignedForCompilation();

if (toStrNode == null) {
CompilerDirectives.transferToInterpreter();
toStrNode = insert(ToStrNodeFactory.create(getContext(), getSourceSection(), null));
}

return encode(string, toStrNode.executeRubyString(frame, encoding));
}
}

@CoreMethod(names = "encoding")

0 comments on commit 226e682

Please sign in to comment.