Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

util.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. // Copyright Joyent, Inc. and other Node contributors.
  2. //
  3. // Permission is hereby granted, free of charge, to any person obtaining a
  4. // copy of this software and associated documentation files (the
  5. // "Software"), to deal in the Software without restriction, including
  6. // without limitation the rights to use, copy, modify, merge, publish,
  7. // distribute, sublicense, and/or sell copies of the Software, and to permit
  8. // persons to whom the Software is furnished to do so, subject to the
  9. // following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included
  12. // in all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  15. // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  16. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
  17. // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
  18. // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
  19. // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
  20. // USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. var getOwnPropertyDescriptors = Object.getOwnPropertyDescriptors ||
  22. function getOwnPropertyDescriptors(obj) {
  23. var keys = Object.keys(obj);
  24. var descriptors = {};
  25. for (var i = 0; i < keys.length; i++) {
  26. descriptors[keys[i]] = Object.getOwnPropertyDescriptor(obj, keys[i]);
  27. }
  28. return descriptors;
  29. };
  30. var formatRegExp = /%[sdj%]/g;
  31. exports.format = function(f) {
  32. if (!isString(f)) {
  33. var objects = [];
  34. for (var i = 0; i < arguments.length; i++) {
  35. objects.push(inspect(arguments[i]));
  36. }
  37. return objects.join(' ');
  38. }
  39. var i = 1;
  40. var args = arguments;
  41. var len = args.length;
  42. var str = String(f).replace(formatRegExp, function(x) {
  43. if (x === '%%') return '%';
  44. if (i >= len) return x;
  45. switch (x) {
  46. case '%s': return String(args[i++]);
  47. case '%d': return Number(args[i++]);
  48. case '%j':
  49. try {
  50. return JSON.stringify(args[i++]);
  51. } catch (_) {
  52. return '[Circular]';
  53. }
  54. default:
  55. return x;
  56. }
  57. });
  58. for (var x = args[i]; i < len; x = args[++i]) {
  59. if (isNull(x) || !isObject(x)) {
  60. str += ' ' + x;
  61. } else {
  62. str += ' ' + inspect(x);
  63. }
  64. }
  65. return str;
  66. };
  67. // Mark that a method should not be used.
  68. // Returns a modified function which warns once by default.
  69. // If --no-deprecation is set, then it is a no-op.
  70. exports.deprecate = function(fn, msg) {
  71. if (typeof process !== 'undefined' && process.noDeprecation === true) {
  72. return fn;
  73. }
  74. // Allow for deprecating things in the process of starting up.
  75. if (typeof process === 'undefined') {
  76. return function() {
  77. return exports.deprecate(fn, msg).apply(this, arguments);
  78. };
  79. }
  80. var warned = false;
  81. function deprecated() {
  82. if (!warned) {
  83. if (process.throwDeprecation) {
  84. throw new Error(msg);
  85. } else if (process.traceDeprecation) {
  86. console.trace(msg);
  87. } else {
  88. console.error(msg);
  89. }
  90. warned = true;
  91. }
  92. return fn.apply(this, arguments);
  93. }
  94. return deprecated;
  95. };
  96. var debugs = {};
  97. var debugEnviron;
  98. exports.debuglog = function(set) {
  99. if (isUndefined(debugEnviron))
  100. debugEnviron = process.env.NODE_DEBUG || '';
  101. set = set.toUpperCase();
  102. if (!debugs[set]) {
  103. if (new RegExp('\\b' + set + '\\b', 'i').test(debugEnviron)) {
  104. var pid = process.pid;
  105. debugs[set] = function() {
  106. var msg = exports.format.apply(exports, arguments);
  107. console.error('%s %d: %s', set, pid, msg);
  108. };
  109. } else {
  110. debugs[set] = function() {};
  111. }
  112. }
  113. return debugs[set];
  114. };
  115. /**
  116. * Echos the value of a value. Trys to print the value out
  117. * in the best way possible given the different types.
  118. *
  119. * @param {Object} obj The object to print out.
  120. * @param {Object} opts Optional options object that alters the output.
  121. */
  122. /* legacy: obj, showHidden, depth, colors*/
  123. function inspect(obj, opts) {
  124. // default options
  125. var ctx = {
  126. seen: [],
  127. stylize: stylizeNoColor
  128. };
  129. // legacy...
  130. if (arguments.length >= 3) ctx.depth = arguments[2];
  131. if (arguments.length >= 4) ctx.colors = arguments[3];
  132. if (isBoolean(opts)) {
  133. // legacy...
  134. ctx.showHidden = opts;
  135. } else if (opts) {
  136. // got an "options" object
  137. exports._extend(ctx, opts);
  138. }
  139. // set default options
  140. if (isUndefined(ctx.showHidden)) ctx.showHidden = false;
  141. if (isUndefined(ctx.depth)) ctx.depth = 2;
  142. if (isUndefined(ctx.colors)) ctx.colors = false;
  143. if (isUndefined(ctx.customInspect)) ctx.customInspect = true;
  144. if (ctx.colors) ctx.stylize = stylizeWithColor;
  145. return formatValue(ctx, obj, ctx.depth);
  146. }
  147. exports.inspect = inspect;
  148. // http://en.wikipedia.org/wiki/ANSI_escape_code#graphics
  149. inspect.colors = {
  150. 'bold' : [1, 22],
  151. 'italic' : [3, 23],
  152. 'underline' : [4, 24],
  153. 'inverse' : [7, 27],
  154. 'white' : [37, 39],
  155. 'grey' : [90, 39],
  156. 'black' : [30, 39],
  157. 'blue' : [34, 39],
  158. 'cyan' : [36, 39],
  159. 'green' : [32, 39],
  160. 'magenta' : [35, 39],
  161. 'red' : [31, 39],
  162. 'yellow' : [33, 39]
  163. };
  164. // Don't use 'blue' not visible on cmd.exe
  165. inspect.styles = {
  166. 'special': 'cyan',
  167. 'number': 'yellow',
  168. 'boolean': 'yellow',
  169. 'undefined': 'grey',
  170. 'null': 'bold',
  171. 'string': 'green',
  172. 'date': 'magenta',
  173. // "name": intentionally not styling
  174. 'regexp': 'red'
  175. };
  176. function stylizeWithColor(str, styleType) {
  177. var style = inspect.styles[styleType];
  178. if (style) {
  179. return '\u001b[' + inspect.colors[style][0] + 'm' + str +
  180. '\u001b[' + inspect.colors[style][1] + 'm';
  181. } else {
  182. return str;
  183. }
  184. }
  185. function stylizeNoColor(str, styleType) {
  186. return str;
  187. }
  188. function arrayToHash(array) {
  189. var hash = {};
  190. array.forEach(function(val, idx) {
  191. hash[val] = true;
  192. });
  193. return hash;
  194. }
  195. function formatValue(ctx, value, recurseTimes) {
  196. // Provide a hook for user-specified inspect functions.
  197. // Check that value is an object with an inspect function on it
  198. if (ctx.customInspect &&
  199. value &&
  200. isFunction(value.inspect) &&
  201. // Filter out the util module, it's inspect function is special
  202. value.inspect !== exports.inspect &&
  203. // Also filter out any prototype objects using the circular check.
  204. !(value.constructor && value.constructor.prototype === value)) {
  205. var ret = value.inspect(recurseTimes, ctx);
  206. if (!isString(ret)) {
  207. ret = formatValue(ctx, ret, recurseTimes);
  208. }
  209. return ret;
  210. }
  211. // Primitive types cannot have properties
  212. var primitive = formatPrimitive(ctx, value);
  213. if (primitive) {
  214. return primitive;
  215. }
  216. // Look up the keys of the object.
  217. var keys = Object.keys(value);
  218. var visibleKeys = arrayToHash(keys);
  219. if (ctx.showHidden) {
  220. keys = Object.getOwnPropertyNames(value);
  221. }
  222. // IE doesn't make error fields non-enumerable
  223. // http://msdn.microsoft.com/en-us/library/ie/dww52sbt(v=vs.94).aspx
  224. if (isError(value)
  225. && (keys.indexOf('message') >= 0 || keys.indexOf('description') >= 0)) {
  226. return formatError(value);
  227. }
  228. // Some type of object without properties can be shortcutted.
  229. if (keys.length === 0) {
  230. if (isFunction(value)) {
  231. var name = value.name ? ': ' + value.name : '';
  232. return ctx.stylize('[Function' + name + ']', 'special');
  233. }
  234. if (isRegExp(value)) {
  235. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  236. }
  237. if (isDate(value)) {
  238. return ctx.stylize(Date.prototype.toString.call(value), 'date');
  239. }
  240. if (isError(value)) {
  241. return formatError(value);
  242. }
  243. }
  244. var base = '', array = false, braces = ['{', '}'];
  245. // Make Array say that they are Array
  246. if (isArray(value)) {
  247. array = true;
  248. braces = ['[', ']'];
  249. }
  250. // Make functions say that they are functions
  251. if (isFunction(value)) {
  252. var n = value.name ? ': ' + value.name : '';
  253. base = ' [Function' + n + ']';
  254. }
  255. // Make RegExps say that they are RegExps
  256. if (isRegExp(value)) {
  257. base = ' ' + RegExp.prototype.toString.call(value);
  258. }
  259. // Make dates with properties first say the date
  260. if (isDate(value)) {
  261. base = ' ' + Date.prototype.toUTCString.call(value);
  262. }
  263. // Make error with message first say the error
  264. if (isError(value)) {
  265. base = ' ' + formatError(value);
  266. }
  267. if (keys.length === 0 && (!array || value.length == 0)) {
  268. return braces[0] + base + braces[1];
  269. }
  270. if (recurseTimes < 0) {
  271. if (isRegExp(value)) {
  272. return ctx.stylize(RegExp.prototype.toString.call(value), 'regexp');
  273. } else {
  274. return ctx.stylize('[Object]', 'special');
  275. }
  276. }
  277. ctx.seen.push(value);
  278. var output;
  279. if (array) {
  280. output = formatArray(ctx, value, recurseTimes, visibleKeys, keys);
  281. } else {
  282. output = keys.map(function(key) {
  283. return formatProperty(ctx, value, recurseTimes, visibleKeys, key, array);
  284. });
  285. }
  286. ctx.seen.pop();
  287. return reduceToSingleString(output, base, braces);
  288. }
  289. function formatPrimitive(ctx, value) {
  290. if (isUndefined(value))
  291. return ctx.stylize('undefined', 'undefined');
  292. if (isString(value)) {
  293. var simple = '\'' + JSON.stringify(value).replace(/^"|"$/g, '')
  294. .replace(/'/g, "\\'")
  295. .replace(/\\"/g, '"') + '\'';
  296. return ctx.stylize(simple, 'string');
  297. }
  298. if (isNumber(value))
  299. return ctx.stylize('' + value, 'number');
  300. if (isBoolean(value))
  301. return ctx.stylize('' + value, 'boolean');
  302. // For some reason typeof null is "object", so special case here.
  303. if (isNull(value))
  304. return ctx.stylize('null', 'null');
  305. }
  306. function formatError(value) {
  307. return '[' + Error.prototype.toString.call(value) + ']';
  308. }
  309. function formatArray(ctx, value, recurseTimes, visibleKeys, keys) {
  310. var output = [];
  311. for (var i = 0, l = value.length; i < l; ++i) {
  312. if (hasOwnProperty(value, String(i))) {
  313. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  314. String(i), true));
  315. } else {
  316. output.push('');
  317. }
  318. }
  319. keys.forEach(function(key) {
  320. if (!key.match(/^\d+$/)) {
  321. output.push(formatProperty(ctx, value, recurseTimes, visibleKeys,
  322. key, true));
  323. }
  324. });
  325. return output;
  326. }
  327. function formatProperty(ctx, value, recurseTimes, visibleKeys, key, array) {
  328. var name, str, desc;
  329. desc = Object.getOwnPropertyDescriptor(value, key) || { value: value[key] };
  330. if (desc.get) {
  331. if (desc.set) {
  332. str = ctx.stylize('[Getter/Setter]', 'special');
  333. } else {
  334. str = ctx.stylize('[Getter]', 'special');
  335. }
  336. } else {
  337. if (desc.set) {
  338. str = ctx.stylize('[Setter]', 'special');
  339. }
  340. }
  341. if (!hasOwnProperty(visibleKeys, key)) {
  342. name = '[' + key + ']';
  343. }
  344. if (!str) {
  345. if (ctx.seen.indexOf(desc.value) < 0) {
  346. if (isNull(recurseTimes)) {
  347. str = formatValue(ctx, desc.value, null);
  348. } else {
  349. str = formatValue(ctx, desc.value, recurseTimes - 1);
  350. }
  351. if (str.indexOf('\n') > -1) {
  352. if (array) {
  353. str = str.split('\n').map(function(line) {
  354. return ' ' + line;
  355. }).join('\n').substr(2);
  356. } else {
  357. str = '\n' + str.split('\n').map(function(line) {
  358. return ' ' + line;
  359. }).join('\n');
  360. }
  361. }
  362. } else {
  363. str = ctx.stylize('[Circular]', 'special');
  364. }
  365. }
  366. if (isUndefined(name)) {
  367. if (array && key.match(/^\d+$/)) {
  368. return str;
  369. }
  370. name = JSON.stringify('' + key);
  371. if (name.match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)) {
  372. name = name.substr(1, name.length - 2);
  373. name = ctx.stylize(name, 'name');
  374. } else {
  375. name = name.replace(/'/g, "\\'")
  376. .replace(/\\"/g, '"')
  377. .replace(/(^"|"$)/g, "'");
  378. name = ctx.stylize(name, 'string');
  379. }
  380. }
  381. return name + ': ' + str;
  382. }
  383. function reduceToSingleString(output, base, braces) {
  384. var numLinesEst = 0;
  385. var length = output.reduce(function(prev, cur) {
  386. numLinesEst++;
  387. if (cur.indexOf('\n') >= 0) numLinesEst++;
  388. return prev + cur.replace(/\u001b\[\d\d?m/g, '').length + 1;
  389. }, 0);
  390. if (length > 60) {
  391. return braces[0] +
  392. (base === '' ? '' : base + '\n ') +
  393. ' ' +
  394. output.join(',\n ') +
  395. ' ' +
  396. braces[1];
  397. }
  398. return braces[0] + base + ' ' + output.join(', ') + ' ' + braces[1];
  399. }
  400. // NOTE: These type checking functions intentionally don't use `instanceof`
  401. // because it is fragile and can be easily faked with `Object.create()`.
  402. function isArray(ar) {
  403. return Array.isArray(ar);
  404. }
  405. exports.isArray = isArray;
  406. function isBoolean(arg) {
  407. return typeof arg === 'boolean';
  408. }
  409. exports.isBoolean = isBoolean;
  410. function isNull(arg) {
  411. return arg === null;
  412. }
  413. exports.isNull = isNull;
  414. function isNullOrUndefined(arg) {
  415. return arg == null;
  416. }
  417. exports.isNullOrUndefined = isNullOrUndefined;
  418. function isNumber(arg) {
  419. return typeof arg === 'number';
  420. }
  421. exports.isNumber = isNumber;
  422. function isString(arg) {
  423. return typeof arg === 'string';
  424. }
  425. exports.isString = isString;
  426. function isSymbol(arg) {
  427. return typeof arg === 'symbol';
  428. }
  429. exports.isSymbol = isSymbol;
  430. function isUndefined(arg) {
  431. return arg === void 0;
  432. }
  433. exports.isUndefined = isUndefined;
  434. function isRegExp(re) {
  435. return isObject(re) && objectToString(re) === '[object RegExp]';
  436. }
  437. exports.isRegExp = isRegExp;
  438. function isObject(arg) {
  439. return typeof arg === 'object' && arg !== null;
  440. }
  441. exports.isObject = isObject;
  442. function isDate(d) {
  443. return isObject(d) && objectToString(d) === '[object Date]';
  444. }
  445. exports.isDate = isDate;
  446. function isError(e) {
  447. return isObject(e) &&
  448. (objectToString(e) === '[object Error]' || e instanceof Error);
  449. }
  450. exports.isError = isError;
  451. function isFunction(arg) {
  452. return typeof arg === 'function';
  453. }
  454. exports.isFunction = isFunction;
  455. function isPrimitive(arg) {
  456. return arg === null ||
  457. typeof arg === 'boolean' ||
  458. typeof arg === 'number' ||
  459. typeof arg === 'string' ||
  460. typeof arg === 'symbol' || // ES6 symbol
  461. typeof arg === 'undefined';
  462. }
  463. exports.isPrimitive = isPrimitive;
  464. exports.isBuffer = require('./support/isBuffer');
  465. function objectToString(o) {
  466. return Object.prototype.toString.call(o);
  467. }
  468. function pad(n) {
  469. return n < 10 ? '0' + n.toString(10) : n.toString(10);
  470. }
  471. var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep',
  472. 'Oct', 'Nov', 'Dec'];
  473. // 26 Feb 16:19:34
  474. function timestamp() {
  475. var d = new Date();
  476. var time = [pad(d.getHours()),
  477. pad(d.getMinutes()),
  478. pad(d.getSeconds())].join(':');
  479. return [d.getDate(), months[d.getMonth()], time].join(' ');
  480. }
  481. // log is just a thin wrapper to console.log that prepends a timestamp
  482. exports.log = function() {
  483. console.log('%s - %s', timestamp(), exports.format.apply(exports, arguments));
  484. };
  485. /**
  486. * Inherit the prototype methods from one constructor into another.
  487. *
  488. * The Function.prototype.inherits from lang.js rewritten as a standalone
  489. * function (not on Function.prototype). NOTE: If this file is to be loaded
  490. * during bootstrapping this function needs to be rewritten using some native
  491. * functions as prototype setup using normal JavaScript does not work as
  492. * expected during bootstrapping (see mirror.js in r114903).
  493. *
  494. * @param {function} ctor Constructor function which needs to inherit the
  495. * prototype.
  496. * @param {function} superCtor Constructor function to inherit prototype from.
  497. */
  498. exports.inherits = require('inherits');
  499. exports._extend = function(origin, add) {
  500. // Don't do anything if add isn't an object
  501. if (!add || !isObject(add)) return origin;
  502. var keys = Object.keys(add);
  503. var i = keys.length;
  504. while (i--) {
  505. origin[keys[i]] = add[keys[i]];
  506. }
  507. return origin;
  508. };
  509. function hasOwnProperty(obj, prop) {
  510. return Object.prototype.hasOwnProperty.call(obj, prop);
  511. }
  512. var kCustomPromisifiedSymbol = typeof Symbol !== 'undefined' ? Symbol('util.promisify.custom') : undefined;
  513. exports.promisify = function promisify(original) {
  514. if (typeof original !== 'function')
  515. throw new TypeError('The "original" argument must be of type Function');
  516. if (kCustomPromisifiedSymbol && original[kCustomPromisifiedSymbol]) {
  517. var fn = original[kCustomPromisifiedSymbol];
  518. if (typeof fn !== 'function') {
  519. throw new TypeError('The "util.promisify.custom" argument must be of type Function');
  520. }
  521. Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  522. value: fn, enumerable: false, writable: false, configurable: true
  523. });
  524. return fn;
  525. }
  526. function fn() {
  527. var promiseResolve, promiseReject;
  528. var promise = new Promise(function (resolve, reject) {
  529. promiseResolve = resolve;
  530. promiseReject = reject;
  531. });
  532. var args = [];
  533. for (var i = 0; i < arguments.length; i++) {
  534. args.push(arguments[i]);
  535. }
  536. args.push(function (err, value) {
  537. if (err) {
  538. promiseReject(err);
  539. } else {
  540. promiseResolve(value);
  541. }
  542. });
  543. try {
  544. original.apply(this, args);
  545. } catch (err) {
  546. promiseReject(err);
  547. }
  548. return promise;
  549. }
  550. Object.setPrototypeOf(fn, Object.getPrototypeOf(original));
  551. if (kCustomPromisifiedSymbol) Object.defineProperty(fn, kCustomPromisifiedSymbol, {
  552. value: fn, enumerable: false, writable: false, configurable: true
  553. });
  554. return Object.defineProperties(
  555. fn,
  556. getOwnPropertyDescriptors(original)
  557. );
  558. }
  559. exports.promisify.custom = kCustomPromisifiedSymbol
  560. function callbackifyOnRejected(reason, cb) {
  561. // `!reason` guard inspired by bluebird (Ref: https://goo.gl/t5IS6M).
  562. // Because `null` is a special error value in callbacks which means "no error
  563. // occurred", we error-wrap so the callback consumer can distinguish between
  564. // "the promise rejected with null" or "the promise fulfilled with undefined".
  565. if (!reason) {
  566. var newReason = new Error('Promise was rejected with a falsy value');
  567. newReason.reason = reason;
  568. reason = newReason;
  569. }
  570. return cb(reason);
  571. }
  572. function callbackify(original) {
  573. if (typeof original !== 'function') {
  574. throw new TypeError('The "original" argument must be of type Function');
  575. }
  576. // We DO NOT return the promise as it gives the user a false sense that
  577. // the promise is actually somehow related to the callback's execution
  578. // and that the callback throwing will reject the promise.
  579. function callbackified() {
  580. var args = [];
  581. for (var i = 0; i < arguments.length; i++) {
  582. args.push(arguments[i]);
  583. }
  584. var maybeCb = args.pop();
  585. if (typeof maybeCb !== 'function') {
  586. throw new TypeError('The last argument must be of type Function');
  587. }
  588. var self = this;
  589. var cb = function() {
  590. return maybeCb.apply(self, arguments);
  591. };
  592. // In true node style we process the callback on `nextTick` with all the
  593. // implications (stack, `uncaughtException`, `async_hooks`)
  594. original.apply(this, args)
  595. .then(function(ret) { process.nextTick(cb, null, ret) },
  596. function(rej) { process.nextTick(callbackifyOnRejected, rej, cb) });
  597. }
  598. Object.setPrototypeOf(callbackified, Object.getPrototypeOf(original));
  599. Object.defineProperties(callbackified,
  600. getOwnPropertyDescriptors(original));
  601. return callbackified;
  602. }
  603. exports.callbackify = callbackify;