@@ -83,8 +83,6 @@ class TupleOrigin {
8383
8484function onParseComplete ( flags , protocol , username , password ,
8585 host , port , path , query , fragment ) {
86- if ( flags & binding . URL_FLAGS_FAILED )
87- throw new TypeError ( 'Invalid URL' ) ;
8886 var ctx = this [ context ] ;
8987 ctx . flags = flags ;
9088 ctx . scheme = protocol ;
@@ -102,20 +100,24 @@ function onParseComplete(flags, protocol, username, password,
102100 initSearchParams ( this [ searchParams ] , query ) ;
103101}
104102
103+ function onParseError ( flags , input ) {
104+ const error = new TypeError ( 'Invalid URL: ' + input ) ;
105+ error . input = input ;
106+ throw error ;
107+ }
108+
105109// Reused by URL constructor and URL#href setter.
106110function parse ( url , input , base ) {
107111 input = String ( input ) ;
108112 const base_context = base ? base [ context ] : undefined ;
109113 url [ context ] = new StorageObject ( ) ;
110114 binding . parse ( input . trim ( ) , - 1 ,
111115 base_context , undefined ,
112- onParseComplete . bind ( url ) ) ;
116+ onParseComplete . bind ( url ) , onParseError ) ;
113117}
114118
115119function onParseProtocolComplete ( flags , protocol , username , password ,
116120 host , port , path , query , fragment ) {
117- if ( flags & binding . URL_FLAGS_FAILED )
118- return ;
119121 const newIsSpecial = ( flags & binding . URL_FLAGS_SPECIAL ) !== 0 ;
120122 const s = this [ special ] ;
121123 const ctx = this [ context ] ;
@@ -144,8 +146,6 @@ function onParseProtocolComplete(flags, protocol, username, password,
144146
145147function onParseHostComplete ( flags , protocol , username , password ,
146148 host , port , path , query , fragment ) {
147- if ( flags & binding . URL_FLAGS_FAILED )
148- return ;
149149 const ctx = this [ context ] ;
150150 if ( host ) {
151151 ctx . host = host ;
@@ -159,8 +159,6 @@ function onParseHostComplete(flags, protocol, username, password,
159159
160160function onParseHostnameComplete ( flags , protocol , username , password ,
161161 host , port , path , query , fragment ) {
162- if ( flags & binding . URL_FLAGS_FAILED )
163- return ;
164162 const ctx = this [ context ] ;
165163 if ( host ) {
166164 ctx . host = host ;
@@ -172,15 +170,11 @@ function onParseHostnameComplete(flags, protocol, username, password,
172170
173171function onParsePortComplete ( flags , protocol , username , password ,
174172 host , port , path , query , fragment ) {
175- if ( flags & binding . URL_FLAGS_FAILED )
176- return ;
177173 this [ context ] . port = port ;
178174}
179175
180176function onParsePathComplete ( flags , protocol , username , password ,
181177 host , port , path , query , fragment ) {
182- if ( flags & binding . URL_FLAGS_FAILED )
183- return ;
184178 const ctx = this [ context ] ;
185179 if ( path ) {
186180 ctx . path = path ;
@@ -192,16 +186,12 @@ function onParsePathComplete(flags, protocol, username, password,
192186
193187function onParseSearchComplete ( flags , protocol , username , password ,
194188 host , port , path , query , fragment ) {
195- if ( flags & binding . URL_FLAGS_FAILED )
196- return ;
197189 const ctx = this [ context ] ;
198190 ctx . query = query ;
199191}
200192
201193function onParseHashComplete ( flags , protocol , username , password ,
202194 host , port , path , query , fragment ) {
203- if ( flags & binding . URL_FLAGS_FAILED )
204- return ;
205195 const ctx = this [ context ] ;
206196 if ( fragment ) {
207197 ctx . fragment = fragment ;
0 commit comments