diff options
Diffstat (limited to 'WebCore/inspector/front-end/utilities.js')
-rw-r--r-- | WebCore/inspector/front-end/utilities.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/WebCore/inspector/front-end/utilities.js b/WebCore/inspector/front-end/utilities.js index 8f86504..7b0a20b 100644 --- a/WebCore/inspector/front-end/utilities.js +++ b/WebCore/inspector/front-end/utilities.js @@ -37,6 +37,8 @@ Object.type = function(obj, win) win = win || window; + if (obj instanceof win.Node) + return "node"; if (obj instanceof win.String) return "string"; if (obj instanceof win.Array) @@ -70,6 +72,7 @@ Object.describe = function(obj, abbreviated) switch (type1) { case "object": + case "node": return type2; case "array": return "[" + obj.toString() + "]"; @@ -937,6 +940,40 @@ Array.prototype.remove = function(value, onlyFirst) } } +function insertionIndexForObjectInListSortedByFunction(anObject, aList, aFunction) +{ + // indexOf returns (-lowerBound - 1). Taking (-result - 1) works out to lowerBound. + return (-indexOfObjectInListSortedByFunction(anObject, aList, aFunction) - 1); +} + +function indexOfObjectInListSortedByFunction(anObject, aList, aFunction) +{ + var first = 0; + var last = aList.length - 1; + var floor = Math.floor; + var mid, c; + + while (first <= last) { + mid = floor((first + last) / 2); + c = aFunction(anObject, aList[mid]); + + if (c > 0) + first = mid + 1; + else if (c < 0) + last = mid - 1; + else { + //we return the first occurance of an item in the list. + while (mid > 0 && aFunction(anObject, aList[mid - 1]) === 0) + mid--; + return mid; + } + } + + // By returning 1 less than the negative lower search bound, we can reuse this function + // for both indexOf and insertionIndexFor, with some simple arithmetic. + return (-first - 1); +} + String.sprintf = function(format) { return String.vsprintf(format, Array.prototype.slice.call(arguments, 1)); |