node/test/parallel/test-whatwg-url-canparse.js
Yagiz Nizipli e0500d6e88
url: fix canParse false value when v8 optimizes
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>
2023-07-17 20:29:05 -04:00

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);
}