From fd19c9fae818a915550a784e420a530202f50f14 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Fri, 30 Mar 2012 13:22:47 +0400 Subject: [PATCH] Add safeParseInt and safeParseDouble to standard library. --- js/js.libraries/src/core/math.kt | 38 ++++++++++++------------ js/js.translator/testFiles/kotlin_lib.js | 10 +++++++ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/js/js.libraries/src/core/math.kt b/js/js.libraries/src/core/math.kt index dc1fc9d8ec7..d1b8944c2ea 100644 --- a/js/js.libraries/src/core/math.kt +++ b/js/js.libraries/src/core/math.kt @@ -5,27 +5,27 @@ import js.native //TODO: declare using number native class MathClass() { - val PI : Double = 1.0; - fun random() : Double = 0.0; - fun abs(value : Double) = 0.0 - fun acos(value : Double) = 0.0 - fun asin(value : Double) = 0.0 - fun atan(value : Double) = 0.0 - fun atan2(x : Double, y : Double) = 0.0 - fun cos(value : Double) = 0.0 - fun sin(value : Double) = 0.0 - fun exp(value : Double) = 0.0 - fun max(vararg values : Double) = 0.0 + val PI : Double = js.noImpl; + fun random() : Double = js.noImpl; + fun abs(value : Double) : Double = js.noImpl + fun acos(value : Double) : Double = js.noImpl + fun asin(value : Double) : Double = js.noImpl + fun atan(value : Double) : Double = js.noImpl + fun atan2(x : Double, y : Double) : Double = js.noImpl + fun cos(value : Double) : Double = js.noImpl + fun sin(value : Double) : Double = js.noImpl + fun exp(value : Double) : Double = js.noImpl + fun max(vararg values : Double) : Double = js.noImpl fun max(vararg values : Int) : Int = js.noImpl fun min(vararg values : Int) : Int = js.noImpl - fun min(vararg values : Double) = 0.0 - fun sqrt(value : Double) = 0.0 - fun tan(value : Double) = 0.0 - fun log(value : Double) = 0.0 - fun pow(base : Double, exp : Double) = 0.0 - fun round(value : Number) = 0 - fun floor(value : Number) = 0 - fun ceil(value : Number) = 0 + fun min(vararg values : Double) : Double = js.noImpl + fun sqrt(value : Double) : Double = js.noImpl + fun tan(value : Double) : Double = js.noImpl + fun log(value : Double) : Double = js.noImpl + fun pow(base : Double, exp : Double) : Double = js.noImpl + fun round(value : Number) : Int = js.noImpl + fun floor(value : Number) : Int = js.noImpl + fun ceil(value : Number) : Int = js.noImpl } native diff --git a/js/js.translator/testFiles/kotlin_lib.js b/js/js.translator/testFiles/kotlin_lib.js index 8c2b828a74a..07e456d794f 100644 --- a/js/js.translator/testFiles/kotlin_lib.js +++ b/js/js.translator/testFiles/kotlin_lib.js @@ -351,6 +351,16 @@ var Kotlin; } ; + Kotlin.safeParseInt = function(str) { + var r = parseInt(str, 10); + return isNaN(r) ? null : r; + }; + + Kotlin.safeParseDouble = function(str) { + var r = parseFloat(str, 10); + return isNaN(r) ? null : r; + }; + Kotlin.System = function () { var output = "";