File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ All notable changes to this project will be documented in this file.
55
66## [ 14.1.0.2]
77### Added
8+ - Berry ` classof ` extended to class methods
89
910### Breaking Changed
1011
Original file line number Diff line number Diff line change @@ -544,6 +544,22 @@ BERRY_API bbool be_classof(bvm *vm, int index)
544544 binstance * ins = var_toobj (v );
545545 var_setclass (top , be_instance_class (ins ));
546546 return btrue ;
547+ } else if (var_isclosure (v )) {
548+ bclosure * cl = var_toobj (v );
549+ bproto * pr = cl -> proto ;
550+ if (pr != NULL ) {
551+ bclass * cla ;
552+ if (pr -> nproto > 0 ) {
553+ cla = (bclass * ) pr -> ptab [pr -> nproto ];
554+ } else {
555+ cla = (bclass * ) pr -> ptab ;
556+ }
557+ if (cla && var_basetype (cla ) == BE_CLASS ) {
558+ bvalue * top = be_incrtop (vm );
559+ var_setclass (top , cla );
560+ return btrue ;
561+ }
562+ }
547563 }
548564 return bfalse ;
549565}
Original file line number Diff line number Diff line change @@ -57,4 +57,19 @@ c4 = Test_class()
5757assert ( type ( c4.c ) == 'class' )
5858c5 = c4.c ()
5959assert ( type ( c5) == 'instance' )
60- assert ( classname ( c5) == 'map' )
60+ assert ( classname ( c5) == 'map' )
61+
62+ #- classof now gets back the class of Berry methods -#
63+ class A
64+ def f () end
65+ static def g () end
66+ end
67+ class B : A
68+ def h () end
69+ end
70+ assert ( classof ( A.f ) == A)
71+ assert ( classof ( A.g ) == A)
72+ assert ( classof ( B.h ) == B)
73+ #- returns nil if native function of not in class -#
74+ assert ( classof ( int) == nil )
75+ assert ( classof ( def () end ) == nil )
You can’t perform that action at this time.
0 commit comments