@@ -456,7 +456,8 @@ class JSCodeGen()(implicit ctx: Context) {
456
456
}
457
457
}*/
458
458
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)
460
461
}).toList
461
462
}
462
463
@@ -514,7 +515,7 @@ class JSCodeGen()(implicit ctx: Context) {
514
515
/* if (primitives.isPrimitive(sym)) {
515
516
None
516
517
} else*/ if (sym.is(Deferred )) {
517
- Some (js.MethodDef (static = false , methodName,
518
+ Some (js.MethodDef (js. MemberFlags .empty , methodName,
518
519
jsParams, toIRType(patchedResultType(sym)), None )(
519
520
OptimizerHints .empty, None ))
520
521
} else /* if (isJSNativeCtorDefaultParam(sym)) {
@@ -549,15 +550,19 @@ class JSCodeGen()(implicit ctx: Context) {
549
550
val body1 =
550
551
if (!sym.isPrimaryConstructor) body0
551
552
else moveAllStatementsAfterSuperConstructorCall(body0)
552
- js.MethodDef(static = false , methodName,
553
+ js.MethodDef(js.MemberFlags.empty , methodName,
553
554
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 ,
557
559
Some (genStat(rhs)))(optimizerHints, None )
558
560
} else {
561
+ val namespace =
562
+ if (sym.isPrivate) js.MemberNamespace .Private
563
+ else js.MemberNamespace .Public
559
564
val resultIRType = toIRType(patchedResultType(sym))
560
- genMethodDef(static = false , methodName,
565
+ genMethodDef(namespace , methodName,
561
566
params, resultIRType, rhs, optimizerHints)
562
567
}
563
568
}
@@ -576,7 +581,7 @@ class JSCodeGen()(implicit ctx: Context) {
576
581
* Methods Scala.js-defined JS classes are compiled as static methods taking
577
582
* an explicit parameter for their `this` value.
578
583
*/
579
- private def genMethodDef (static : Boolean , methodName : js.PropertyName ,
584
+ private def genMethodDef (namespace : js. MemberNamespace , methodName : js.PropertyName ,
580
585
paramsSyms : List [Symbol ], resultIRType : jstpe.Type ,
581
586
tree : Tree , optimizerHints : OptimizerHints ): js.MethodDef = {
582
587
implicit val pos = tree.span
@@ -595,10 +600,11 @@ class JSCodeGen()(implicit ctx: Context) {
595
600
else genExpr(tree)
596
601
597
602
// 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()))(
599
605
optimizerHints, None )
600
606
/* } else {
601
- assert(!static , tree.span)
607
+ assert(!namespace.isStatic , tree.span)
602
608
603
609
withScopedVars(
604
610
thisLocalVarIdent := Some(freshLocalIdent("this"))
@@ -962,7 +968,8 @@ class JSCodeGen()(implicit ctx: Context) {
962
968
currentMethodSym.get.isClassConstructor) {
963
969
isModuleInitialized = true
964
970
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))
966
973
js.Block (superCall, initModule)
967
974
} else {
968
975
superCall
@@ -1001,12 +1008,12 @@ class JSCodeGen()(implicit ctx: Context) {
1001
1008
else if (clsSym == jsdefn.JSArrayClass && args.isEmpty) js.JSArrayConstr (Nil )
1002
1009
else js.JSNew (genLoadJSConstructor(clsSym), genActualJSArgs(ctor, args))
1003
1010
} else {
1004
- toIRType (tpe) match {
1005
- case cls : jstpe.ClassType =>
1011
+ toTypeRef (tpe) match {
1012
+ case cls : jstpe.ClassRef =>
1006
1013
js.New (cls, encodeMethodSym(ctor), genActualArgs(ctor, args))
1007
1014
1008
1015
case other =>
1009
- throw new FatalError (s " Non ClassType cannot be instantiated: $other" )
1016
+ throw new FatalError (s " Non ClassRef cannot be instantiated: $other" )
1010
1017
}
1011
1018
}
1012
1019
}
@@ -1030,7 +1037,7 @@ class JSCodeGen()(implicit ctx: Context) {
1030
1037
}
1031
1038
val newMethodIdent = js.Ident (newMethodName, origName)
1032
1039
1033
- js.Apply (genLoadModule(moduleClass), newMethodIdent, args)(
1040
+ js.Apply (js. ApplyFlags .empty, genLoadModule(moduleClass), newMethodIdent, args)(
1034
1041
jstpe.ClassType (encodedName))
1035
1042
}
1036
1043
@@ -1575,11 +1582,8 @@ class JSCodeGen()(implicit ctx: Context) {
1575
1582
genApplyJSMethodGeneric(tree, sym, genExpr(receiver), genActualJSArgs(sym, args), isStat)
1576
1583
/* else
1577
1584
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))
1581
1585
} else {
1582
- genApplyMethod (genExpr(receiver), sym, genActualArgs(sym, args))
1586
+ genApplyMethodMaybeStatically (genExpr(receiver), sym, genActualArgs(sym, args))
1583
1587
}
1584
1588
}
1585
1589
@@ -1789,7 +1793,7 @@ class JSCodeGen()(implicit ctx: Context) {
1789
1793
1790
1794
val genElems = tree.elems.map(genExpr)
1791
1795
val arrayTypeRef = toTypeRef(tree.tpe).asInstanceOf [jstpe.ArrayTypeRef ]
1792
- js.ArrayValue (jstpe. ArrayType ( arrayTypeRef) , genElems)
1796
+ js.ArrayValue (arrayTypeRef, genElems)
1793
1797
}
1794
1798
1795
1799
/** Gen JS code for a closure.
@@ -1877,7 +1881,8 @@ class JSCodeGen()(implicit ctx: Context) {
1877
1881
1878
1882
val genBody = {
1879
1883
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
1880
- val call = genApplyMethod(thisCaptureRef, sym, argCaptureRefs ::: actualParams)
1884
+ val call = genApplyMethodMaybeStatically(thisCaptureRef, sym,
1885
+ argCaptureRefs ::: actualParams)
1881
1886
box(call, sym.info.finalResultType)
1882
1887
}
1883
1888
@@ -1892,7 +1897,7 @@ class JSCodeGen()(implicit ctx: Context) {
1892
1897
s " Invalid functional interface $funInterfaceSym reached the back-end " )
1893
1898
val cls = " sjsr_AnonFunction" + formalParams.size
1894
1899
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))
1896
1901
}
1897
1902
}
1898
1903
@@ -1993,30 +1998,41 @@ class JSCodeGen()(implicit ctx: Context) {
1993
1998
}
1994
1999
}
1995
2000
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
+
1996
2010
/** 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 ])(
1999
2013
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)))
2002
2018
}
2003
2019
2004
2020
/** Gen a statically linked call to an instance method. */
2005
2021
private def genApplyMethodStatically (receiver : js.Tree , method : Symbol ,
2006
2022
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)))
2012
2029
}
2013
2030
2014
2031
/** Gen a call to a static method. */
2015
2032
private def genApplyStatic (method : Symbol , arguments : List [js.Tree ])(
2016
2033
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)(
2020
2036
toIRType(patchedResultType(method)))
2021
2037
}
2022
2038
@@ -2264,7 +2280,7 @@ class JSCodeGen()(implicit ctx: Context) {
2264
2280
} else {
2265
2281
val inst = genLoadModule(sym.owner)
2266
2282
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))
2268
2284
}
2269
2285
}
2270
2286
@@ -2279,13 +2295,13 @@ class JSCodeGen()(implicit ctx: Context) {
2279
2295
2280
2296
if (isJSType(sym)) {
2281
2297
if (isScalaJSDefinedJSClass(sym))
2282
- js.LoadJSModule (jstpe. ClassType (encodeClassFullName( sym) ))
2298
+ js.LoadJSModule (encodeClassRef( sym))
2283
2299
/* else if (sym.derivesFrom(jsdefn.JSGlobalScopeClass))
2284
2300
genLoadJSGlobal()*/
2285
2301
else
2286
2302
genLoadNativeJSModule(sym)
2287
2303
} else {
2288
- js.LoadModule (jstpe. ClassType (encodeClassFullName( sym) ))
2304
+ js.LoadModule (encodeClassRef( sym))
2289
2305
}
2290
2306
}
2291
2307
@@ -2294,7 +2310,7 @@ class JSCodeGen()(implicit ctx: Context) {
2294
2310
implicit pos : Position ): js.Tree = {
2295
2311
assert(! isStaticModule(sym) && ! sym.is(Trait ),
2296
2312
s " genPrimitiveJSClass called with non-class $sym" )
2297
- js.LoadJSConstructor (jstpe. ClassType (encodeClassFullName( sym) ))
2313
+ js.LoadJSConstructor (encodeClassRef( sym))
2298
2314
}
2299
2315
2300
2316
/** Gen JS code representing a native JS module. */
@@ -2331,11 +2347,12 @@ class JSCodeGen()(implicit ctx: Context) {
2331
2347
protected lazy val isHijackedClass : Set [Symbol ] = {
2332
2348
/* This list is a duplicate of ir.Definitions.HijackedClasses, but
2333
2349
* with global.Symbol's instead of IR encoded names as Strings.
2350
+ * We also add java.lang.Void, which BoxedUnit "erases" to.
2334
2351
*/
2335
2352
Set [Symbol ](
2336
2353
defn.BoxedUnitClass , defn.BoxedBooleanClass , defn.BoxedCharClass , defn.BoxedByteClass ,
2337
2354
defn.BoxedShortClass , defn.BoxedIntClass , defn.BoxedLongClass , defn.BoxedFloatClass ,
2338
- defn.BoxedDoubleClass , defn.StringClass
2355
+ defn.BoxedDoubleClass , defn.StringClass , jsdefn. JavaLangVoidClass
2339
2356
)
2340
2357
}
2341
2358
0 commit comments