forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-whatwg-url-canparse.js
More file actions
48 lines (38 loc) · 1.4 KB
/
Copy pathtest-whatwg-url-canparse.js
File metadata and controls
48 lines (38 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Flags: --expose-internals --no-warnings --allow-natives-syntax
'use strict';
const common = require('../common');
const { URL } = require('url');
const assert = require('assert');
const { internalBinding } = require('internal/test/binding');
// 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);
{
// Only javascript methods can be optimized through %OptimizeFunctionOnNextCall
// This is why we surround the C++ method we want to optimize with a JS function.
function canParse(input) {
return URL.canParse(input);
}
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');
assert.strictEqual(getV8FastApiCallCount('url.canParse'), 1);
assert.strictEqual(getV8FastApiCallCount('url.canParse.withBase'), 1);
}
}