Skip to content

Commit a8ece14

Browse files
committed
url: adding WHATWG URL support
Implements WHATWG URL support. Example: ``` var u = new url.URL('http://example.org'); ``` Currently passing all WHATWG url parsing tests and all but two of the setter tests. The two setter tests are intentionally skipped for now but will be revisited. PR-URL: #7448 Reviewed-By: Ilkka Myller <[email protected]>
1 parent e175188 commit a8ece14

12 files changed

+3965
-72
lines changed

benchmark/url/new-url-parse.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
'use strict';
2+
const common = require('../common.js');
3+
const url = require('url');
4+
const v8 = require('v8');
5+
6+
const bench = common.createBenchmark(main, {
7+
type: 'one two three four five'.split(' '),
8+
method: ['old', 'new'],
9+
n: [25e4]
10+
});
11+
12+
function useOld(n, input) {
13+
// Force-optimize url.parse() so that the benchmark doesn't get
14+
// disrupted by the optimizer kicking in halfway through.
15+
url.parse(input);
16+
v8.setFlagsFromString('--allow_natives_syntax');
17+
eval('%OptimizeFunctionOnNextCall(url.parse)');
18+
19+
bench.start();
20+
for (var i = 0; i < n; i += 1)
21+
url.parse(input);
22+
bench.end(n);
23+
}
24+
25+
function useNew(n, input) {
26+
bench.start();
27+
for (var i = 0; i < n; i += 1)
28+
new url.URL(input);
29+
bench.end(n);
30+
}
31+
32+
function main(conf) {
33+
const type = conf.type;
34+
const n = conf.n | 0;
35+
const method = conf.method;
36+
37+
var inputs = {
38+
one: 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj',
39+
two: 'http://blog.nodejs.org/',
40+
three: 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
41+
four: 'javascript:alert("node is awesome");',
42+
//five: 'some.ran/dom/url.thing?oh=yes#whoo',
43+
five: 'https://user:[email protected]/',
44+
};
45+
var input = inputs[type] || '';
46+
47+
switch (method) {
48+
case 'old':
49+
useOld(n, input);
50+
break;
51+
case 'new':
52+
useNew(n, input);
53+
break;
54+
default:
55+
throw new Error('Unknown method');
56+
}
57+
}

0 commit comments

Comments
 (0)