@@ -2188,15 +2188,45 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
2188
2188
isJSFunctionDef(currentClassSym)) {
2189
2189
val flags = js.MemberFlags .empty.withNamespace(namespace)
2190
2190
val body = {
2191
+ def genAsUnaryOp (op : js.UnaryOp .Code ): js.Tree =
2192
+ js.UnaryOp (op, genThis())
2193
+ def genAsBinaryOp (op : js.BinaryOp .Code ): js.Tree =
2194
+ js.BinaryOp (op, genThis(), jsParams.head.ref)
2195
+ def genAsBinaryOpRhsNotNull (op : js.BinaryOp .Code ): js.Tree =
2196
+ js.BinaryOp (op, genThis(), js.UnaryOp (js.UnaryOp .CheckNotNull , jsParams.head.ref))
2197
+
2191
2198
if (currentClassSym.get == HackedStringClass ) {
2192
2199
/* Hijack the bodies of String.length and String.charAt and replace
2193
2200
* them with String_length and String_charAt operations, respectively.
2194
2201
*/
2195
2202
methodName.name match {
2196
- case `lengthMethodName` =>
2197
- js.UnaryOp (js.UnaryOp .String_length , genThis())
2198
- case `charAtMethodName` =>
2199
- js.BinaryOp (js.BinaryOp .String_charAt , genThis(), jsParams.head.ref)
2203
+ case `lengthMethodName` => genAsUnaryOp(js.UnaryOp .String_length )
2204
+ case `charAtMethodName` => genAsBinaryOp(js.BinaryOp .String_charAt )
2205
+ case _ => genBody()
2206
+ }
2207
+ } else if (currentClassSym.get == ClassClass ) {
2208
+ // Similar, for the Class_x operations
2209
+ methodName.name match {
2210
+ case `getNameMethodName` => genAsUnaryOp(js.UnaryOp .Class_name )
2211
+ case `isPrimitiveMethodName` => genAsUnaryOp(js.UnaryOp .Class_isPrimitive )
2212
+ case `isInterfaceMethodName` => genAsUnaryOp(js.UnaryOp .Class_isInterface )
2213
+ case `isArrayMethodName` => genAsUnaryOp(js.UnaryOp .Class_isArray )
2214
+ case `getComponentTypeMethodName` => genAsUnaryOp(js.UnaryOp .Class_componentType )
2215
+ case `getSuperclassMethodName` => genAsUnaryOp(js.UnaryOp .Class_superClass )
2216
+
2217
+ case `isInstanceMethodName` => genAsBinaryOp(js.BinaryOp .Class_isInstance )
2218
+ case `isAssignableFromMethodName` => genAsBinaryOpRhsNotNull(js.BinaryOp .Class_isAssignableFrom )
2219
+ case `castMethodName` => genAsBinaryOp(js.BinaryOp .Class_cast )
2220
+
2221
+ case _ => genBody()
2222
+ }
2223
+ } else if (currentClassSym.get == JavaLangReflectArrayModClass ) {
2224
+ methodName.name match {
2225
+ case `arrayNewInstanceMethodName` =>
2226
+ val List (jlClassParam, lengthParam) = jsParams
2227
+ js.BinaryOp (js.BinaryOp .Class_newArray ,
2228
+ js.UnaryOp (js.UnaryOp .CheckNotNull , jlClassParam.ref),
2229
+ lengthParam.ref)
2200
2230
case _ =>
2201
2231
genBody()
2202
2232
}
@@ -3644,12 +3674,11 @@ abstract class GenJSCode[G <: Global with Singleton](val global: G)
3644
3674
*/
3645
3675
def genNewArray (arrayTypeRef : jstpe.ArrayTypeRef , arguments : List [js.Tree ])(
3646
3676
implicit pos : Position ): js.Tree = {
3647
- assert(arguments.length <= arrayTypeRef.dimensions,
3648
- " too many arguments for array constructor: found " + arguments.length +
3649
- " but array has only " + arrayTypeRef.dimensions +
3650
- " dimension(s)" )
3677
+ assert(arguments.size == 1 ,
3678
+ " expected exactly 1 argument for array constructor: found " +
3679
+ s " ${arguments.length} at $pos" )
3651
3680
3652
- js.NewArray (arrayTypeRef, arguments)
3681
+ js.NewArray (arrayTypeRef, arguments.head )
3653
3682
}
3654
3683
3655
3684
/** Gen JS code for an array literal. */
@@ -7084,6 +7113,32 @@ private object GenJSCode {
7084
7113
private val charAtMethodName =
7085
7114
MethodName (" charAt" , List (jstpe.IntRef ), jstpe.CharRef )
7086
7115
7116
+ private val getNameMethodName =
7117
+ MethodName (" getName" , Nil , jstpe.ClassRef (ir.Names .BoxedStringClass ))
7118
+ private val isPrimitiveMethodName =
7119
+ MethodName (" isPrimitive" , Nil , jstpe.BooleanRef )
7120
+ private val isInterfaceMethodName =
7121
+ MethodName (" isInterface" , Nil , jstpe.BooleanRef )
7122
+ private val isArrayMethodName =
7123
+ MethodName (" isArray" , Nil , jstpe.BooleanRef )
7124
+ private val getComponentTypeMethodName =
7125
+ MethodName (" getComponentType" , Nil , jstpe.ClassRef (ir.Names .ClassClass ))
7126
+ private val getSuperclassMethodName =
7127
+ MethodName (" getSuperclass" , Nil , jstpe.ClassRef (ir.Names .ClassClass ))
7128
+
7129
+ private val isInstanceMethodName =
7130
+ MethodName (" isInstance" , List (jstpe.ClassRef (ir.Names .ObjectClass )), jstpe.BooleanRef )
7131
+ private val isAssignableFromMethodName =
7132
+ MethodName (" isAssignableFrom" , List (jstpe.ClassRef (ir.Names .ClassClass )), jstpe.BooleanRef )
7133
+ private val castMethodName =
7134
+ MethodName (" cast" , List (jstpe.ClassRef (ir.Names .ObjectClass )), jstpe.ClassRef (ir.Names .ObjectClass ))
7135
+
7136
+ private val arrayNewInstanceMethodName = {
7137
+ MethodName (" newInstance" ,
7138
+ List (jstpe.ClassRef (ir.Names .ClassClass ), jstpe.IntRef ),
7139
+ jstpe.ClassRef (ir.Names .ObjectClass ))
7140
+ }
7141
+
7087
7142
private val thisOriginalName = OriginalName (" this" )
7088
7143
7089
7144
private object BlockOrAlone {
0 commit comments