Skip to content

test: fix URL v8 fast api tests #58021

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

Closed
wants to merge 1 commit into from
Closed
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
32 changes: 19 additions & 13 deletions test/parallel/test-whatwg-url-canparse.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,29 @@ assert.throws(() => {
assert.strictEqual(URL.canParse('https://example.org'), true);

{
// V8 Fast API
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);
// Only javascript methods can be optimized through %OptimizeFunctionOnNextCall
// This is why we surround the C++ method we want to optimize with a JS function.
Comment on lines +23 to +24
Copy link
Member

Choose a reason for hiding this comment

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

I think is worthy to update the fast api docs to add this note, and maybe the exception when it's called with C++, just to be easy to find the docs when someone receive this error

function canParse(input) {
return URL.canParse(input);
}

eval('%PrepareFunctionForOptimization(URL.canParse)');
testFastPaths();
eval('%OptimizeFunctionOnNextCall(URL.canParse)');
testFastPaths();
function canParseWithBase(input, base) {
return URL.canParse(input, base);
}

eval('%PrepareFunctionForOptimization(canParse)');
canParse('https://nodejs.org');
eval('%OptimizeFunctionOnNextCall(canParse)');
canParse('https://nodejs.org');

eval('%PrepareFunctionForOptimization(canParseWithBase)');
canParseWithBase('https://nodejs.org');
eval('%OptimizeFunctionOnNextCall(canParseWithBase)');
canParseWithBase('/contact', 'https://nodejs.org');

if (common.isDebug) {
const { getV8FastApiCallCount } = internalBinding('debug');
// TODO: the counts should be 1. The function is optimized, but the fast
// API is not called.
assert.strictEqual(getV8FastApiCallCount('url.canParse'), 0);
assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 0);
assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1);
assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1);
}
}
Loading