|
2 | 2 |
|
3 | 3 | const{ |
4 | 4 | ERR_INVALID_ARG_TYPE, |
5 | | -ERR_INVALID_PROTOCOL, |
| 5 | +ERR_INVALID_RETURN_PROPERTY, |
| 6 | +ERR_INVALID_RETURN_PROPERTY_VALUE, |
| 7 | +ERR_INVALID_RETURN_VALUE, |
6 | 8 | ERR_MISSING_DYNAMIC_INTSTANTIATE_HOOK, |
7 | 9 | ERR_UNKNOWN_MODULE_FORMAT |
8 | 10 | }=require('internal/errors').codes; |
| 11 | +const{URL}=require('url'); |
9 | 12 | constModuleMap=require('internal/modules/esm/module_map'); |
10 | 13 | constModuleJob=require('internal/modules/esm/module_job'); |
11 | 14 | constdefaultResolve=require('internal/modules/esm/default_resolve'); |
@@ -52,20 +55,42 @@ class Loader { |
52 | 55 | if(!isMain&&typeofparentURL!=='string') |
53 | 56 | thrownewERR_INVALID_ARG_TYPE('parentURL','string',parentURL); |
54 | 57 |
|
55 | | -const{ url, format }= |
56 | | -awaitthis._resolve(specifier,parentURL,defaultResolve); |
| 58 | +constresolved=awaitthis._resolve(specifier,parentURL,defaultResolve); |
| 59 | + |
| 60 | +if(typeofresolved!=='object') |
| 61 | +thrownewERR_INVALID_RETURN_VALUE( |
| 62 | +'object','loader resolve',resolved |
| 63 | +); |
| 64 | + |
| 65 | +const{ url, format }=resolved; |
57 | 66 |
|
58 | 67 | if(typeofurl!=='string') |
59 | | -thrownewERR_INVALID_ARG_TYPE('url','string',url); |
| 68 | +thrownewERR_INVALID_RETURN_PROPERTY_VALUE( |
| 69 | +'string','loader resolve','url',url |
| 70 | +); |
60 | 71 |
|
61 | 72 | if(typeofformat!=='string') |
62 | | -thrownewERR_INVALID_ARG_TYPE('format','string',format); |
| 73 | +thrownewERR_INVALID_RETURN_PROPERTY_VALUE( |
| 74 | +'string','loader resolve','format',format |
| 75 | +); |
63 | 76 |
|
64 | 77 | if(format==='builtin') |
65 | 78 | return{url: `node:${url}`, format }; |
66 | 79 |
|
| 80 | +if(this._resolve!==defaultResolve){ |
| 81 | +try{ |
| 82 | +newURL(url); |
| 83 | +}catch(e){ |
| 84 | +thrownewERR_INVALID_RETURN_PROPERTY( |
| 85 | +'url','loader resolve','url',url |
| 86 | +); |
| 87 | +} |
| 88 | +} |
| 89 | + |
67 | 90 | if(format!=='dynamic'&&!url.startsWith('file:')) |
68 | | -thrownewERR_INVALID_PROTOCOL(url,'file:'); |
| 91 | +thrownewERR_INVALID_RETURN_PROPERTY( |
| 92 | +'file: url','loader resolve','url',url |
| 93 | +); |
69 | 94 |
|
70 | 95 | return{ url, format }; |
71 | 96 | } |
|
0 commit comments