Skip to content

Commit

Permalink
fix: fixed the instantiation of spec objects with ScalaJS
Browse files Browse the repository at this point in the history
  • Loading branch information
symbiont-eric-torreborre committed Feb 29, 2020
1 parent a4835eb commit 9921898
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions common/js-native/src/main/scala/org/specs2/reflect/Classes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,26 @@ trait Classes extends ClassOperations {
type EnableReflectiveInstantiation =
org.portablescala.reflect.annotation.EnableReflectiveInstantiation

def loadModule(name: String, loader: ClassLoader): Any =
def newInstance(name: String, loader: ClassLoader): Any =
Reflect
.lookupInstantiatableClass(name, loader)
.getOrElse(throw new ClassNotFoundException(name))
.newInstance

def loadModule(name: String, loader: ClassLoader): Any =
Reflect
.lookupLoadableModuleClass(name, loader)
.getOrElse(throw new ClassNotFoundException(name))
.loadModule

def createInstance[T <: AnyRef](className: String)(implicit m: ClassTag[T]): Operation[T] =
throw new Exception("Classes.createInstance: no js implementation")

def createInstance[T <: AnyRef](className: String, loader: ClassLoader, defaultInstances: =>List[AnyRef] = Nil)(implicit m: ClassTag[T]): Operation[T] =
protect[OperationStack, T](loadModule(className, loader).asInstanceOf[T])
if (className.endsWith("$"))
protect[OperationStack, T](loadModule(className, loader).asInstanceOf[T])
else
protect[OperationStack, T](newInstance(className, loader).asInstanceOf[T])

def createInstanceFromClass[T <: AnyRef](klass: Class[T], defaultInstances: =>List[AnyRef])(implicit m: ClassTag[T]): Operation[T] = {
Use(m)
Expand Down

0 comments on commit 9921898

Please sign in to comment.