mirror of
https://github.com/nodejs/node.git
synced 2026-11-21 12:59:16 -05:00
lib: flag to conditionally modify proto on deprecate
Refs: https://github.com/nodejs/node/issues/58218 Signed-off-by: RafaelGSS <rafael.nunu@hotmail.com> PR-URL: https://github.com/nodejs/node/pull/58928 Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com>
This commit is contained in:
1 parent
d86cc9dc82
commit
2fc25fd400
2 files changed
+53
-13
No files matched your search
@@ -0,0 +1,36 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
const assert = require('assert');
|
||||
|
||||
const bench = common.createBenchmark(main, {
|
||||
n: [1e5],
|
||||
modifyPrototype: [1, 0],
|
||||
emitWarningSync: [1, 0],
|
||||
}, {
|
||||
flags: ['--expose-internals'],
|
||||
});
|
||||
|
||||
function simpleFunction(x) {
|
||||
return x * 2 + (new Array(1000)).fill(0).map((_, i) => i).reduce((a, b) => a + b, 0);
|
||||
}
|
||||
|
||||
function main({ n, modifyPrototype, emitWarningSync }) {
|
||||
const { deprecate } = require('internal/util');
|
||||
|
||||
const fn = deprecate(
|
||||
simpleFunction,
|
||||
'This function is deprecated',
|
||||
'DEP0000',
|
||||
emitWarningSync,
|
||||
!!modifyPrototype,
|
||||
);
|
||||
|
||||
let sum = 0;
|
||||
bench.start();
|
||||
for (let i = 0; i < n; ++i) {
|
||||
sum += fn(i);
|
||||
}
|
||||
bench.end(n);
|
||||
assert.ok(sum);
|
||||
}
|
||||
Reference in new issue
Block a user