@@ -70,25 +70,30 @@ async function getSource(url, context) {
70
70
return { __proto__ : null , responseURL, source } ;
71
71
}
72
72
73
+ /**
74
+ * @param {URL } url URL to the module
75
+ * @param {ESModuleContext } context used to decorate error messages
76
+ * @returns {{ responseURL: string, source: string | BufferView } }
77
+ */
73
78
function getSourceSync ( url , context ) {
74
- const parsed = new URL ( url ) ;
75
- const responseURL = url ;
79
+ const { protocol , href } = url ;
80
+ const responseURL = href ;
76
81
let source ;
77
- if ( parsed . protocol === 'file:' ) {
78
- source = readFileSync ( parsed ) ;
79
- } else if ( parsed . protocol === 'data:' ) {
80
- const match = RegExpPrototypeExec ( DATA_URL_PATTERN , parsed . pathname ) ;
82
+ if ( protocol === 'file:' ) {
83
+ source = readFileSync ( url ) ;
84
+ } else if ( protocol === 'data:' ) {
85
+ const match = RegExpPrototypeExec ( DATA_URL_PATTERN , url . pathname ) ;
81
86
if ( ! match ) {
82
- throw new ERR_INVALID_URL ( url ) ;
87
+ throw new ERR_INVALID_URL ( responseURL ) ;
83
88
}
84
89
const { 1 : base64 , 2 : body } = match ;
85
90
source = BufferFrom ( decodeURIComponent ( body ) , base64 ? 'base64' : 'utf8' ) ;
86
91
} else {
87
92
const supportedSchemes = [ 'file' , 'data' ] ;
88
- throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( parsed , supportedSchemes ) ;
93
+ throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( url , supportedSchemes ) ;
89
94
}
90
95
if ( policy ?. manifest ) {
91
- policy . manifest . assertIntegrity ( parsed , source ) ;
96
+ policy . manifest . assertIntegrity ( url , source ) ;
92
97
}
93
98
return { __proto__ : null , responseURL, source } ;
94
99
}
@@ -159,14 +164,18 @@ function defaultLoadSync(url, context = kEmptyObject) {
159
164
source,
160
165
} = context ;
161
166
162
- format ??= defaultGetFormat ( new URL ( url ) , context ) ;
167
+ const urlInstance = new URL ( url ) ;
168
+
169
+ throwIfUnsupportedURLScheme ( urlInstance , false ) ;
170
+
171
+ format ??= defaultGetFormat ( urlInstance , context ) ;
163
172
164
173
validateAssertions ( url , format , importAssertions ) ;
165
174
166
175
if ( format === 'builtin' ) {
167
176
source = null ;
168
177
} else if ( source == null ) {
169
- ( { responseURL, source } = getSourceSync ( url , context ) ) ;
178
+ ( { responseURL, source } = getSourceSync ( urlInstance , context ) ) ;
170
179
}
171
180
172
181
return {
0 commit comments