Comments (9)
Did you find changing the arity for a deprecated function caused programs to break?
There are dumb interfaces that depend on arity, for example expressjs-style middlewares need their arities.
However, if it is a big deal, then I'd suggest instead having several wrapArity1(fn), wrapArity2(fn), and so forth, up to... 6? 10? It could be small as well.
No, the code generation can handle that. I'll definitely look into the issue. Do you know what is causing the slow down? How would I make something that would implement an arity differently? Basically the wrap tries to make the deprecated function look as close as possible to the original: it keeps fn.length
the same, keeps arguments.length
the same within the original function, etc.
I would welcome a suggestion or PR that meets these requirements, though :)
from nodejs-depd.
P.S. I'm going to start looking through how you are using depd
in https://github.com/seanmonstar/intel to see how I can add some more convenience methods that may be more useful. So far it does look like what you are doing with __deprecatedCallback
may be better off using deprecate
directly instead of wrapping an empty function, but I'm still looking at your use-case and thinking about it.
from nodejs-depd.
I've been toying with this in a fork:
function wrapfunction(fn, message) {
if (typeof fn !== 'function') {
throw new TypeError('argument fn must be a function')
}
var deprecate = this
var stack = getStack()
var site = callSiteLocation(stack[1])
site.name = fn.name
var wrapper = arityWrappers[fn.length] || arityWrappers[0];
return wrapper(function() {
log.call(deprecate, message, site);
return fn.apply(this, arguments);
});
}
var arityWrappers = {
'0': function arity0(fn) {
return function() {
return fn.apply(this, arguments);
}
},
'1': function arity1(fn) {
return function(a) {
return fn.apply(this, arguments);
}
}
'2': function arity2(fn) {
return function(a, b) {
return fn.apply(this, arguments);
}
}
'3': function arity3(fn) {
return function(a, b, c) {
return fn.apply(this, arguments);
}
}
'4': function arity4(fn) {
return function(a, b, c, d) {
return fn.apply(this, arguments);
}
}
}
Of course, it could extend out to a sane number of arguments (someone has a function with more than 10 arity, they should be shot?).
from nodejs-depd.
So far it does look like what you are doing with __deprecatedCallback may be better off using deprecate directly instead of wrapping an empty function, but I'm still looking at your use-case and thinking about it.
I have switched to using deprecate directly.
this.__deprecatedCallback = function deprecated() {
deprecate('Handler.emit callback argument has been removed');
};
// in handle()
this.emit(record, this.__deprecatedCallback);
I need to pass a function argument, so people don't end up with undefined()
. I can't pass deprecate
itself, cause when my users execute the callback, it would just be generating a function, instead of leaving a warning.
from nodejs-depd.
Oh, by "use deprecate directly" I meant using to what you changed it to for now :)
So from your examples, it looks like the one-time eval is making all future calls slow?
from nodejs-depd.
Hrm, trying again with a different computer saw now speed lost. Differences between computes: Slow: Ubuntu 14.04, node v0.10.20. Fast: Windows 7, node v0.10.26.
process.versions
says that v8 is v3.14.5.9 in both, which I'd think would be the reason for eval behaving differently...
from nodejs-depd.
It could just be my one computer gone crazy, as I can't repro on others (though, it continues to show on the Ubuntu.). I'd recommend closing unless it repros anywhere else.
from nodejs-depd.
I'd recommend closing unless it repros anywhere else.
The fact that you took the time to report it makes me want to at least look into it myself as well, because there could be something to it :) I don't want to close it just yet because there may well be an issue and I just haven't had the time to dig in yet.
from nodejs-depd.
@seanmonstar sorry for the long delay :( So I was able to examine it and there is a slow down. Using the wrapper is much slower per call than just calling deprecate(msg)
within your function. There is a v8 trick to make them the same, though, which I'm adding. I added a simple benchmark as well so I could see that it actually made the calls faster.
from nodejs-depd.
Related Issues (20)
- Fail gracefully in unsupported browsers HOT 15
- Drop eval usage HOT 21
- line info is not help HOT 8
- Cannot redefine property: callSiteToString HOT 2
- Call-site calculation does not fail gracefully when Stack information is unavailable HOT 14
- Call site calculation fails when importing an esm'ed package that imports sequelize internally HOT 14
- Respect --no-deprecation and process.noDeprecation HOT 17
- TypeError: eval is not a function HOT 8
- Why is this library overwriting Error type? HOT 5
- Turkish Language Problem HOT 2
- Incopatibile with --enable-source-maps node 12 option HOT 7
- (!) Use of eval is strongly discouraged, rollup HOT 1
- compatibility with Node.js' source-map implementation HOT 12
- please rewrite nodejs-depd with modern syntax HOT 1
- Compatibility with --disallow-code-generation-from-strings HOT 9
- Use of eval() is strongly discouraged, as it poses security risks HOT 9
- Calling `process.cwd()` from index.js can be problematic HOT 4
- callSite.getFileName() is not Function HOT 5
- `callSite.getFileName` is not a function HOT 10
- NodeJS 20.11.0 fails when building snapshot.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nodejs-depd.