mirror of
https://github.com/nodejs/node.git
synced 2025-05-04 00:31:51 +00:00

PR-URL: https://github.com/nodejs/node/pull/48817 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
30 lines
894 B
JavaScript
30 lines
894 B
JavaScript
// Flags: --expose-internals
|
|
'use strict';
|
|
|
|
require('../common');
|
|
|
|
const { URL } = require('url');
|
|
const assert = require('assert');
|
|
|
|
let internalBinding;
|
|
try {
|
|
internalBinding = require('internal/test/binding').internalBinding;
|
|
} catch (e) {
|
|
console.log('using `test/parallel/test-whatwg-url-canparse` requires `--expose-internals`');
|
|
throw e;
|
|
}
|
|
|
|
const { canParse } = internalBinding('url');
|
|
|
|
// It should not throw when called without a base string
|
|
assert.strictEqual(URL.canParse('https://example.org'), true);
|
|
assert.strictEqual(canParse('https://example.org'), true);
|
|
|
|
// This for-loop is used to test V8 Fast API optimizations
|
|
for (let i = 0; i < 100000; i++) {
|
|
// This example is used because only parsing the first parameter
|
|
// results in an invalid URL. They have to be used together to
|
|
// produce truthy value.
|
|
assert.strictEqual(URL.canParse('/', 'http://n'), true);
|
|
}
|