@@ -20,23 +20,29 @@ assert.throws(() => {
2020assert . strictEqual ( URL . canParse ( 'https://example.org' ) , true ) ;
2121
2222{
23- // V8 Fast API
24- function testFastPaths ( ) {
25- // `canParse` binding has two overloads.
26- assert . strictEqual ( URL . canParse ( 'https://www.example.com/path/?query=param#hash' ) , true ) ;
27- assert . strictEqual ( URL . canParse ( '/' , 'http://n' ) , true ) ;
23+ // Only javascript methods can be optimized through %OptimizeFunctionOnNextCall
24+ // This is why we surround the C++ method we want to optimize with a JS function.
25+ function canParse ( input ) {
26+ return URL . canParse ( input ) ;
2827 }
2928
30- eval ( '%PrepareFunctionForOptimization(URL.canParse)' ) ;
31- testFastPaths ( ) ;
32- eval ( '%OptimizeFunctionOnNextCall(URL.canParse)' ) ;
33- testFastPaths ( ) ;
29+ function canParseWithBase ( input , base ) {
30+ return URL . canParse ( input , base ) ;
31+ }
32+
33+ eval ( '%PrepareFunctionForOptimization(canParse)' ) ;
34+ canParse ( 'https://nodejs.org' ) ;
35+ eval ( '%OptimizeFunctionOnNextCall(canParse)' ) ;
36+ canParse ( 'https://nodejs.org' ) ;
37+
38+ eval ( '%PrepareFunctionForOptimization(canParseWithBase)' ) ;
39+ canParseWithBase ( 'https://nodejs.org' ) ;
40+ eval ( '%OptimizeFunctionOnNextCall(canParseWithBase)' ) ;
41+ canParseWithBase ( '/contact' , 'https://nodejs.org' ) ;
3442
3543 if ( common . isDebug ) {
3644 const { getV8FastApiCallCount } = internalBinding ( 'debug' ) ;
37- // TODO: the counts should be 1. The function is optimized, but the fast
38- // API is not called.
39- assert . strictEqual ( getV8FastApiCallCount ( 'url.canParse' ) , 0 ) ;
40- assert . strictEqual ( getV8FastApiCallCount ( 'url.canParse.withBase' ) , 0 ) ;
45+ assert . strictEqual ( getV8FastApiCallCount ( 'url.canParse' ) , 1 ) ;
46+ assert . strictEqual ( getV8FastApiCallCount ( 'url.canParse.withBase' ) , 1 ) ;
4147 }
4248}
0 commit comments