Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: use a global symbol for util.promisify.custom
Define `util.promisify.custom`
as `Symbol.for("nodejs.util.inspect.custom")`, rather than
as `Symbol("util.inspect.custom")`.

This allows custom `promisify` wrappers to easily/safely be defined
in non‑Node.js environments.

Refs: nodejs/node#31647
Refs: nodejs/node#31672
  • Loading branch information
ExE-Boss committed Feb 8, 2020
commit f89af7de3250ee8a5da72fe6965bc17e7e743b45
5 changes: 4 additions & 1 deletion util.js
Original file line number Diff line number Diff line change
Expand Up @@ -607,7 +607,10 @@ function hasOwnProperty(obj, prop) {
return Object.prototype.hasOwnProperty.call(obj, prop);
}

var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
var kCustomPromisifiedSymbol =
typeof Symbol === 'function' && typeof Symbol['for'] === 'function'
? Symbol['for']('nodejs.util.promisify.custom')
: undefined;

exports.promisify = function promisify(original) {
if (typeof original !== 'function')
Expand Down