3838import static org .jruby .api .Convert .asSymbol ;
3939import static org .jruby .api .Error .*;
4040import static org .jruby .api .Warn .warn ;
41+ import static org .jruby .runtime .ObjectAllocator .NOT_ALLOCATABLE_ALLOCATOR ;
4142import static org .jruby .runtime .Visibility .PRIVATE ;
4243import static org .jruby .runtime .Visibility .PUBLIC ;
4344import static org .jruby .util .CodegenUtils .ci ;
@@ -135,7 +136,7 @@ public static void finishCreateClassClass(ThreadContext context, RubyClass Class
135136
136137 public static final ObjectAllocator CLASS_ALLOCATOR = (runtime , klass ) -> {
137138 RubyClass clazz = new RubyClass (runtime );
138- clazz .allocator = ObjectAllocator . NOT_ALLOCATABLE_ALLOCATOR ; // Class.allocate object is not allocatable before it is initialized
139+ clazz .allocator = NOT_ALLOCATABLE_ALLOCATOR ; // Class.allocate object is not allocatable before it is initialized
139140 return clazz ;
140141 };
141142
@@ -491,20 +492,26 @@ protected RubyClass(Ruby runtime, RubyClass superClazz, CallSite[] extraCallSite
491492 * and with Object as its immediate superclass.
492493 * Corresponds to rb_class_new in MRI.
493494 */
495+ @ Deprecated (since = "10.0" )
494496 public static RubyClass newClass (Ruby runtime , RubyClass superClass ) {
495497 if (superClass == runtime .getClassClass ()) throw typeError (runtime .getCurrentContext (), "can't make subclass of Class" );
496498 if (superClass .isSingleton ()) throw typeError (runtime .getCurrentContext (), "can't make subclass of virtual class" );
497499 return new RubyClass (runtime , superClass );
498500 }
499501
502+ @ Deprecated (since = "10.0" )
503+ public static RubyClass newClass (Ruby runtime , RubyClass superClass , CallSite [] extraCallSites ) {
504+ return newClass (runtime .getCurrentContext (), superClass , extraCallSites );
505+ }
506+
500507 /**
501508 * A variation on newClass that allow passing in an array of supplementary
502509 * call sites to improve dynamic invocation.
503510 */
504- public static RubyClass newClass (Ruby runtime , RubyClass superClass , CallSite [] extraCallSites ) {
505- if (superClass == runtime . getClassClass ( )) throw typeError (runtime . getCurrentContext () , "can't make subclass of Class" );
506- if (superClass .isSingleton ()) throw typeError (runtime . getCurrentContext () , "can't make subclass of virtual class" );
507- return new RubyClass (runtime , superClass , extraCallSites );
511+ public static RubyClass newClass (ThreadContext context , RubyClass superClass , CallSite [] extraCallSites ) {
512+ if (superClass == classClass ( context )) throw typeError (context , "can't make subclass of Class" );
513+ if (superClass .isSingleton ()) throw typeError (context , "can't make subclass of virtual class" );
514+ return new RubyClass (context . runtime , superClass , extraCallSites );
508515 }
509516
510517 /**
@@ -515,42 +522,76 @@ public static RubyClass newClass(Ruby runtime, RubyClass superClass, CallSite[]
515522 * Corresponds to rb_class_new/rb_define_class_id/rb_name_class/rb_set_class_path
516523 * in MRI.
517524 */
525+ @ Deprecated (since = "10.0" )
518526 public static RubyClass newClass (Ruby runtime , RubyClass superClass , String name , ObjectAllocator allocator , RubyModule parent , boolean setParent ) {
519- RubyClass clazz = newClass (runtime , superClass ).
527+ var context = runtime .getCurrentContext ();
528+ RubyClass clazz = newClass (context , superClass , null ).
520529 allocator (allocator ).
521530 baseName (name );
522531
523532 clazz .makeMetaClass (superClass .getMetaClass ());
524533 if (setParent ) clazz .setParent (parent );
525534 parent .setConstant (name , clazz );
526- clazz . inherit ( superClass );
535+ superClass . invokeInherited ( context , superClass , clazz );
527536 return clazz ;
528537 }
529538
539+ @ Deprecated (since = "10.0" )
530540 public static RubyClass newClass (Ruby runtime , RubyClass superClass , String name , ObjectAllocator allocator ,
531541 RubyModule parent , boolean setParent , String file , int line ) {
532- RubyClass clazz = newClass (runtime , superClass ).
542+ return newClass (runtime .getCurrentContext (), superClass , name , allocator , parent , setParent , file , line );
543+ }
544+
545+ public static RubyClass newClass (ThreadContext context , RubyClass superClass , String name , ObjectAllocator allocator ,
546+ RubyModule parent , boolean setParent , String file , int line ) {
547+ assert superClass != null ;
548+ RubyClass clazz = newClass (context , superClass , null ).
533549 allocator (allocator ).
534550 baseName (name );
535551 clazz .makeMetaClass (superClass .getMetaClass ());
536552 if (setParent ) clazz .setParent (parent );
537553 parent .setConstant (name , clazz , file , line );
538- clazz . inherit ( superClass );
554+ superClass . invokeInherited ( context , superClass , clazz );
539555 return clazz ;
540556 }
541557
558+ @ Deprecated (since = "10.0" )
559+ public static RubyClass newClass (Ruby runtime , RubyClass superClass , String name , ObjectAllocator allocator , RubyModule parent , boolean setParent , CallSite [] extraCallSites ) {
560+ return newClass (runtime .getCurrentContext (), superClass , name , allocator , parent , setParent , extraCallSites );
561+ }
562+
542563 /**
543564 * A variation on newClass that allows passing in an array of supplementary
544565 * call sites to improve dynamic invocation performance.
545566 */
546- public static RubyClass newClass (Ruby runtime , RubyClass superClass , String name , ObjectAllocator allocator , RubyModule parent , boolean setParent , CallSite [] extraCallSites ) {
547- RubyClass clazz = newClass (runtime , superClass , extraCallSites ).
567+ public static RubyClass newClass (ThreadContext context , RubyClass superClass , String name ,
568+ ObjectAllocator allocator , RubyModule parent , boolean setParent ,
569+ CallSite [] extraCallSites ) {
570+ RubyClass clazz = newClass (context , superClass , extraCallSites ).
548571 allocator (allocator ).
549572 baseName (name );
550573 clazz .makeMetaClass (superClass .getMetaClass ());
551574 if (setParent ) clazz .setParent (parent );
552575 parent .setConstant (name , clazz , BUILTIN_CONSTANT , -1 );
553- clazz .inherit (superClass );
576+ superClass .invokeInherited (context , superClass , clazz );
577+ return clazz ;
578+ }
579+
580+ /**
581+ * This is an internal API for bootstrapping a few classes before ThreadContext is available. The API
582+ * is intentionally limited/obtuse so no one is tempted to try and use it.
583+ *
584+ * @param runtime the runtime
585+ * @param Object reference to Object which is superclass and parent for new type
586+ * @param name the name of the new class
587+ * @return the new class.
588+ */
589+ public static RubyClass newClassBootstrap (Ruby runtime , RubyClass Object , String name ) {
590+ RubyClass clazz = new RubyClass (runtime , Object ).
591+ allocator (NOT_ALLOCATABLE_ALLOCATOR ).
592+ baseName (name );
593+ clazz .makeMetaClass (Object .getMetaClass ());
594+ Object .setConstant (name , clazz , BUILTIN_CONSTANT , -1 );
554595 return clazz ;
555596 }
556597
@@ -1029,7 +1070,7 @@ private RubyClass initializeCommon(ThreadContext context, RubyClass superClazz,
10291070
10301071 marshal = superClazz .marshal ;
10311072
1032- inherit ( superClazz );
1073+ superClazz . invokeInherited ( runtime . getCurrentContext (), superClazz , this );
10331074 super .initialize (context , block );
10341075
10351076 return this ;
@@ -1347,12 +1388,11 @@ public IRubyObject inherited(ThreadContext context, IRubyObject arg) {
13471388 /** rb_class_inherited (reversed semantics!)
13481389 *
13491390 */
1391+ @ Deprecated (since = "10.0" )
13501392 public void inherit (RubyClass superClazz ) {
13511393 if (superClazz == null ) superClazz = runtime .getObject ();
13521394
1353- if (runtime .getNil () != null ) {
1354- superClazz .invokeInherited (runtime .getCurrentContext (), superClazz , this );
1355- }
1395+ superClazz .invokeInherited (runtime .getCurrentContext (), superClazz , this );
13561396 }
13571397
13581398 /** Return the real super class of this class.
0 commit comments