2024-08-15 14:23:43 +00:00
|
|
|
// Flags: --expose-internals --no-warnings --allow-natives-syntax
|
2023-04-14 11:34:20 +00:00
|
|
|
'use strict';
|
|
|
|
|
2024-08-15 14:23:43 +00:00
|
|
|
const common = require('../common');
|
2023-04-14 11:34:20 +00:00
|
|
|
|
|
|
|
const { URL } = require('url');
|
|
|
|
const assert = require('assert');
|
|
|
|
|
2024-08-15 14:23:43 +00:00
|
|
|
const { internalBinding } = require('internal/test/binding');
|
2023-04-14 11:34:20 +00:00
|
|
|
|
2024-08-15 14:23:43 +00:00
|
|
|
// One argument is required
|
|
|
|
assert.throws(() => {
|
|
|
|
URL.canParse();
|
|
|
|
}, {
|
|
|
|
code: 'ERR_MISSING_ARGS',
|
|
|
|
name: 'TypeError',
|
|
|
|
});
|
2023-04-14 11:34:20 +00:00
|
|
|
|
|
|
|
// It should not throw when called without a base string
|
|
|
|
assert.strictEqual(URL.canParse('https://example.org'), true);
|
2024-08-15 14:23:43 +00:00
|
|
|
|
2024-08-30 10:25:01 +00:00
|
|
|
{
|
|
|
|
// V8 Fast API
|
2024-08-15 14:23:43 +00:00
|
|
|
function testFastPaths() {
|
|
|
|
// `canParse` binding has two overloads.
|
|
|
|
assert.strictEqual(URL.canParse('https://www.example.com/path/?query=param#hash'), true);
|
|
|
|
assert.strictEqual(URL.canParse('/', 'http://n'), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
eval('%PrepareFunctionForOptimization(URL.canParse)');
|
|
|
|
testFastPaths();
|
|
|
|
eval('%OptimizeFunctionOnNextCall(URL.canParse)');
|
|
|
|
testFastPaths();
|
|
|
|
|
2024-08-30 10:25:01 +00:00
|
|
|
if (common.isDebug) {
|
|
|
|
const { getV8FastApiCallCount } = internalBinding('debug');
|
|
|
|
assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1);
|
|
|
|
assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1);
|
|
|
|
}
|
2023-07-17 17:42:23 +00:00
|
|
|
}
|