-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
src,test: track
URL.canParse
fast API calls
Also regroup two small test files for naming consistency and simplify the tests. PR-URL: #54356 Reviewed-By: Daniel Lemire <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
Showing
4 changed files
with
31 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,38 @@ | ||
// Flags: --expose-internals | ||
// Flags: --expose-internals --no-warnings --allow-natives-syntax | ||
'use strict'; | ||
|
||
require('../common'); | ||
const common = 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 { internalBinding } = require('internal/test/binding'); | ||
|
||
const { canParse } = internalBinding('url'); | ||
// One argument is required | ||
assert.throws(() => { | ||
URL.canParse(); | ||
}, { | ||
code: 'ERR_MISSING_ARGS', | ||
name: 'TypeError', | ||
}); | ||
|
||
// 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); | ||
|
||
if (common.isDebug) { | ||
const { getV8FastApiCallCount } = internalBinding('debug'); | ||
|
||
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(); | ||
|
||
assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1); | ||
assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters