| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -83,7 +83,14 @@ const { | |||
| 83 | 83 | ||
| 84 | 84 | const { FSReqCallback } = binding; | |
| 85 | 85 | const { toPathIfFileURL } = require('internal/url'); | |
| 86 | - const internalUtil = require('internal/util'); | ||
| 86 | + const { | ||
| 87 | + customPromisifyArgs: kCustomPromisifyArgsSymbol, | ||
| 88 | + deprecate, | ||
| 89 | + kEmptyObject, | ||
| 90 | + promisify: { | ||
| 91 | + custom: kCustomPromisifiedSymbol, | ||
| 92 | + }, | ||
| 93 | + } = require('internal/util'); | ||
| 87 | 94 | const { | |
| 88 | 95 | constants: { | |
| 89 | 96 | kIoMaxLength, | |
@@ -164,7 +171,7 @@ const isWindows = process.platform === 'win32'; | |||
| 164 | 171 | const isOSX = process.platform === 'darwin'; | |
| 165 | 172 | ||
| 166 | 173 | ||
| 167 | - const showStringCoercionDeprecation = internalUtil.deprecate( | ||
| 174 | + const showStringCoercionDeprecation = deprecate( | ||
| 168 | 175 | () => {}, | |
| 169 | 176 | 'Implicit coercion of objects with own toString property is deprecated.', | |
| 170 | 177 | 'DEP0162' | |
@@ -276,7 +283,7 @@ function exists(path, callback) { | |||
| 276 | 283 | } | |
| 277 | 284 | } | |
| 278 | 285 | ||
| 279 | - ObjectDefineProperty(exists, internalUtil.promisify.custom, { | ||
| 286 | + ObjectDefineProperty(exists, kCustomPromisifiedSymbol, { | ||
| 280 | 287 | __proto__: null, | |
| 281 | 288 | value: function exists(path) { // eslint-disable-line func-name-matching | |
| 282 | 289 | return new Promise((resolve) => fs.exists(path, resolve)); | |
@@ -623,7 +630,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) { | |||
| 623 | 630 | if (!isArrayBufferView(buffer)) { | |
| 624 | 631 | // This is fs.read(fd, params, callback) | |
| 625 | 632 | params = buffer; | |
| 626 | - ({ buffer = Buffer.alloc(16384) } = params ?? ObjectCreate(null)); | ||
| 633 | + ({ buffer = Buffer.alloc(16384) } = params ?? kEmptyObject); | ||
| 627 | 634 | } | |
| 628 | 635 | callback = offsetOrOptions; | |
| 629 | 636 | } else { | |
@@ -636,7 +643,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) { | |||
| 636 | 643 | offset = 0, | |
| 637 | 644 | length = buffer.byteLength - offset, | |
| 638 | 645 | position = null, | |
| 639 | - } = params ?? ObjectCreate(null)); | ||
| 646 | + } = params ?? kEmptyObject); | ||
| 640 | 647 | } | |
| 641 | 648 | ||
| 642 | 649 | validateBuffer(buffer); | |
@@ -679,7 +686,7 @@ function read(fd, buffer, offsetOrOptions, length, position, callback) { | |||
| 679 | 686 | binding.read(fd, buffer, offset, length, position, req); | |
| 680 | 687 | } | |
| 681 | 688 | ||
| 682 | - ObjectDefineProperty(read, internalUtil.customPromisifyArgs, | ||
| 689 | + ObjectDefineProperty(read, kCustomPromisifyArgsSymbol, | ||
| 683 | 690 | { __proto__: null, value: ['bytesRead', 'buffer'], enumerable: false }); | |
| 684 | 691 | ||
| 685 | 692 | /** | |
@@ -701,7 +708,7 @@ function readSync(fd, buffer, offset, length, position) { | |||
| 701 | 708 | ||
| 702 | 709 | if (arguments.length <= 3) { | |
| 703 | 710 | // Assume fs.readSync(fd, buffer, options) | |
| 704 | - const options = offset || ObjectCreate(null); | ||
| 711 | + const options = offset || kEmptyObject; | ||
| 705 | 712 | ||
| 706 | 713 | ({ | |
| 707 | 714 | offset = 0, | |
@@ -772,7 +779,7 @@ function readv(fd, buffers, position, callback) { | |||
| 772 | 779 | return binding.readBuffers(fd, buffers, position, req); | |
| 773 | 780 | } | |
| 774 | 781 | ||
| 775 | - ObjectDefineProperty(readv, internalUtil.customPromisifyArgs, | ||
| 782 | + ObjectDefineProperty(readv, kCustomPromisifyArgsSymbol, | ||
| 776 | 783 | { __proto__: null, value: ['bytesRead', 'buffers'], enumerable: false }); | |
| 777 | 784 | ||
| 778 | 785 | /** | |
@@ -829,7 +836,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) { | |||
| 829 | 836 | offset = 0, | |
| 830 | 837 | length = buffer.byteLength - offset, | |
| 831 | 838 | position = null, | |
| 832 | - } = offsetOrOptions ?? ObjectCreate(null)); | ||
| 839 | + } = offsetOrOptions ?? kEmptyObject); | ||
| 833 | 840 | } | |
| 834 | 841 | ||
| 835 | 842 | if (offset == null || typeof offset === 'function') { | |
@@ -872,7 +879,7 @@ function write(fd, buffer, offsetOrOptions, length, position, callback) { | |||
| 872 | 879 | return binding.writeString(fd, str, offset, length, req); | |
| 873 | 880 | } | |
| 874 | 881 | ||
| 875 | - ObjectDefineProperty(write, internalUtil.customPromisifyArgs, | ||
| 882 | + ObjectDefineProperty(write, kCustomPromisifyArgsSymbol, | ||
| 876 | 883 | { __proto__: null, value: ['bytesWritten', 'buffer'], enumerable: false }); | |
| 877 | 884 | ||
| 878 | 885 | /** | |
@@ -899,7 +906,7 @@ function writeSync(fd, buffer, offsetOrOptions, length, position) { | |||
| 899 | 906 | offset = 0, | |
| 900 | 907 | length = buffer.byteLength - offset, | |
| 901 | 908 | position = null, | |
| 902 | - } = offsetOrOptions ?? ObjectCreate(null)); | ||
| 909 | + } = offsetOrOptions ?? kEmptyObject); | ||
| 903 | 910 | } | |
| 904 | 911 | if (position === undefined) | |
| 905 | 912 | position = null; | |
@@ -962,7 +969,7 @@ function writev(fd, buffers, position, callback) { | |||
| 962 | 969 | return binding.writeBuffers(fd, buffers, position, req); | |
| 963 | 970 | } | |
| 964 | 971 | ||
| 965 | - ObjectDefineProperty(writev, internalUtil.customPromisifyArgs, { | ||
| 972 | + ObjectDefineProperty(writev, kCustomPromisifyArgsSymbol, { | ||
| 966 | 973 | __proto__: null, | |
| 967 | 974 | value: ['bytesWritten', 'buffer'], | |
| 968 | 975 | enumerable: false | |
@@ -1405,7 +1412,7 @@ function mkdirSync(path, options) { | |||
| 1405 | 1412 | */ | |
| 1406 | 1413 | function readdir(path, options, callback) { | |
| 1407 | 1414 | callback = makeCallback(typeof options === 'function' ? options : callback); | |
| 1408 | - options = getOptions(options, {}); | ||
| 1415 | + options = getOptions(options); | ||
| 1409 | 1416 | path = getValidatedPath(path); | |
| 1410 | 1417 | ||
| 1411 | 1418 | const req = new FSReqCallback(); | |
@@ -1434,7 +1441,7 @@ function readdir(path, options, callback) { | |||
| 1434 | 1441 | * @returns {string | Buffer[] | Dirent[]} | |
| 1435 | 1442 | */ | |
| 1436 | 1443 | function readdirSync(path, options) { | |
| 1437 | - options = getOptions(options, {}); | ||
| 1444 | + options = getOptions(options); | ||
| 1438 | 1445 | path = getValidatedPath(path); | |
| 1439 | 1446 | const ctx = { path }; | |
| 1440 | 1447 | const result = binding.readdir(pathModule.toNamespacedPath(path), | |
@@ -1458,7 +1465,7 @@ function readdirSync(path, options) { | |||
| 1458 | 1465 | function fstat(fd, options = { bigint: false }, callback) { | |
| 1459 | 1466 | if (typeof options === 'function') { | |
| 1460 | 1467 | callback = options; | |
| 1461 | - options = {}; | ||
| 1468 | + options = kEmptyObject; | ||
| 1462 | 1469 | } | |
| 1463 | 1470 | fd = getValidatedFd(fd); | |
| 1464 | 1471 | callback = makeStatsCallback(callback); | |
@@ -1482,7 +1489,7 @@ function fstat(fd, options = { bigint: false }, callback) { | |||
| 1482 | 1489 | function lstat(path, options = { bigint: false }, callback) { | |
| 1483 | 1490 | if (typeof options === 'function') { | |
| 1484 | 1491 | callback = options; | |
| 1485 | - options = {}; | ||
| 1492 | + options = kEmptyObject; | ||
| 1486 | 1493 | } | |
| 1487 | 1494 | callback = makeStatsCallback(callback); | |
| 1488 | 1495 | path = getValidatedPath(path); | |
@@ -1505,7 +1512,7 @@ function lstat(path, options = { bigint: false }, callback) { | |||
| 1505 | 1512 | function stat(path, options = { bigint: false }, callback) { | |
| 1506 | 1513 | if (typeof options === 'function') { | |
| 1507 | 1514 | callback = options; | |
| 1508 | - options = {}; | ||
| 1515 | + options = kEmptyObject; | ||
| 1509 | 1516 | } | |
| 1510 | 1517 | callback = makeStatsCallback(callback); | |
| 1511 | 1518 | path = getValidatedPath(path); | |
@@ -1603,7 +1610,7 @@ function statSync(path, options = { bigint: false, throwIfNoEntry: true }) { | |||
| 1603 | 1610 | */ | |
| 1604 | 1611 | function readlink(path, options, callback) { | |
| 1605 | 1612 | callback = makeCallback(typeof options === 'function' ? options : callback); | |
| 1606 | - options = getOptions(options, {}); | ||
| 1613 | + options = getOptions(options); | ||
| 1607 | 1614 | path = getValidatedPath(path, 'oldPath'); | |
| 1608 | 1615 | const req = new FSReqCallback(); | |
| 1609 | 1616 | req.oncomplete = callback; | |
@@ -1618,7 +1625,7 @@ function readlink(path, options, callback) { | |||
| 1618 | 1625 | * @returns {string | Buffer} | |
| 1619 | 1626 | */ | |
| 1620 | 1627 | function readlinkSync(path, options) { | |
| 1621 | - options = getOptions(options, {}); | ||
| 1628 | + options = getOptions(options); | ||
| 1622 | 1629 | path = getValidatedPath(path, 'oldPath'); | |
| 1623 | 1630 | const ctx = { path }; | |
| 1624 | 1631 | const result = binding.readlink(pathModule.toNamespacedPath(path), | |
@@ -2295,7 +2302,7 @@ function watch(filename, options, listener) { | |||
| 2295 | 2302 | if (typeof options === 'function') { | |
| 2296 | 2303 | listener = options; | |
| 2297 | 2304 | } | |
| 2298 | - options = getOptions(options, {}); | ||
| 2305 | + options = getOptions(options); | ||
| 2299 | 2306 | ||
| 2300 | 2307 | // Don't make changes directly on options object | |
| 2301 | 2308 | options = copyObject(options); | |
@@ -2458,16 +2465,14 @@ if (isWindows) { | |||
| 2458 | 2465 | }; | |
| 2459 | 2466 | } | |
| 2460 | 2467 | ||
| 2461 | - const emptyObj = ObjectCreate(null); | ||
| 2462 | - | ||
| 2463 | 2468 | /** | |
| 2464 | 2469 | * Returns the resolved pathname. | |
| 2465 | 2470 | * @param {string | Buffer | URL} p | |
| 2466 | 2471 | * @param {string | { encoding?: string | null; }} [options] | |
| 2467 | 2472 | * @returns {string | Buffer} | |
| 2468 | 2473 | */ | |
| 2469 | 2474 | function realpathSync(p, options) { | |
| 2470 | - options = getOptions(options, emptyObj); | ||
| 2475 | + options = getOptions(options); | ||
| 2471 | 2476 | p = toPathIfFileURL(p); | |
| 2472 | 2477 | if (typeof p !== 'string') { | |
| 2473 | 2478 | p += ''; | |
@@ -2604,7 +2609,7 @@ function realpathSync(p, options) { | |||
| 2604 | 2609 | * @returns {string | Buffer} | |
| 2605 | 2610 | */ | |
| 2606 | 2611 | realpathSync.native = (path, options) => { | |
| 2607 | - options = getOptions(options, {}); | ||
| 2612 | + options = getOptions(options); | ||
| 2608 | 2613 | path = getValidatedPath(path); | |
| 2609 | 2614 | const ctx = { path }; | |
| 2610 | 2615 | const result = binding.realpath(path, options.encoding, undefined, ctx); | |
@@ -2625,7 +2630,7 @@ realpathSync.native = (path, options) => { | |||
| 2625 | 2630 | */ | |
| 2626 | 2631 | function realpath(p, options, callback) { | |
| 2627 | 2632 | callback = typeof options === 'function' ? options : maybeCallback(callback); | |
| 2628 | - options = getOptions(options, {}); | ||
| 2633 | + options = getOptions(options); | ||
| 2629 | 2634 | p = toPathIfFileURL(p); | |
| 2630 | 2635 | ||
| 2631 | 2636 | if (typeof p !== 'string') { | |
@@ -2763,7 +2768,7 @@ function realpath(p, options, callback) { | |||
| 2763 | 2768 | */ | |
| 2764 | 2769 | realpath.native = (path, options, callback) => { | |
| 2765 | 2770 | callback = makeCallback(callback || options); | |
| 2766 | - options = getOptions(options, {}); | ||
| 2771 | + options = getOptions(options); | ||
| 2767 | 2772 | path = getValidatedPath(path); | |
| 2768 | 2773 | const req = new FSReqCallback(); | |
| 2769 | 2774 | req.oncomplete = callback; | |
@@ -2782,7 +2787,7 @@ realpath.native = (path, options, callback) => { | |||
| 2782 | 2787 | */ | |
| 2783 | 2788 | function mkdtemp(prefix, options, callback) { | |
| 2784 | 2789 | callback = makeCallback(typeof options === 'function' ? options : callback); | |
| 2785 | - options = getOptions(options, {}); | ||
| 2790 | + options = getOptions(options); | ||
| 2786 | 2791 | ||
| 2787 | 2792 | validateString(prefix, 'prefix'); | |
| 2788 | 2793 | nullCheck(prefix, 'prefix'); | |
@@ -2799,7 +2804,7 @@ function mkdtemp(prefix, options, callback) { | |||
| 2799 | 2804 | * @returns {string} | |
| 2800 | 2805 | */ | |
| 2801 | 2806 | function mkdtempSync(prefix, options) { | |
| 2802 | - options = getOptions(options, {}); | ||
| 2807 | + options = getOptions(options); | ||
| 2803 | 2808 | ||
| 2804 | 2809 | validateString(prefix, 'prefix'); | |
| 2805 | 2810 | nullCheck(prefix, 'prefix'); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -5,7 +5,6 @@ const { | |||
| 5 | 5 | Error, | |
| 6 | 6 | MathMax, | |
| 7 | 7 | MathMin, | |
| 8 | - ObjectCreate, | ||
| 9 | 8 | NumberIsSafeInteger, | |
| 10 | 9 | Promise, | |
| 11 | 10 | PromisePrototypeThen, | |
@@ -81,7 +80,11 @@ const { | |||
| 81 | 80 | validateString, | |
| 82 | 81 | } = require('internal/validators'); | |
| 83 | 82 | const pathModule = require('path'); | |
| 84 | - const { lazyDOMException, promisify } = require('internal/util'); | ||
| 83 | + const { | ||
| 84 | + kEmptyObject, | ||
| 85 | + lazyDOMException, | ||
| 86 | + promisify, | ||
| 87 | + } = require('internal/util'); | ||
| 85 | 88 | const { EventEmitterMixin } = require('internal/event_target'); | |
| 86 | 89 | const { watch } = require('internal/fs/watchers'); | |
| 87 | 90 | const { isIterable } = require('internal/streams/utils'); | |
@@ -519,7 +522,7 @@ async function read(handle, bufferOrParams, offset, length, position) { | |||
| 519 | 522 | offset = 0, | |
| 520 | 523 | length = buffer.byteLength - offset, | |
| 521 | 524 | position = null, | |
| 522 | - } = bufferOrParams ?? ObjectCreate(null)); | ||
| 525 | + } = bufferOrParams ?? kEmptyObject); | ||
| 523 | 526 | ||
| 524 | 527 | validateBuffer(buffer); | |
| 525 | 528 | } | |
@@ -582,7 +585,7 @@ async function write(handle, buffer, offsetOrOptions, length, position) { | |||
| 582 | 585 | offset = 0, | |
| 583 | 586 | length = buffer.byteLength - offset, | |
| 584 | 587 | position = null, | |
| 585 | - } = offsetOrOptions ?? ObjectCreate(null)); | ||
| 588 | + } = offsetOrOptions ?? kEmptyObject); | ||
| 586 | 589 | } | |
| 587 | 590 | ||
| 588 | 591 | if (offset == null) { | |
@@ -678,7 +681,7 @@ async function mkdir(path, options) { | |||
| 678 | 681 | const { | |
| 679 | 682 | recursive = false, | |
| 680 | 683 | mode = 0o777 | |
| 681 | - } = options || {}; | ||
| 684 | + } = options || kEmptyObject; | ||
| 682 | 685 | path = getValidatedPath(path); | |
| 683 | 686 | validateBoolean(recursive, 'options.recursive'); | |
| 684 | 687 | ||
@@ -688,7 +691,7 @@ async function mkdir(path, options) { | |||
| 688 | 691 | } | |
| 689 | 692 | ||
| 690 | 693 | async function readdir(path, options) { | |
| 691 | - options = getOptions(options, {}); | ||
| 694 | + options = getOptions(options); | ||
| 692 | 695 | path = getValidatedPath(path); | |
| 693 | 696 | const result = await binding.readdir(pathModule.toNamespacedPath(path), | |
| 694 | 697 | options.encoding, | |
@@ -700,7 +703,7 @@ async function readdir(path, options) { | |||
| 700 | 703 | } | |
| 701 | 704 | ||
| 702 | 705 | async function readlink(path, options) { | |
| 703 | - options = getOptions(options, {}); | ||
| 706 | + options = getOptions(options); | ||
| 704 | 707 | path = getValidatedPath(path, 'oldPath'); | |
| 705 | 708 | return binding.readlink(pathModule.toNamespacedPath(path), | |
| 706 | 709 | options.encoding, kUsePromises); | |
@@ -812,13 +815,13 @@ async function lutimes(path, atime, mtime) { | |||
| 812 | 815 | } | |
| 813 | 816 | ||
| 814 | 817 | async function realpath(path, options) { | |
| 815 | - options = getOptions(options, {}); | ||
| 818 | + options = getOptions(options); | ||
| 816 | 819 | path = getValidatedPath(path); | |
| 817 | 820 | return binding.realpath(path, options.encoding, kUsePromises); | |
| 818 | 821 | } | |
| 819 | 822 | ||
| 820 | 823 | async function mkdtemp(prefix, options) { | |
| 821 | - options = getOptions(options, {}); | ||
| 824 | + options = getOptions(options); | ||
| 822 | 825 | ||
| 823 | 826 | validateString(prefix, 'prefix'); | |
| 824 | 827 | nullCheck(prefix); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -16,7 +16,10 @@ const { | |||
| 16 | 16 | ERR_OUT_OF_RANGE, | |
| 17 | 17 | ERR_METHOD_NOT_IMPLEMENTED, | |
| 18 | 18 | } = require('internal/errors').codes; | |
| 19 | - const { deprecate } = require('internal/util'); | ||
| 19 | + const { | ||
| 20 | + deprecate, | ||
| 21 | + kEmptyObject, | ||
| 22 | + } = require('internal/util'); | ||
| 20 | 23 | const { | |
| 21 | 24 | validateFunction, | |
| 22 | 25 | validateInteger, | |
@@ -147,7 +150,7 @@ function ReadStream(path, options) { | |||
| 147 | 150 | return new ReadStream(path, options); | |
| 148 | 151 | ||
| 149 | 152 | // A little bit bigger buffer and water marks by default | |
| 150 | - options = copyObject(getOptions(options, {})); | ||
| 153 | + options = copyObject(getOptions(options, kEmptyObject)); | ||
| 151 | 154 | if (options.highWaterMark === undefined) | |
| 152 | 155 | options.highWaterMark = 64 * 1024; | |
| 153 | 156 | ||
@@ -305,7 +308,7 @@ function WriteStream(path, options) { | |||
| 305 | 308 | if (!(this instanceof WriteStream)) | |
| 306 | 309 | return new WriteStream(path, options); | |
| 307 | 310 | ||
| 308 | - options = copyObject(getOptions(options, {})); | ||
| 311 | + options = copyObject(getOptions(options, kEmptyObject)); | ||
| 309 | 312 | ||
| 310 | 313 | // Only buffers are supported. | |
| 311 | 314 | options.decodeStrings = true; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,14 +4,15 @@ const { | |||
| 4 | 4 | ObjectSetPrototypeOf, | |
| 5 | 5 | ReflectApply, | |
| 6 | 6 | } = primordials; | |
| 7 | + const { kEmptyObject } = require('internal/util'); | ||
| 7 | 8 | ||
| 8 | 9 | const { Writable } = require('stream'); | |
| 9 | 10 | const { closeSync, writeSync } = require('fs'); | |
| 10 | 11 | ||
| 11 | 12 | function SyncWriteStream(fd, options) { | |
| 12 | 13 | ReflectApply(Writable, this, [{ autoDestroy: true }]); | |
| 13 | 14 | ||
| 14 | - options = options || {}; | ||
| 15 | + options = options || kEmptyObject; | ||
| 15 | 16 | ||
| 16 | 17 | this.fd = fd; | |
| 17 | 18 | this.readable = false; | |
| Back | FazBrowse Home | New Git URL |
0 commit comments