1
1
'use strict' ;
2
2
3
3
const {
4
+ ArrayPrototypeSlice,
5
+ ArrayPrototypeSort,
6
+ RegExpPrototypeTest,
4
7
StringFromCharCode,
8
+ StringPrototypeCharCodeAt,
9
+ StringPrototypeCodePointAt,
10
+ StringPrototypeMatch,
11
+ StringPrototypeSlice,
12
+ StringPrototypeToLowerCase,
5
13
Symbol,
6
14
} = primordials ;
7
15
@@ -32,8 +40,9 @@ CSI.kClearScreenDown = CSI`0J`;
32
40
function charLengthLeft ( str , i ) {
33
41
if ( i <= 0 )
34
42
return 0 ;
35
- if ( ( i > 1 && str . codePointAt ( i - 2 ) >= kUTF16SurrogateThreshold ) ||
36
- str . codePointAt ( i - 1 ) >= kUTF16SurrogateThreshold ) {
43
+ if ( ( i > 1 &&
44
+ StringPrototypeCodePointAt ( str , i - 2 ) >= kUTF16SurrogateThreshold ) ||
45
+ StringPrototypeCodePointAt ( str , i - 1 ) >= kUTF16SurrogateThreshold ) {
37
46
return 2 ;
38
47
}
39
48
return 1 ;
@@ -45,7 +54,7 @@ function charLengthAt(str, i) {
45
54
// moving to the right.
46
55
return 1 ;
47
56
}
48
- return str . codePointAt ( i ) >= kUTF16SurrogateThreshold ? 2 : 1 ;
57
+ return StringPrototypeCodePointAt ( str , i ) >= kUTF16SurrogateThreshold ? 2 : 1 ;
49
58
}
50
59
51
60
/*
@@ -178,13 +187,15 @@ function* emitKeys(stream) {
178
187
* We buffered enough data, now trying to extract code
179
188
* and modifier from it
180
189
*/
181
- const cmd = s . slice ( cmdStart ) ;
190
+ const cmd = StringPrototypeSlice ( s , cmdStart ) ;
182
191
let match ;
183
192
184
- if ( ( match = cmd . match ( / ^ ( \d \d ? ) ( ; ( \d ) ) ? ( [ ~ ^ $ ] ) $ / ) ) ) {
193
+ if ( ( match = StringPrototypeMatch ( cmd , / ^ ( \d \d ? ) ( ; ( \d ) ) ? ( [ ~ ^ $ ] ) $ / ) ) ) {
185
194
code += match [ 1 ] + match [ 4 ] ;
186
195
modifier = ( match [ 3 ] || 1 ) - 1 ;
187
- } else if ( ( match = cmd . match ( / ^ ( ( \d ; ) ? ( \d ) ) ? ( [ A - Z a - z ] ) $ / ) ) ) {
196
+ } else if (
197
+ ( match = StringPrototypeMatch ( cmd , / ^ ( ( \d ; ) ? ( \d ) ) ? ( [ A - Z a - z ] ) $ / ) )
198
+ ) {
188
199
code += match [ 4 ] ;
189
200
modifier = ( match [ 3 ] || 1 ) - 1 ;
190
201
} else {
@@ -325,12 +336,14 @@ function* emitKeys(stream) {
325
336
key . meta = escaped ;
326
337
} else if ( ! escaped && ch <= '\x1a' ) {
327
338
// ctrl+letter
328
- key . name = StringFromCharCode ( ch . charCodeAt ( 0 ) + 'a' . charCodeAt ( 0 ) - 1 ) ;
339
+ key . name = StringFromCharCode (
340
+ StringPrototypeCharCodeAt ( ch ) + StringPrototypeCharCodeAt ( 'a' ) - 1
341
+ ) ;
329
342
key . ctrl = true ;
330
- } else if ( / ^ [ 0 - 9 A - Z a - z ] $ / . test ( ch ) ) {
343
+ } else if ( RegExpPrototypeTest ( / ^ [ 0 - 9 A - Z a - z ] $ / , ch ) ) {
331
344
// Letter, number, shift+letter
332
- key . name = ch . toLowerCase ( ) ;
333
- key . shift = / ^ [ A - Z ] $ / . test ( ch ) ;
345
+ key . name = StringPrototypeToLowerCase ( ch ) ;
346
+ key . shift = RegExpPrototypeTest ( / ^ [ A - Z ] $ / , ch ) ;
334
347
key . meta = escaped ;
335
348
} else if ( escaped ) {
336
349
// Escape sequence timeout
@@ -356,12 +369,12 @@ function commonPrefix(strings) {
356
369
if ( strings . length === 1 ) {
357
370
return strings [ 0 ] ;
358
371
}
359
- const sorted = strings . slice ( ) . sort ( ) ;
372
+ const sorted = ArrayPrototypeSort ( ArrayPrototypeSlice ( strings ) ) ;
360
373
const min = sorted [ 0 ] ;
361
374
const max = sorted [ sorted . length - 1 ] ;
362
375
for ( let i = 0 ; i < min . length ; i ++ ) {
363
376
if ( min [ i ] !== max [ i ] ) {
364
- return min . slice ( 0 , i ) ;
377
+ return StringPrototypeSlice ( min , 0 , i ) ;
365
378
}
366
379
}
367
380
return min ;
0 commit comments