@@ -70,25 +70,30 @@ async function getSource(url, context) {
7070 return { __proto__ : null , responseURL, source } ;
7171}
7272
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+ */
7378function getSourceSync ( url , context ) {
74- const parsed = new URL ( url ) ;
75- const responseURL = url ;
79+ const { protocol , href } = url ;
80+ const responseURL = href ;
7681 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 ) ;
8186 if ( ! match ) {
82- throw new ERR_INVALID_URL ( url ) ;
87+ throw new ERR_INVALID_URL ( responseURL ) ;
8388 }
8489 const { 1 : base64 , 2 : body } = match ;
8590 source = BufferFrom ( decodeURIComponent ( body ) , base64 ? 'base64' : 'utf8' ) ;
8691 } else {
8792 const supportedSchemes = [ 'file' , 'data' ] ;
88- throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( parsed , supportedSchemes ) ;
93+ throw new ERR_UNSUPPORTED_ESM_URL_SCHEME ( url , supportedSchemes ) ;
8994 }
9095 if ( policy ?. manifest ) {
91- policy . manifest . assertIntegrity ( parsed , source ) ;
96+ policy . manifest . assertIntegrity ( url , source ) ;
9297 }
9398 return { __proto__ : null , responseURL, source } ;
9499}
@@ -159,14 +164,18 @@ function defaultLoadSync(url, context = kEmptyObject) {
159164 source,
160165 } = context ;
161166
162- format ??= defaultGetFormat ( new URL ( url ) , context ) ;
167+ const urlInstance = new URL ( url ) ;
168+
169+ throwIfUnsupportedURLScheme ( urlInstance , false ) ;
170+
171+ format ??= defaultGetFormat ( urlInstance , context ) ;
163172
164173 validateAssertions ( url , format , importAssertions ) ;
165174
166175 if ( format === 'builtin' ) {
167176 source = null ;
168177 } else if ( source == null ) {
169- ( { responseURL, source } = getSourceSync ( url , context ) ) ;
178+ ( { responseURL, source } = getSourceSync ( urlInstance , context ) ) ;
170179 }
171180
172181 return {
0 commit comments