From 45b92be1ae949744a26c6b6ed464b313c3977584 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Fri, 23 Dec 2016 19:23:17 +0300 Subject: [PATCH] KJS: extract string polyfills to separate file --- js/js.translator/testData/kotlin_lib.js | 23 ----------- js/js.translator/testData/kotlin_polyfills.js | 38 +++++++++++++++++++ 2 files changed, 38 insertions(+), 23 deletions(-) create mode 100644 js/js.translator/testData/kotlin_polyfills.js diff --git a/js/js.translator/testData/kotlin_lib.js b/js/js.translator/testData/kotlin_lib.js index 22aada7a974..db2da145784 100644 --- a/js/js.translator/testData/kotlin_lib.js +++ b/js/js.translator/testData/kotlin_lib.js @@ -14,29 +14,6 @@ * limitations under the License. */ -// 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) { diff --git a/js/js.translator/testData/kotlin_polyfills.js b/js/js.translator/testData/kotlin_polyfills.js new file mode 100644 index 00000000000..7e3a44423a5 --- /dev/null +++ b/js/js.translator/testData/kotlin_polyfills.js @@ -0,0 +1,38 @@ +/** + * Copyright 2010 Tim Down. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +// 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; +};