Skip to content

Commit

Permalink
Merge pull request scala-js#4633 from sjrd/fix-optimized-strict-floats
Browse files Browse the repository at this point in the history
Fix scala-js#4632: Fix strict-floats + optimized semantics.
  • Loading branch information
gzm0 authored Jan 31, 2022
2 parents 5e5880a + 0ae15d3 commit 12285ab
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2597,7 +2597,7 @@ private[emitter] class FunctionEmitter(sjsGen: SJSGen) {
genIsInstanceOf(transformExprNoChar(expr), testType)

case AsInstanceOf(expr, tpe) =>
genAsInstanceOf(transformExprNoChar(expr), tpe)
extractWithGlobals(genAsInstanceOf(transformExprNoChar(expr), tpe))

case GetClass(expr) =>
genCallHelper("objectGetClass", transformExprNoChar(expr))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,31 +268,34 @@ private[emitter] final class SJSGen(

def genAsInstanceOf(expr: Tree, tpe: Type)(
implicit moduleContext: ModuleContext, globalKnowledge: GlobalKnowledge,
pos: Position): Tree = {
pos: Position): WithGlobals[Tree] = {
import TreeDSL._

// Local short-hand of WithGlobals(...)
def wg(tree: Tree): WithGlobals[Tree] = WithGlobals(tree)

if (semantics.asInstanceOfs == CheckedBehavior.Unchecked) {
tpe match {
case _:ClassType | _:ArrayType | AnyType =>
expr
wg(expr)

case UndefType => Block(expr, Undefined())
case BooleanType => !(!expr)
case CharType => genCallHelper("uC", expr)
case ByteType | ShortType| IntType => expr | 0
case LongType => genCallHelper("uJ", expr)
case DoubleType => UnaryOp(irt.JSUnaryOp.+, expr)
case StringType => expr || StringLiteral("")
case UndefType => wg(Block(expr, Undefined()))
case BooleanType => wg(!(!expr))
case CharType => wg(genCallHelper("uC", expr))
case ByteType | ShortType| IntType => wg(expr | 0)
case LongType => wg(genCallHelper("uJ", expr))
case DoubleType => wg(UnaryOp(irt.JSUnaryOp.+, expr))
case StringType => wg(expr || StringLiteral(""))

case FloatType =>
if (semantics.strictFloats) genCallHelper("fround", expr)
else UnaryOp(irt.JSUnaryOp.+, expr)
if (semantics.strictFloats) genCallPolyfillableBuiltin(FroundBuiltin, expr)
else wg(UnaryOp(irt.JSUnaryOp.+, expr))

case NoType | NullType | NothingType | _:RecordType =>
throw new AssertionError(s"Unexpected type $tpe in genAsInstanceOf")
}
} else {
tpe match {
val resultTree = tpe match {
case ClassType(ObjectClass) =>
expr
case ClassType(className) =>
Expand All @@ -316,6 +319,8 @@ private[emitter] final class SJSGen(
case NoType | NullType | NothingType | _:RecordType =>
throw new AssertionError(s"Unexpected type $tpe in genAsInstanceOf")
}

wg(resultTree)
}
}

Expand Down

0 comments on commit 12285ab

Please sign in to comment.