@@ -456,7 +456,8 @@ class JSCodeGen()(implicit ctx: Context) {
456456 }
457457 }*/
458458
459- js.FieldDef (static = false , name, irTpe, f.is(Mutable ))
459+ val flags = js.MemberFlags .empty.withMutable(f.is(Mutable ))
460+ js.FieldDef (flags, name, irTpe)
460461 }).toList
461462 }
462463
@@ -514,7 +515,7 @@ class JSCodeGen()(implicit ctx: Context) {
514515 /* if (primitives.isPrimitive(sym)) {
515516 None
516517 } else*/ if (sym.is(Deferred )) {
517- Some (js.MethodDef (static = false , methodName,
518+ Some (js.MethodDef (js. MemberFlags .empty , methodName,
518519 jsParams, toIRType(patchedResultType(sym)), None )(
519520 OptimizerHints .empty, None ))
520521 } else /* if (isJSNativeCtorDefaultParam(sym)) {
@@ -549,15 +550,19 @@ class JSCodeGen()(implicit ctx: Context) {
549550 val body1 =
550551 if (!sym.isPrimaryConstructor) body0
551552 else moveAllStatementsAfterSuperConstructorCall(body0)
552- js.MethodDef(static = false , methodName,
553+ js.MethodDef(js.MemberFlags.empty , methodName,
553554 jsParams, jstpe.NoType, body1)(optimizerHints, None)
554- } else*/ if (sym.isConstructor) {
555- js.MethodDef (static = false , methodName,
556- jsParams, jstpe.NoType ,
555+ } else*/ if (sym.isClassConstructor) {
556+ val namespace = js.MemberNamespace .Constructor
557+ js.MethodDef (js.MemberFlags .empty.withNamespace(namespace),
558+ methodName, jsParams, jstpe.NoType ,
557559 Some (genStat(rhs)))(optimizerHints, None )
558560 } else {
561+ val namespace =
562+ if (sym.isPrivate) js.MemberNamespace .Private
563+ else js.MemberNamespace .Public
559564 val resultIRType = toIRType(patchedResultType(sym))
560- genMethodDef(static = false , methodName,
565+ genMethodDef(namespace , methodName,
561566 params, resultIRType, rhs, optimizerHints)
562567 }
563568 }
@@ -576,7 +581,7 @@ class JSCodeGen()(implicit ctx: Context) {
576581 * Methods Scala.js-defined JS classes are compiled as static methods taking
577582 * an explicit parameter for their `this` value.
578583 */
579- private def genMethodDef (static : Boolean , methodName : js.PropertyName ,
584+ private def genMethodDef (namespace : js. MemberNamespace , methodName : js.PropertyName ,
580585 paramsSyms : List [Symbol ], resultIRType : jstpe.Type ,
581586 tree : Tree , optimizerHints : OptimizerHints ): js.MethodDef = {
582587 implicit val pos = tree.span
@@ -595,10 +600,11 @@ class JSCodeGen()(implicit ctx: Context) {
595600 else genExpr(tree)
596601
597602 // if (!isScalaJSDefinedJSClass(currentClassSym)) {
598- js.MethodDef (static, methodName, jsParams, resultIRType, Some (genBody()))(
603+ val flags = js.MemberFlags .empty.withNamespace(namespace)
604+ js.MethodDef (flags, methodName, jsParams, resultIRType, Some (genBody()))(
599605 optimizerHints, None )
600606 /* } else {
601- assert(!static , tree.span)
607+ assert(!namespace.isStatic , tree.span)
602608
603609 withScopedVars(
604610 thisLocalVarIdent := Some(freshLocalIdent("this"))
@@ -962,7 +968,8 @@ class JSCodeGen()(implicit ctx: Context) {
962968 currentMethodSym.get.isClassConstructor) {
963969 isModuleInitialized = true
964970 val thisType = jstpe.ClassType (encodeClassFullName(currentClassSym))
965- val initModule = js.StoreModule (thisType, js.This ()(thisType))
971+ val initModule = js.StoreModule (encodeClassRef(currentClassSym),
972+ js.This ()(thisType))
966973 js.Block (superCall, initModule)
967974 } else {
968975 superCall
@@ -1001,12 +1008,12 @@ class JSCodeGen()(implicit ctx: Context) {
10011008 else if (clsSym == jsdefn.JSArrayClass && args.isEmpty) js.JSArrayConstr (Nil )
10021009 else js.JSNew (genLoadJSConstructor(clsSym), genActualJSArgs(ctor, args))
10031010 } else {
1004- toIRType (tpe) match {
1005- case cls : jstpe.ClassType =>
1011+ toTypeRef (tpe) match {
1012+ case cls : jstpe.ClassRef =>
10061013 js.New (cls, encodeMethodSym(ctor), genActualArgs(ctor, args))
10071014
10081015 case other =>
1009- throw new FatalError (s " Non ClassType cannot be instantiated: $other" )
1016+ throw new FatalError (s " Non ClassRef cannot be instantiated: $other" )
10101017 }
10111018 }
10121019 }
@@ -1030,7 +1037,7 @@ class JSCodeGen()(implicit ctx: Context) {
10301037 }
10311038 val newMethodIdent = js.Ident (newMethodName, origName)
10321039
1033- js.Apply (genLoadModule(moduleClass), newMethodIdent, args)(
1040+ js.Apply (js. ApplyFlags .empty, genLoadModule(moduleClass), newMethodIdent, args)(
10341041 jstpe.ClassType (encodedName))
10351042 }
10361043
@@ -1575,11 +1582,8 @@ class JSCodeGen()(implicit ctx: Context) {
15751582 genApplyJSMethodGeneric(tree, sym, genExpr(receiver), genActualJSArgs(sym, args), isStat)
15761583 /* else
15771584 genApplyJSClassMethod(genExpr(receiver), sym, genActualArgs(sym, args))*/
1578- } else if (sym.isClassConstructor) {
1579- // Calls to constructors are always statically linked
1580- genApplyMethodStatically(genExpr(receiver), sym, genActualArgs(sym, args))
15811585 } else {
1582- genApplyMethod (genExpr(receiver), sym, genActualArgs(sym, args))
1586+ genApplyMethodMaybeStatically (genExpr(receiver), sym, genActualArgs(sym, args))
15831587 }
15841588 }
15851589
@@ -1789,7 +1793,7 @@ class JSCodeGen()(implicit ctx: Context) {
17891793
17901794 val genElems = tree.elems.map(genExpr)
17911795 val arrayTypeRef = toTypeRef(tree.tpe).asInstanceOf [jstpe.ArrayTypeRef ]
1792- js.ArrayValue (jstpe. ArrayType ( arrayTypeRef) , genElems)
1796+ js.ArrayValue (arrayTypeRef, genElems)
17931797 }
17941798
17951799 /** Gen JS code for a closure.
@@ -1877,7 +1881,8 @@ class JSCodeGen()(implicit ctx: Context) {
18771881
18781882 val genBody = {
18791883 val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
1880- val call = genApplyMethod(thisCaptureRef, sym, argCaptureRefs ::: actualParams)
1884+ val call = genApplyMethodMaybeStatically(thisCaptureRef, sym,
1885+ argCaptureRefs ::: actualParams)
18811886 box(call, sym.info.finalResultType)
18821887 }
18831888
@@ -1892,7 +1897,7 @@ class JSCodeGen()(implicit ctx: Context) {
18921897 s " Invalid functional interface $funInterfaceSym reached the back-end " )
18931898 val cls = " sjsr_AnonFunction" + formalParams.size
18941899 val ctor = js.Ident (" init___sjs_js_Function" + formalParams.size)
1895- js.New (jstpe.ClassType (cls), ctor, List (closure))
1900+ js.New (jstpe.ClassRef (cls), ctor, List (closure))
18961901 }
18971902 }
18981903
@@ -1993,30 +1998,41 @@ class JSCodeGen()(implicit ctx: Context) {
19931998 }
19941999 }
19952000
2001+ /** Gen a statically linked call to an instance method. */
2002+ private def genApplyMethodMaybeStatically (receiver : js.Tree , method : Symbol ,
2003+ arguments : List [js.Tree ])(implicit pos : Position ): js.Tree = {
2004+ if (method.isPrivate || method.isClassConstructor)
2005+ genApplyMethodStatically(receiver, method, arguments)
2006+ else
2007+ genApplyMethod(receiver, method, arguments)
2008+ }
2009+
19962010 /** Gen a dynamically linked call to a Scala method. */
1997- private def genApplyMethod (receiver : js.Tree ,
1998- methodSym : Symbol , arguments : List [js.Tree ])(
2011+ private def genApplyMethod (receiver : js.Tree , method : Symbol ,
2012+ arguments : List [js.Tree ])(
19992013 implicit pos : Position ): js.Tree = {
2000- js.Apply (receiver, encodeMethodSym(methodSym), arguments)(
2001- toIRType(patchedResultType(methodSym)))
2014+ assert(! method.isPrivate,
2015+ s " Cannot generate a dynamic call to private method $method at $pos" )
2016+ js.Apply (js.ApplyFlags .empty, receiver, encodeMethodSym(method), arguments)(
2017+ toIRType(patchedResultType(method)))
20022018 }
20032019
20042020 /** Gen a statically linked call to an instance method. */
20052021 private def genApplyMethodStatically (receiver : js.Tree , method : Symbol ,
20062022 arguments : List [js.Tree ])(implicit pos : Position ): js.Tree = {
2007- val className = encodeClassFullName(method.owner)
2008- val methodIdent = encodeMethodSym(method)
2009- val resultType = toIRType(patchedResultType(method))
2010- js.ApplyStatically (receiver, jstpe.ClassType (className),
2011- methodIdent, arguments)(resultType)
2023+ val flags = js.ApplyFlags .empty
2024+ .withPrivate(method.isPrivate && ! method.isClassConstructor)
2025+ .withConstructor(method.isClassConstructor)
2026+ js.ApplyStatically (flags, receiver, encodeClassRef(method.owner),
2027+ encodeMethodSym(method), arguments)(
2028+ toIRType(patchedResultType(method)))
20122029 }
20132030
20142031 /** Gen a call to a static method. */
20152032 private def genApplyStatic (method : Symbol , arguments : List [js.Tree ])(
20162033 implicit pos : Position ): js.Tree = {
2017- val cls = jstpe.ClassType (encodeClassFullName(method.owner))
2018- val methodIdent = encodeMethodSym(method)
2019- js.ApplyStatic (cls, methodIdent, arguments)(
2034+ js.ApplyStatic (js.ApplyFlags .empty, encodeClassRef(method.owner),
2035+ encodeMethodSym(method), arguments)(
20202036 toIRType(patchedResultType(method)))
20212037 }
20222038
@@ -2264,7 +2280,7 @@ class JSCodeGen()(implicit ctx: Context) {
22642280 } else {
22652281 val inst = genLoadModule(sym.owner)
22662282 val method = encodeStaticMemberSym(sym)
2267- js.Apply (inst, method, Nil )(toIRType(sym.info))
2283+ js.Apply (js. ApplyFlags .empty, inst, method, Nil )(toIRType(sym.info))
22682284 }
22692285 }
22702286
@@ -2279,13 +2295,13 @@ class JSCodeGen()(implicit ctx: Context) {
22792295
22802296 if (isJSType(sym)) {
22812297 if (isScalaJSDefinedJSClass(sym))
2282- js.LoadJSModule (jstpe. ClassType (encodeClassFullName( sym) ))
2298+ js.LoadJSModule (encodeClassRef( sym))
22832299 /* else if (sym.derivesFrom(jsdefn.JSGlobalScopeClass))
22842300 genLoadJSGlobal()*/
22852301 else
22862302 genLoadNativeJSModule(sym)
22872303 } else {
2288- js.LoadModule (jstpe. ClassType (encodeClassFullName( sym) ))
2304+ js.LoadModule (encodeClassRef( sym))
22892305 }
22902306 }
22912307
@@ -2294,7 +2310,7 @@ class JSCodeGen()(implicit ctx: Context) {
22942310 implicit pos : Position ): js.Tree = {
22952311 assert(! isStaticModule(sym) && ! sym.is(Trait ),
22962312 s " genPrimitiveJSClass called with non-class $sym" )
2297- js.LoadJSConstructor (jstpe. ClassType (encodeClassFullName( sym) ))
2313+ js.LoadJSConstructor (encodeClassRef( sym))
22982314 }
22992315
23002316 /** Gen JS code representing a native JS module. */
@@ -2331,11 +2347,12 @@ class JSCodeGen()(implicit ctx: Context) {
23312347 protected lazy val isHijackedClass : Set [Symbol ] = {
23322348 /* This list is a duplicate of ir.Definitions.HijackedClasses, but
23332349 * with global.Symbol's instead of IR encoded names as Strings.
2350+ * We also add java.lang.Void, which BoxedUnit "erases" to.
23342351 */
23352352 Set [Symbol ](
23362353 defn.BoxedUnitClass , defn.BoxedBooleanClass , defn.BoxedCharClass , defn.BoxedByteClass ,
23372354 defn.BoxedShortClass , defn.BoxedIntClass , defn.BoxedLongClass , defn.BoxedFloatClass ,
2338- defn.BoxedDoubleClass , defn.StringClass
2355+ defn.BoxedDoubleClass , defn.StringClass , jsdefn. JavaLangVoidClass
23392356 )
23402357 }
23412358
0 commit comments