add shim for es6 string methods and Object.assign

pull/232/head
nightwing 2015-06-08 15:28:44 +04:00
rodzic 880890b61f
commit 16cc9e55d2
4 zmienionych plików z 73 dodań i 4 usunięć

66
node_modules/ace/lib/ace/lib/es6-shim.js wygenerowano vendored 100644
Wyświetl plik

@ -0,0 +1,66 @@
define(function(require, exports, module) {
function defineProp(obj, name, val) {
Object.defineProperty(obj, name, {
value: val,
enumerable: false,
writable: true,
configurable: true,
});
}
if (!String.prototype.startsWith) {
defineProp(String.prototype, "startsWith", function(searchString, position) {
position = position || 0;
return this.lastIndexOf(searchString, position) === position;
});
}
if (!String.prototype.endsWith) {
// Taken from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith
defineProp(String.prototype, "endsWith", function(searchString, position) {
var subjectString = this;
if (position === undefined || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
});
}
if (!String.prototype.repeat) {
defineProp(String.prototype, "repeat", function(count) {
var result = "";
var string = this;
while (count > 0) {
if (count & 1)
result += string;
if (count >>= 1)
string += string;
}
return result;
});
}
if (!String.prototype.includes) {
defineProp(String.prototype, "includes", function(str, position) {
return this.indexOf(str, position != -1);
});
}
if (!Object.assign) {
Object.assign = function (target) {
if (target === undefined || target === null) {
throw new TypeError('Cannot convert undefined or null to object');
}
var output = Object(target);
for (var index = 1; index < arguments.length; index++) {
var source = arguments[index];
if (source !== undefined && source !== null) {
Object.keys(source).forEach(function(key) {
output[key] = source[key];
});
}
}
return output;
};
}
});

Wyświetl plik

@ -15,5 +15,6 @@ define(function(require, exports, module) {
require("./regexp");
require("./es5-shim");
require("./es6-shim");
});

Wyświetl plik

@ -210,6 +210,7 @@ window.onmessage = function(e) {
else if (msg.init) {
window.initBaseUrls(msg.tlns);
require("ace/lib/es5-shim");
require("ace/lib/es6-shim");
sender = window.sender = window.initSender();
var clazz = require(msg.module)[msg.classname];
main = window.main = new clazz(sender);

Wyświetl plik

@ -2988,10 +2988,11 @@ String.prototype.trim = function(){
* @param {Number} times Number of times to repeat the String concatenation
* @type {String}
*/
String.prototype.repeat = function(times) {
return Array(times + 1).join(this);
};
if (!String.prototype.repeat) {
String.prototype.repeat = function(times) {
return Array(times + 1).join(this);
};
}
/*
* Count the number of occurences of substring 'str' inside a string
*