Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

url: adding WHATWG URL support #7448

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions benchmark/url/new-url-parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
'use strict';
const common = require('../common.js');
const url = require('url');
const v8 = require('v8');

const bench = common.createBenchmark(main, {
type: 'one two three four five'.split(' '),
method: ['old', 'new'],
n: [25e4]
});

function useOld(n, input) {
// Force-optimize url.parse() so that the benchmark doesn't get
// disrupted by the optimizer kicking in halfway through.
url.parse(input);
v8.setFlagsFromString('--allow_natives_syntax');
eval('%OptimizeFunctionOnNextCall(url.parse)');

bench.start();
for (var i = 0; i < n; i += 1)
url.parse(input);
bench.end(n);
}

function useNew(n, input) {
bench.start();
for (var i = 0; i < n; i += 1)
new url.URL(input);
bench.end(n);
}

function main(conf) {
const type = conf.type;
const n = conf.n | 0;
const method = conf.method;

var inputs = {
one: 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj',
two: 'http://blog.nodejs.org/',
three: 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en',
four: 'javascript:alert("node is awesome");',
//five: 'some.ran/dom/url.thing?oh=yes#whoo',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is not used?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The WHATWG URL parser algorithm does not support URLs that do not have a scheme prefix without a base URL so the five case is always an error.

Copy link
Member

@RReverser RReverser Jul 20, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps use http:// (literally, without any domain) as default base URL for the parser?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The initial goal to impl the WHATWG parsing spec as is without introducing
any additional default behavior. As such, since that spec does not assume a
default, neither does this impl. I do believe it may be worthwhile adding
an escape hatch for extended behaviors with the understanding that those
are nonstandard.

On Jul 20, 2016 10:09 AM, "Ingvar Stepanyan" [email protected]
wrote:

In benchmark/url/new-url-parse.js
#7448 (comment):

  • for (var i = 0; i < n; i += 1)
  • new url.URL(input);
  • bench.end(n);
    +}

+function main(conf) {

  • const type = conf.type;
  • const n = conf.n | 0;
  • const method = conf.method;

Perhaps use http:// as default base URL for the parser?


You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/nodejs/node/pull/7448/files/367924f52d393fc398a340bb5ee60d1a10a5cdf2#r71566061,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAa2ecJo9qtJYSMQ_zYGpiq-kjQwd8sSks5qXlZPgaJpZM4I_c8x
.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, base URLs should be explicit. You shouldn't accept relative URLs as absolute ones. They should error.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant having default base URL for test purposes only (so that we could check parsing of relative URLs with given base).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The standard tests cover this well already. This particular case is in the benchmarks, which currently do not cover base URLs as I wanted to keep the benchmark as close to the existing url.parse benchmark as possible.

five: 'https://user:[email protected]/',
};
var input = inputs[type] || '';

switch (method) {
case 'old':
useOld(n, input);
break;
case 'new':
useNew(n, input);
break;
default:
throw new Error('Unknown method');
}
}
Loading