-
-
Notifications
You must be signed in to change notification settings - Fork 89
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
fix: callbackify resulting function should have one more argument #72
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
module.exports = function isFunctionLengthConfigurable(arg) { | ||
return Object.getOwnPropertyDescriptor(function () { }, 'length').configurable; | ||
} | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
module.exports = function nodeJSVersion(arg) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This shouldn’t be needed at all; the feature detection is sufficient (and more reliable) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you elaborate? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm skeptical - in my experimentation, it works fine in node 10: function f() {}
Object.getOwnPropertyDescriptor(f, 'length').configurable; // true
Object.defineProperty(f, 'length', { value: 42 });
f.length; // 42 but then we should be feature-detecting this failure. we shouldn't be hardcoding specific versions of things, especially since any issue in specific node versions also matches issues in some Chrome versions. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ljharb , yes fct.length is configurable in node10 onward but the util.callbackify do not take advantage of this and keep the fct.length unchanged. the behavior has been fixed by the nodejs team from node12 onwards.
Let me know if there is anything else I can do . There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this still seems an issue, since this file shouldn't exist |
||
|
||
if (!process || !process.version || !process.version.match(/^v(\d+)\.(\d+)/)) { | ||
return false; | ||
} | ||
return parseInt(process.version.split('.')[0].slice(1), 10); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -703,13 +703,21 @@ function callbackify(original) { | |
// In true node style we process the callback on `nextTick` with all the | ||
// implications (stack, `uncaughtException`, `async_hooks`) | ||
original.apply(this, args) | ||
.then(function(ret) { process.nextTick(cb.bind(null, null, ret)) }, | ||
function(rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) }); | ||
.then(function (ret) { process.nextTick(cb.bind(null, null, ret)) }, | ||
function (rej) { process.nextTick(callbackifyOnRejected.bind(null, rej, cb)) }); | ||
} | ||
|
||
Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original)); | ||
Object.defineProperties(callbackified, | ||
getOwnPropertyDescriptors(original)); | ||
const desc = getOwnPropertyDescriptors(original); | ||
erossignon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
var isFunctionLengthConfigurable = Object.getOwnPropertyDescriptor(callbackified, 'length').configurable; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be using the file above, or better |
||
|
||
// versions of NodeJS <12.0 have a bug where the callback's `length` is not adjusted as in recent NodeJS version | ||
// even though functionLength is configurable. | ||
if (isFunctionLengthConfigurable) { | ||
desc.length.value += 1; | ||
} | ||
|
||
Object.defineProperties(callbackified, desc); | ||
erossignon marked this conversation as resolved.
Show resolved
Hide resolved
erossignon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return callbackified; | ||
} | ||
exports.callbackify = callbackify; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this already exists on npm - https://npmjs.com/functions-have-names in the
functionsHaveConfigurableNames
property. let's just use that.