From 315badd5d168edcc3bf545b9d9cdb438038c8491 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Wed, 1 Apr 2015 16:30:14 +0300 Subject: [PATCH] Restore native js functions: startsWith, endsWith, contains. startsWith and endsWith implementation taken from MDN. --- js/js.translator/testData/kotlin_lib.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/js/js.translator/testData/kotlin_lib.js b/js/js.translator/testData/kotlin_lib.js index 1027621d12e..9fdc79725fd 100644 --- a/js/js.translator/testData/kotlin_lib.js +++ b/js/js.translator/testData/kotlin_lib.js @@ -17,6 +17,29 @@ (function (Kotlin) { "use strict"; + // Shims for String + if (typeof String.prototype.startsWith === "undefined") { + String.prototype.startsWith = function(searchString, position) { + position = position || 0; + return this.lastIndexOf(searchString, position) === position; + }; + } + if (typeof String.prototype.endsWith === "undefined") { + String.prototype.endsWith = function(searchString, position) { + var subjectString = this.toString(); + if (position === undefined || position > subjectString.length) { + position = subjectString.length; + } + position -= searchString.length; + var lastIndex = subjectString.indexOf(searchString, position); + return lastIndex !== -1 && lastIndex === position; + }; + } + + String.prototype.contains = function (s) { + return this.indexOf(s) !== -1; + }; + // Kotlin stdlib Kotlin.equals = function (obj1, obj2) {