Skip to content

Commit 7cfcb70

Browse files
committed
Kernel#Pathname returns argument when it is a Pathname
1 parent 8eca629 commit 7cfcb70

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

lib/truffle/pathname.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# truffleruby_primitives: true
12
#
23
# = pathname.rb
34
#
@@ -1068,6 +1069,7 @@ module Kernel
10681069
#
10691070
# This method is available since 1.8.5.
10701071
def Pathname(path) # :doc:
1072+
return path if Primitive.class_of(path) == Pathname
10711073
Pathname.new(path)
10721074
end
10731075
private :Pathname # Truffle: private as in MRI

lib/truffle/truffle/cext.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,10 @@ def rb_obj_classname(object)
386386
object.class.name
387387
end
388388

389+
def rb_class_of(object)
390+
Primitive.class_of(object)
391+
end
392+
389393
def rb_class_real(ruby_class)
390394
while ruby_class.singleton_class?
391395
ruby_class = ruby_class.superclass

lib/truffle/truffle/cext_structs.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ def polyglot_read_member(name)
224224
when 'flags'
225225
compute_flags
226226
when 'klass'
227-
Primitive.cext_wrap(Truffle::CExt.rb_class_of(@object))
227+
Primitive.cext_wrap(Primitive.class_of(@object))
228228
else
229229
raise Truffle::Interop::UnknownIdentifierException
230230
end

src/main/java/org/truffleruby/cext/CExtNodes.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -458,17 +458,6 @@ protected Object dbl2big(double num,
458458

459459
}
460460

461-
@CoreMethod(names = "rb_class_of", onSingleton = true, required = 1)
462-
public abstract static class RBClassOfNode extends CoreMethodArrayArgumentsNode {
463-
464-
@Specialization
465-
protected RubyClass rb_class_of(Object object,
466-
@Cached MetaClassNode metaClassNode) {
467-
return metaClassNode.execute(object);
468-
}
469-
470-
}
471-
472461
@CoreMethod(names = "rb_long2int", onSingleton = true, required = 1)
473462
public abstract static class Long2Int extends CoreMethodArrayArgumentsNode {
474463

src/main/java/org/truffleruby/core/support/TypeNodes.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
import org.truffleruby.language.library.RubyLibrary;
4747
import org.truffleruby.language.objects.IsANode;
4848
import org.truffleruby.language.objects.LogicalClassNode;
49+
import org.truffleruby.language.objects.MetaClassNode;
4950
import org.truffleruby.language.objects.WriteObjectFieldNode;
5051

5152
import com.oracle.truffle.api.CompilerDirectives.TruffleBoundary;
@@ -100,6 +101,17 @@ protected RubyClass objectClass(Object object) {
100101

101102
}
102103

104+
@Primitive(name = "class_of")
105+
public abstract static class ClassOfNode extends PrimitiveArrayArgumentsNode {
106+
107+
@Specialization
108+
protected RubyClass classOf(Object object,
109+
@Cached MetaClassNode metaClassNode) {
110+
return metaClassNode.execute(object);
111+
}
112+
113+
}
114+
103115
@Primitive(name = "object_equal")
104116
public static abstract class ObjectEqualNode extends PrimitiveArrayArgumentsNode {
105117

test/mri/excludes/TestPathname.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,5 +41,4 @@
4141
exclude :test_freeze_and_taint, "needs investigation"
4242
exclude :test_glob, "needs investigation"
4343
exclude :test_relative_path_from_mock, "needs investigation"
44-
exclude :test_global_constructor, "needs investigation"
4544
exclude :test_readlines_opts, "needs investigation"

0 commit comments

Comments
 (0)