1
|
|
|
|
2
|
|
|
// https://tc39.github.io/ecma262/#sec-array.prototype.includes |
3
|
|
|
if (!Array.prototype.includes) { |
4
|
|
|
Object.defineProperty(Array.prototype, 'includes', { |
5
|
|
|
value: function(searchElement, fromIndex) { |
6
|
|
|
|
7
|
|
|
if (this == null) { |
|
|
|
|
8
|
|
|
throw new TypeError('"this" is null or not defined'); |
9
|
|
|
} |
10
|
|
|
|
11
|
|
|
// 1. Let O be ? ToObject(this value). |
12
|
|
|
var o = Object(this); |
13
|
|
|
|
14
|
|
|
// 2. Let len be ? ToLength(? Get(O, "length")). |
15
|
|
|
var len = o.length >>> 0; |
16
|
|
|
|
17
|
|
|
// 3. If len is 0, return false. |
18
|
|
|
if (len === 0) { |
19
|
|
|
return false; |
20
|
|
|
} |
21
|
|
|
|
22
|
|
|
// 4. Let n be ? ToInteger(fromIndex). |
23
|
|
|
// (If fromIndex is undefined, this step produces the value 0.) |
24
|
|
|
var n = fromIndex | 0; |
25
|
|
|
|
26
|
|
|
// 5. If n ≥ 0, then |
27
|
|
|
// a. Let k be n. |
28
|
|
|
// 6. Else n < 0, |
29
|
|
|
// a. Let k be len + n. |
30
|
|
|
// b. If k < 0, let k be 0. |
31
|
|
|
var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0); |
32
|
|
|
|
33
|
|
|
function sameValueZero(x, y) { |
34
|
|
|
return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y)); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
// 7. Repeat, while k < len |
38
|
|
|
while (k < len) { |
39
|
|
|
// a. Let elementK be the result of ? Get(O, ! ToString(k)). |
40
|
|
|
// b. If SameValueZero(searchElement, elementK) is true, return true. |
41
|
|
|
if (sameValueZero(o[k], searchElement)) { |
42
|
|
|
return true; |
43
|
|
|
} |
44
|
|
|
// c. Increase k by 1. |
45
|
|
|
k++; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
// 8. Return false |
49
|
|
|
return false; |
50
|
|
|
} |
51
|
|
|
}); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/*! https://mths.be/codepointat v0.2.0 by @mathias */ |
55
|
|
|
if (!String.prototype.codePointAt) { |
56
|
|
|
(function() { |
57
|
|
|
'use strict'; // needed to support `apply`/`call` with `undefined`/`null` |
58
|
|
|
var defineProperty = (function() { |
59
|
|
|
// IE 8 only supports `Object.defineProperty` on DOM elements |
60
|
|
|
try { |
61
|
|
|
var object = {}; |
62
|
|
|
var $defineProperty = Object.defineProperty; |
63
|
|
|
var result = $defineProperty(object, object, object) && $defineProperty; |
64
|
|
|
} catch(error) {} |
|
|
|
|
65
|
|
|
return result; |
|
|
|
|
66
|
|
|
}()); |
67
|
|
|
var codePointAt = function(position) { |
68
|
|
|
if (this == null) { |
|
|
|
|
69
|
|
|
throw TypeError(); |
70
|
|
|
} |
71
|
|
|
var string = String(this); |
72
|
|
|
var size = string.length; |
73
|
|
|
// `ToInteger` |
74
|
|
|
var index = position ? Number(position) : 0; |
75
|
|
|
if (index != index) { // better `isNaN` |
76
|
|
|
index = 0; |
77
|
|
|
} |
78
|
|
|
// Account for out-of-bounds indices: |
79
|
|
|
if (index < 0 || index >= size) { |
80
|
|
|
return undefined; |
81
|
|
|
} |
82
|
|
|
// Get the first code unit |
83
|
|
|
var first = string.charCodeAt(index); |
84
|
|
|
var second; |
85
|
|
|
if ( // check if it’s the start of a surrogate pair |
86
|
|
|
first >= 0xD800 && first <= 0xDBFF && // high surrogate |
87
|
|
|
size > index + 1 // there is a next code unit |
88
|
|
|
) { |
89
|
|
|
second = string.charCodeAt(index + 1); |
90
|
|
|
if (second >= 0xDC00 && second <= 0xDFFF) { // low surrogate |
91
|
|
|
// https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae |
92
|
|
|
return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000; |
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
return first; |
96
|
|
|
}; |
97
|
|
|
if (defineProperty) { |
98
|
|
|
defineProperty(String.prototype, 'codePointAt', { |
99
|
|
|
'value': codePointAt, |
100
|
|
|
'configurable': true, |
101
|
|
|
'writable': true |
102
|
|
|
}); |
103
|
|
|
} else { |
104
|
|
|
String.prototype.codePointAt = codePointAt; |
|
|
|
|
105
|
|
|
} |
106
|
|
|
}()); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
// tmp fix |
110
|
|
|
if (!Uint8Array.prototype.slice) { |
111
|
|
|
Object.defineProperty(Uint8Array.prototype, 'slice', { |
112
|
|
|
value: Array.prototype.slice |
113
|
|
|
}); |
114
|
|
|
} |
115
|
|
|
|