Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / Source / devtools / front_end / utilities.js
index cc62be2..068e50f 100644 (file)
@@ -80,6 +80,29 @@ String.prototype.lineEndings = function()
 }
 
 /**
+ * @return {number}
+ */
+String.prototype.lineCount = function()
+{
+    var lineEndings = this.lineEndings();
+    return lineEndings.length;
+}
+
+/**
+ * @return {string}
+ */
+String.prototype.lineAt = function(lineNumber)
+{
+    var lineEndings = this.lineEndings();
+    var lineStart = lineNumber > 0 ? lineEndings[lineNumber - 1] + 1 : 0;
+    var lineEnd = lineEndings[lineNumber];
+    var lineContent = this.substring(lineStart, lineEnd);
+    if (lineContent.length > 0 && lineContent.charAt(lineContent.length - 1) === "\r")
+        lineContent = lineContent.substring(0, lineContent.length - 1);
+    return lineContent;
+}
+
+/**
  * @param {string} chars
  * @return {string}
  */
@@ -287,18 +310,6 @@ String.naturalOrderComparator = function(a, b)
 }
 
 /**
- * @param {string} name
- * @param {number=} arrayLength
- * @return {boolean}
- */
-String.isArrayIndexPropertyName = function(name, arrayLength)
-{
-    // Array index check according to the ES5-15.4.
-    var index = name >>> 0;
-    return String(index) === name && index !== 0xffffffff && (typeof arrayLength === "undefined" || index < arrayLength);
-}
-
-/**
  * @param {number} num
  * @param {number} min
  * @param {number} max
@@ -575,24 +586,28 @@ Object.defineProperty(Array.prototype, "lowerBound",
     /**
      * Return index of the leftmost element that is equal or greater
      * than the specimen object. If there's no such element (i.e. all
-     * elements are smaller than the specimen) returns array.length.
+     * elements are smaller than the specimen) returns right bound.
      * The function works for sorted array.
+     * When specified, |left| (inclusive) and |right| (exclusive) indices
+     * define the search window.
      *
      * @param {!T} object
      * @param {function(!T,!S):number=} comparator
+     * @param {number=} left
+     * @param {number=} right
      * @return {number}
      * @this {Array.<!S>}
      * @template T,S
      */
-    value: function(object, comparator)
+    value: function(object, comparator, left, right)
     {
         function defaultComparator(a, b)
         {
             return a < b ? -1 : (a > b ? 1 : 0);
         }
         comparator = comparator || defaultComparator;
-        var l = 0;
-        var r = this.length;
+        var l = left || 0;
+        var r = right !== undefined ? right : this.length;
         while (l < r) {
             var m = (l + r) >> 1;
             if (comparator(object, this[m]) > 0)
@@ -609,24 +624,28 @@ Object.defineProperty(Array.prototype, "upperBound",
     /**
      * Return index of the leftmost element that is greater
      * than the specimen object. If there's no such element (i.e. all
-     * elements are smaller than the specimen) returns array.length.
+     * elements are smaller or equal to the specimen) returns right bound.
      * The function works for sorted array.
+     * When specified, |left| (inclusive) and |right| (exclusive) indices
+     * define the search window.
      *
      * @param {!T} object
      * @param {function(!T,!S):number=} comparator
+     * @param {number=} left
+     * @param {number=} right
      * @return {number}
      * @this {Array.<!S>}
      * @template T,S
      */
-    value: function(object, comparator)
+    value: function(object, comparator, left, right)
     {
         function defaultComparator(a, b)
         {
             return a < b ? -1 : (a > b ? 1 : 0);
         }
         comparator = comparator || defaultComparator;
-        var l = 0;
-        var r = this.length;
+        var l = left || 0;
+        var r = right !== undefined ? right : this.length;
         while (l < r) {
             var m = (l + r) >> 1;
             if (comparator(object, this[m]) >= 0)
@@ -698,29 +717,20 @@ function mergeOrIntersect(array1, array2, comparator, mergeNotIntersect)
     var result = [];
     var i = 0;
     var j = 0;
-    while (i < array1.length || j < array2.length) {
-        if (i === array1.length) {
-            result = result.concat(array2.slice(j));
-            j = array2.length;
-        } else if (j === array2.length) {
-            result = result.concat(array1.slice(i));
-            i = array1.length;
-        } else {
-            var compareValue = comparator(array1[i], array2[j])
-             if (compareValue < 0) {
-                 if (mergeNotIntersect)
-                    result.push(array1[i]);
-                 ++i;
-             } else if (compareValue > 0) {
-                 if (mergeNotIntersect)
-                     result.push(array2[j]);
-                 ++j;
-             } else {
-                 result.push(array1[i]);
-                 ++i;
-                 ++j;
-             }
-        }
+    while (i < array1.length && j < array2.length) {
+        var compareValue = comparator(array1[i], array2[j]);
+        if (mergeNotIntersect || !compareValue)
+            result.push(compareValue <= 0 ? array1[i] : array2[j]);
+        if (compareValue <= 0)
+            i++;
+        if (compareValue >= 0)
+            j++;
+    }
+    if (mergeNotIntersect) {
+        while (i < array1.length)
+            result.push(array1[i++]);
+        while (j < array2.length)
+            result.push(array2[j++]);
     }
     return result;
 }
@@ -1353,9 +1363,9 @@ StringMap.prototype = {
  * @param {function(?string)=} callback
  * @return {?string}
  */
-function loadXHR(url, async, callback) 
+function loadXHR(url, async, callback)
 {
-    function onReadyStateChanged() 
+    function onReadyStateChanged()
     {
         if (xhr.readyState !== XMLHttpRequest.DONE)
             return;
@@ -1365,7 +1375,7 @@ function loadXHR(url, async, callback)
             return;
         }
 
-        callback(null); 
+        callback(null);
    }
 
     var xhr = new XMLHttpRequest();
@@ -1375,7 +1385,7 @@ function loadXHR(url, async, callback)
     xhr.send(null);
 
     if (!async) {
-        if (xhr.status === 200) 
+        if (xhr.status === 200)
             return xhr.responseText;
         return null;
     }
@@ -1464,7 +1474,7 @@ function importScript(scriptName)
     var baseUrl = location.origin + location.pathname;
     baseUrl = baseUrl.substring(0, baseUrl.lastIndexOf("/"));
     var sourceURL = baseUrl + "/" + scriptName;
-    eval(xhr.responseText + "\n//# sourceURL=" + sourceURL);
+    self.eval(xhr.responseText + "\n//# sourceURL=" + sourceURL);
 }
 
 var loadScript = importScript;
@@ -1515,3 +1525,10 @@ CallbackBarrier.prototype = {
             this._outgoingCallback();
     }
 }
+
+/**
+ * @param {*} value
+ */
+function suppressUnused(value)
+{
+}