From 0a792903dce5ef5ea80ea97c08ec4d3bbf93c5eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 7 Oct 2013 12:22:39 +0200 Subject: [PATCH] Fix browser compatibilities by adding some polyfills Chrome doesn't support Array.concat so we must use the instance method. review1108003 --- src/common.js | 4 ++-- src/sao.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/common.js b/src/common.js index 205b577d3e..56acb54a7e 100644 --- a/src/common.js +++ b/src/common.js @@ -1340,12 +1340,12 @@ if (this.is_leaf(domain)) { return [domain]; } else if (domoperator === undefined) { - return [domain_type].concat(Array.concat.apply([], + return [domain_type].concat([].concat.apply([], domain.map(function(e) { return this.merge(e, domain_type); }.bind(this)))); } else if (domain_type == domoperator) { - return Array.concat.apply([], domain.map(function(e) { + return [].concat.apply([], domain.map(function(e) { return this.merge(e, domain_type); }.bind(this))); } else { diff --git a/src/sao.js b/src/sao.js index f197509227..7b31ae7fb8 100644 --- a/src/sao.js +++ b/src/sao.js @@ -5,6 +5,37 @@ var Sao = {}; (function() { 'use strict'; + // Browser compatibility: polyfill + if (!('contains' in String.prototype)) { + String.prototype.contains = function(str, startIndex) { + return -1 !== String.prototype.indexOf.call(this, str, startIndex); + }; + } + if (!String.prototype.startsWith) { + Object.defineProperty(String.prototype, 'startsWith', { + enumerable: false, + configurable: false, + writable: false, + value: function(searchString, position) { + position = position || 0; + return this.indexOf(searchString, position) === position; + } + }); + } + if (!String.prototype.endsWith) { + Object.defineProperty(String.prototype, 'endsWith', { + enumerable: false, + configurable: false, + writable: false, + value: function(searchString, position) { + position = position || this.length; + position = position - searchString.length; + var lastIndex = this.lastIndexOf(searchString); + return lastIndex !== -1 && lastIndex === position; + } + }); + } + Sao.error = function(title, message) { alert(title + '\n' + (message || '')); };