43
43
44
44
// Adapted from https://github.com/mathiasbynens/punycode.js
45
45
46
- // TODO(petamoriken): enable prefer-primordials for node polyfills
47
- // deno-lint-ignore-file prefer-primordials
48
-
49
46
// TODO(cmorten): migrate punycode logic to "icu" internal binding and/or "url"
50
47
// internal module so there can be re-use within the "url" module etc.
51
48
@@ -55,6 +52,13 @@ import {
55
52
op_node_idna_domain_to_ascii ,
56
53
op_node_idna_domain_to_unicode ,
57
54
} from "ext:core/ops" ;
55
+ import { primordials } from "ext:core/mod.js" ;
56
+ const {
57
+ ArrayPrototypePush,
58
+ SafeArrayIterator,
59
+ StringFromCodePoint,
60
+ StringPrototypeCharCodeAt,
61
+ } = primordials ;
58
62
59
63
/**
60
64
* Creates an array containing the numeric code points of each Unicode
@@ -72,22 +76,25 @@ function ucs2decode(str: string) {
72
76
const length = str . length ;
73
77
74
78
while ( counter < length ) {
75
- const value = str . charCodeAt ( counter ++ ) ;
79
+ const value = StringPrototypeCharCodeAt ( str , counter ++ ) ;
76
80
77
81
if ( value >= 0xD800 && value <= 0xDBFF && counter < length ) {
78
82
// It's a high surrogate, and there is a next character.
79
- const extra = str . charCodeAt ( counter ++ ) ;
83
+ const extra = StringPrototypeCharCodeAt ( str , counter ++ ) ;
80
84
81
85
if ( ( extra & 0xFC00 ) == 0xDC00 ) { // Low surrogate.
82
- output . push ( ( ( value & 0x3FF ) << 10 ) + ( extra & 0x3FF ) + 0x10000 ) ;
86
+ ArrayPrototypePush (
87
+ output ,
88
+ ( ( value & 0x3FF ) << 10 ) + ( extra & 0x3FF ) + 0x10000 ,
89
+ ) ;
83
90
} else {
84
91
// It's an unmatched surrogate; only append this code unit, in case the
85
92
// next code unit is the high surrogate of a surrogate pair.
86
- output . push ( value ) ;
93
+ ArrayPrototypePush ( output , value ) ;
87
94
counter -- ;
88
95
}
89
96
} else {
90
- output . push ( value ) ;
97
+ ArrayPrototypePush ( output , value ) ;
91
98
}
92
99
}
93
100
@@ -103,7 +110,7 @@ function ucs2decode(str: string) {
103
110
* @returns The new Unicode string (UCS-2).
104
111
*/
105
112
function ucs2encode ( array : number [ ] ) {
106
- return String . fromCodePoint ( ...array ) ;
113
+ return StringFromCodePoint ( ...new SafeArrayIterator ( array ) ) ;
107
114
}
108
115
109
116
export const ucs2 = {
0 commit comments