| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent e21b8a4 commit b2ba62c
3 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -13,7 +13,6 @@ const { | |||
| 13 | 13 | Number, | |
| 14 | 14 | NumberIsFinite, | |
| 15 | 15 | ObjectDefineProperties, | |
| 16 | - ObjectDefineProperty, | ||
| 17 | 16 | ObjectIs, | |
| 18 | 17 | ObjectSetPrototypeOf, | |
| 19 | 18 | ReflectOwnKeys, | |
@@ -48,6 +47,7 @@ const { | |||
| 48 | 47 | once, | |
| 49 | 48 | deprecate, | |
| 50 | 49 | isWindows, | |
| 50 | + setOwnProperty, | ||
| 51 | 51 | } = require('internal/util'); | |
| 52 | 52 | const { toPathIfFileURL } = require('internal/url'); | |
| 53 | 53 | const { | |
@@ -449,43 +449,43 @@ const lazyDateFields = { | |||
| 449 | 449 | enumerable: true, | |
| 450 | 450 | configurable: true, | |
| 451 | 451 | get() { | |
| 452 | - return this.atime = dateFromMs(this.atimeMs); | ||
| 452 | + return setOwnProperty(this, 'atime', dateFromMs(this.atimeMs)); | ||
| 453 | 453 | }, | |
| 454 | 454 | set(value) { | |
| 455 | - ObjectDefineProperty(this, 'atime', { __proto__: null, value, writable: true }); | ||
| 455 | + setOwnProperty(this, 'atime', value); | ||
| 456 | 456 | }, | |
| 457 | 457 | }, | |
| 458 | 458 | mtime: { | |
| 459 | 459 | __proto__: null, | |
| 460 | 460 | enumerable: true, | |
| 461 | 461 | configurable: true, | |
| 462 | 462 | get() { | |
| 463 | - return this.mtime = dateFromMs(this.mtimeMs); | ||
| 463 | + return setOwnProperty(this, 'mtime', dateFromMs(this.mtimeMs)); | ||
| 464 | 464 | }, | |
| 465 | 465 | set(value) { | |
| 466 | - ObjectDefineProperty(this, 'mtime', { __proto__: null, value, writable: true }); | ||
| 466 | + setOwnProperty(this, 'mtime', value); | ||
| 467 | 467 | }, | |
| 468 | 468 | }, | |
| 469 | 469 | ctime: { | |
| 470 | 470 | __proto__: null, | |
| 471 | 471 | enumerable: true, | |
| 472 | 472 | configurable: true, | |
| 473 | 473 | get() { | |
| 474 | - return this.ctime = dateFromMs(this.ctimeMs); | ||
| 474 | + return setOwnProperty(this, 'ctime', dateFromMs(this.ctimeMs)); | ||
| 475 | 475 | }, | |
| 476 | 476 | set(value) { | |
| 477 | - ObjectDefineProperty(this, 'ctime', { __proto__: null, value, writable: true }); | ||
| 477 | + setOwnProperty(this, 'ctime', value); | ||
| 478 | 478 | }, | |
| 479 | 479 | }, | |
| 480 | 480 | birthtime: { | |
| 481 | 481 | __proto__: null, | |
| 482 | 482 | enumerable: true, | |
| 483 | 483 | configurable: true, | |
| 484 | 484 | get() { | |
| 485 | - return this.birthtime = dateFromMs(this.birthtimeMs); | ||
| 485 | + return setOwnProperty(this, 'birthtime', dateFromMs(this.birthtimeMs)); | ||
| 486 | 486 | }, | |
| 487 | 487 | set(value) { | |
| 488 | - ObjectDefineProperty(this, 'birthtime', { __proto__: null, value, writable: true }); | ||
| 488 | + setOwnProperty(this, 'birthtime', value); | ||
| 489 | 489 | }, | |
| 490 | 490 | }, | |
| 491 | 491 | }; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -752,13 +752,14 @@ function filterOwnProperties(source, keys) { | |||
| 752 | 752 | * @returns {any} | |
| 753 | 753 | */ | |
| 754 | 754 | function setOwnProperty(obj, key, value) { | |
| 755 | - return ObjectDefineProperty(obj, key, { | ||
| 755 | + ObjectDefineProperty(obj, key, { | ||
| 756 | 756 | __proto__: null, | |
| 757 | 757 | configurable: true, | |
| 758 | 758 | enumerable: true, | |
| 759 | 759 | value, | |
| 760 | 760 | writable: true, | |
| 761 | 761 | }); | |
| 762 | + return value; | ||
| 762 | 763 | } | |
| 763 | 764 | ||
| 764 | 765 | let internalGlobal; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -42,6 +42,13 @@ function closeEnough(actual, expected, margin) { | |||
| 42 | 42 | `expected ${expected} ± ${margin}, got ${actual}`); | |
| 43 | 43 | } | |
| 44 | 44 | ||
| 45 | + // Ensure that accessed atime and mtime are enumerable | ||
| 46 | + function validateEnumerability(stats) { | ||
| 47 | + const keys = Object.keys(stats); | ||
| 48 | + assert.ok(keys.includes('atime')); | ||
| 49 | + assert.ok(keys.includes('mtime')); | ||
| 50 | + } | ||
| 51 | + | ||
| 45 | 52 | async function runTest(atime, mtime, margin = 0) { | |
| 46 | 53 | margin += Number.EPSILON; | |
| 47 | 54 | try { | |
@@ -56,24 +63,28 @@ async function runTest(atime, mtime, margin = 0) { | |||
| 56 | 63 | closeEnough(stats.mtimeMs, mtime, margin); | |
| 57 | 64 | closeEnough(stats.atime.getTime(), new Date(atime).getTime(), margin); | |
| 58 | 65 | closeEnough(stats.mtime.getTime(), new Date(mtime).getTime(), margin); | |
| 66 | + validateEnumerability(stats); | ||
| 59 | 67 | ||
| 60 | 68 | const statsBigint = await fsPromises.stat(filepath, { bigint: true }); | |
| 61 | 69 | closeEnough(statsBigint.atimeMs, BigInt(atime), margin); | |
| 62 | 70 | closeEnough(statsBigint.mtimeMs, BigInt(mtime), margin); | |
| 63 | 71 | closeEnough(statsBigint.atime.getTime(), new Date(atime).getTime(), margin); | |
| 64 | 72 | closeEnough(statsBigint.mtime.getTime(), new Date(mtime).getTime(), margin); | |
| 73 | + validateEnumerability(statsBigint); | ||
| 65 | 74 | ||
| 66 | 75 | const statsSync = fs.statSync(filepath); | |
| 67 | 76 | closeEnough(statsSync.atimeMs, atime, margin); | |
| 68 | 77 | closeEnough(statsSync.mtimeMs, mtime, margin); | |
| 69 | 78 | closeEnough(statsSync.atime.getTime(), new Date(atime).getTime(), margin); | |
| 70 | 79 | closeEnough(statsSync.mtime.getTime(), new Date(mtime).getTime(), margin); | |
| 80 | + validateEnumerability(statsSync); | ||
| 71 | 81 | ||
| 72 | 82 | const statsSyncBigint = fs.statSync(filepath, { bigint: true }); | |
| 73 | 83 | closeEnough(statsSyncBigint.atimeMs, BigInt(atime), margin); | |
| 74 | 84 | closeEnough(statsSyncBigint.mtimeMs, BigInt(mtime), margin); | |
| 75 | 85 | closeEnough(statsSyncBigint.atime.getTime(), new Date(atime).getTime(), margin); | |
| 76 | 86 | closeEnough(statsSyncBigint.mtime.getTime(), new Date(mtime).getTime(), margin); | |
| 87 | + validateEnumerability(statsSyncBigint); | ||
| 77 | 88 | } | |
| 78 | 89 | ||
| 79 | 90 | // Too high/low numbers produce too different results on different platforms | |
| Back | FazBrowse Home | New Git URL |
0 commit comments