-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpolyfill.js
More file actions
57 lines (54 loc) · 1.16 KB
/
Copy pathpolyfill.js
File metadata and controls
57 lines (54 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
'use strict';
// this polyfill is spec-accurate, but not something you should actually use
let join = {
join(separator) {
if (!this || typeof this !== 'object' && typeof this !== 'function') {
throw new TypeError('expected receiver to be an object');
}
let sep;
if (separator === undefined) {
sep = ',';
} else {
try {
sep = `${separator}`;
} catch (e) {
try {
this.return();
} catch { /* ignored */ }
throw e;
}
}
let next = this.next;
let R = '';
let first = true;
while (true) {
let { done, value } = next.call(this);
if (done) {
return R;
}
if (first) {
first = false;
} else {
R = R + sep;
}
if (value !== undefined && value !== null) {
let S;
try {
S = `${value}`;
} catch (e) {
try {
this.return();
} catch { /* ignored */ }
throw e;
}
R = R + S;
}
}
}
}.join;
Object.defineProperty(Iterator.prototype, 'join', {
configurable: true,
writable: true,
enumerable: false,
value: join,
});