Skip to content

Commit

Permalink
KJS: extract string polyfills to separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
bashor committed Jan 18, 2017
1 parent 12a1c63 commit 45b92be
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 23 deletions.
23 changes: 0 additions & 23 deletions js/js.translator/testData/kotlin_lib.js
Expand Up @@ -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) {
Expand Down
38 changes: 38 additions & 0 deletions 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;
};

0 comments on commit 45b92be

Please sign in to comment.