@@ -254,3 +254,95 @@ exports.binding = function(bindingName) {
254254 return process . binding ( bindingName ) ;
255255 }
256256} ;
257+
258+ const urls = {
259+ long : 'http://nodejs.org:89/docs/latest/api/foo/bar/qua/13949281/0f28b/' +
260+ '/5d49/b3020/url.html#test?payload1=true&payload2=false&test=1' +
261+ '&benchmark=3&foo=38.38.011.293&bar=1234834910480&test=19299&3992&' +
262+ 'key=f5c65e1e98fe07e648249ad41e1cfdb0' ,
263+ short : 'https://nodejs.org/en/blog/' ,
264+ idn : 'http://你好你好.在线' ,
265+ auth : 'https://user:pass@example.com/path?search=1' ,
266+ file : 'file:///foo/bar/test/node.js' ,
267+ ws : 'ws://localhost:9229/f46db715-70df-43ad-a359-7f9949f39868' ,
268+ javascript : 'javascript:alert("node is awesome");' ,
269+ percent : 'https://%E4%BD%A0/foo' ,
270+ dot : 'https://example.org/./a/../b/./c'
271+ } ;
272+ exports . urls = urls ;
273+
274+ const searchParams = {
275+ noencode : 'foo=bar&baz=quux&xyzzy=thud' ,
276+ multicharsep : 'foo=bar&&&&&&&&&&baz=quux&&&&&&&&&&xyzzy=thud' ,
277+ encodefake : 'foo=%©ar&baz=%A©uux&xyzzy=%©ud' ,
278+ encodemany : '%66%6F%6F=bar&%62%61%7A=quux&xyzzy=%74h%75d' ,
279+ encodelast : 'foo=bar&baz=quux&xyzzy=thu%64' ,
280+ multivalue : 'foo=bar&foo=baz&foo=quux&quuy=quuz' ,
281+ multivaluemany : 'foo=bar&foo=baz&foo=quux&quuy=quuz&foo=abc&foo=def&' +
282+ 'foo=ghi&foo=jkl&foo=mno&foo=pqr&foo=stu&foo=vwxyz' ,
283+ manypairs : 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z' ,
284+ manyblankpairs : '&&&&&&&&&&&&&&&&&&&&&&&&' ,
285+ altspaces : 'foo+bar=baz+quux&xyzzy+thud=quuy+quuz&abc=def+ghi'
286+ } ;
287+ exports . searchParams = searchParams ;
288+
289+ function getUrlData ( withBase ) {
290+ const data = require ( '../test/fixtures/wpt/url/resources/urltestdata.json' ) ;
291+ const result = [ ] ;
292+ for ( const item of data ) {
293+ if ( item . failure || ! item . input ) continue ;
294+ if ( withBase ) {
295+ result . push ( [ item . input , item . base ] ) ;
296+ } else if ( item . base !== 'about:blank' ) {
297+ result . push ( item . base ) ;
298+ }
299+ }
300+ return result ;
301+ }
302+
303+ exports . urlDataTypes = Object . keys ( urls ) . concat ( [ 'wpt' ] ) ;
304+
305+ /**
306+ * Generate an array of data for URL benchmarks to use.
307+ * The size of the resulting data set is the original data size * 2 ** `e`.
308+ * The 'wpt' type contains about 400 data points when `withBase` is true,
309+ * and 200 data points when `withBase` is false.
310+ * Other types contain 200 data points with or without base.
311+ *
312+ * @param {string } type Type of the data, 'wpt' or a key of `urls`
313+ * @param {number } e The repetition of the data, as exponent of 2
314+ * @param {boolean } withBase Whether to include a base URL
315+ * @param {boolean } asUrl Whether to return the results as URL objects
316+ * @return {string[] | string[][] | URL[] }
317+ */
318+ function bakeUrlData ( type , e = 0 , withBase = false , asUrl = false ) {
319+ let result = [ ] ;
320+ if ( type === 'wpt' ) {
321+ result = getUrlData ( withBase ) ;
322+ } else if ( urls [ type ] ) {
323+ const input = urls [ type ] ;
324+ const item = withBase ? [ input , 'about:blank' ] : input ;
325+ // Roughly the size of WPT URL test data
326+ result = new Array ( 200 ) . fill ( item ) ;
327+ } else {
328+ throw new Error ( `Unknown url data type ${ type } ` ) ;
329+ }
330+
331+ if ( typeof e !== 'number' ) {
332+ throw new Error ( `e must be a number, received ${ e } ` ) ;
333+ }
334+
335+ for ( let i = 0 ; i < e ; ++ i ) {
336+ result = result . concat ( result ) ;
337+ }
338+
339+ if ( asUrl ) {
340+ if ( withBase ) {
341+ result = result . map ( ( [ input , base ] ) => new URL ( input , base ) ) ;
342+ } else {
343+ result = result . map ( ( input ) => new URL ( input ) ) ;
344+ }
345+ }
346+ return result ;
347+ }
348+ exports . bakeUrlData = bakeUrlData ;
0 commit comments