Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upfs: support BigInt in fs.*stat and fs.watchFile #20220
Conversation
nodejs-github-bot
added
C++
lib / src
labels
Apr 23, 2018
mscdex
added
the
work in progress (WIP)
label
Apr 23, 2018
vsemozhetbyt
reviewed
Apr 23, 2018
|
Sorry for many repetitive nits, they are guards to not be missed. I will delete them if they will be rejected or not folded when addressed. |
| @@ -413,6 +413,8 @@ A `fs.Stats` object provides information about a file. | |||
|
|
|||
| Objects returned from [`fs.stat()`][], [`fs.lstat()`][] and [`fs.fstat()`][] and | |||
| their synchronous counterparts are of this type. | |||
| If `bigint` in the `options` passed to those methods is true, the numeric values | |||
| will be `BigInt` instead of `Number`. | |||
This comment has been minimized.
This comment has been minimized.
vsemozhetbyt
Apr 23, 2018
Member
If we mean primitives and not the classes/object wrappers, should these be bigint and number?
| @@ -436,6 +438,30 @@ Stats { | |||
| birthtime: Mon, 10 Oct 2011 23:24:11 GMT } | |||
| ``` | |||
|
|
|||
| `BigInt` version: | |||
This comment has been minimized.
This comment has been minimized.
| @@ -4,6 +4,7 @@ const jsDocPrefix = 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/'; | |||
|
|
|||
| const jsDataStructuresUrl = `${jsDocPrefix}Data_structures`; | |||
| const jsPrimitives = { | |||
| bigint: 'BigInt', | |||
This comment has been minimized.
This comment has been minimized.
vsemozhetbyt
Apr 23, 2018
Member
Unfortunately, this will generate:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#BigInt_type
due to this end point, and there is no such section in the MDN. Unless this section is created by our collaborators, we need temporarily place this type along with something like AsyncIterator in customTypesMap, before Node.js types (as 'bigint' after 'AsyncIterator') with a link to the proposal.
| @@ -1636,9 +1662,16 @@ changes: | |||
| pr-url: https://github.com/nodejs/node/pull/7897 | |||
| description: The `callback` parameter is no longer optional. Not passing | |||
| it will emit a deprecation warning with id DEP0013. | |||
| - version: REPLACEME | |||
| pr-url: REPLACEME | |||
| description: Accepts an additional options object to specify whether | |||
This comment has been minimized.
This comment has been minimized.
| --> | ||
|
|
||
| * `fd` {integer} | ||
| * `options` {Object} | ||
| * `bigint` {boolean} **Default:** `false` Whether the numeric values in |
This comment has been minimized.
This comment has been minimized.
vsemozhetbyt
Apr 23, 2018
Member
Default values usually go at the end, with a period if preceded by a full sentence or if constructed as a full sentence. So this should be:
...should be `BigInt`. **Default:** `false`.| --> | ||
|
|
||
| * `path` {string|Buffer|URL} | ||
| * `options` {Object} | ||
| * `bigint` {boolean} **Default:** `false` Whether the numeric values in |
This comment has been minimized.
This comment has been minimized.
| --> | ||
|
|
||
| * `path` {string|Buffer|URL} | ||
| * `options` {Object} | ||
| * `bigint` {boolean} **Default:** `false` Whether the numeric values in | ||
| the returned [`fs.Stats`][] object should be `BigInt`. |
This comment has been minimized.
This comment has been minimized.
| changes: | ||
| - version: REPLACEME | ||
| pr-url: REPLACEME | ||
| description: Accepts an additional options object to specify whether |
This comment has been minimized.
This comment has been minimized.
| --> | ||
|
|
||
| * `path` {string|Buffer|URL} | ||
| * `options` {Object} | ||
| * `bigint` {boolean} **Default:** `false` Whether the numeric values in |
This comment has been minimized.
This comment has been minimized.
| --> | ||
|
|
||
| * `path` {string|Buffer|URL} | ||
| * `options` {Object} | ||
| * `bigint` {boolean} **Default:** `false` Whether the numeric values in | ||
| the returned [`fs.Stats`][] object should be `BigInt`. |
This comment has been minimized.
This comment has been minimized.
BridgeAR
reviewed
Apr 23, 2018
| const numStats = await handle.stat(); | ||
| verifyStats(bigintStats, numStats); | ||
| await handle.close(); | ||
| })(); |
This comment has been minimized.
This comment has been minimized.
BridgeAR
Apr 23, 2018
Member
These tests would all pass in case e.g. const handle = await promiseFs.open(fn, 'r'); rejects. In that case it would log an unhandled rejection and that would currently not end the process, so we would not notice anything wrong.
Instead, it would be good to write something like:
async function foo() {
}
Promise.all([
foo(),
bar(),
...
]).then(common.mustCall());
This comment has been minimized.
This comment has been minimized.
BridgeAR
Apr 23, 2018
Member
There is also a common function to throw in case of unhandled rejections.
This comment has been minimized.
This comment has been minimized.
joyeecheung
Jun 4, 2018
Author
Member
I went with common.crashOnUnhandledRejection() because it's simple
joyeecheung
force-pushed the
joyeecheung:bigint-stat
branch
from
d7db80b
to
fa59747
Jun 2, 2018
joyeecheung
changed the title
WIP: fs: support BigInt in fs.*stat and fs.watchFile
fs: support BigInt in fs.*stat and fs.watchFile
Jun 4, 2018
This comment has been minimized.
This comment has been minimized.
|
I think I've addressed all the comments from @vsemozhetbyt and @BridgeAR . This should be ready now that v8 6.7 has landed on master. PTAL @nodejs/fs |
This comment has been minimized.
This comment has been minimized.
|
Looks like diff --git a/lib/internal/fs/promises.js b/lib/internal/fs/promises.js
index 43956dae3f..a1670fc65b 100644
--- a/lib/internal/fs/promises.js
+++ b/lib/internal/fs/promises.js
@@ -476,6 +476,7 @@ module.exports = {
symlink,
lstat,
stat,
+ fstat,
link,
unlink,
chmod, |
This comment has been minimized.
This comment has been minimized.
|
@bnoordhuis |
joyeecheung
removed
the
work in progress (WIP)
label
Jun 5, 2018
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Still saying |
joyeecheung
added some commits
Apr 7, 2018
joyeecheung
force-pushed the
joyeecheung:bigint-stat
branch
from
fa59747
to
17fda05
Jun 5, 2018
This comment has been minimized.
This comment has been minimized.
|
https://ci.nodejs.org/job/node-test-pull-request/15260/ Oops, forgot to push |
This comment has been minimized.
This comment has been minimized.
|
Still failing on Windows, I'm afraid: https://ci.nodejs.org/job/node-test-binary-windows/17813/COMPILED_BY=vs2017,RUNNER=win2008r2-vs2017,RUN_SUBSET=2/console |
joyeecheung
force-pushed the
joyeecheung:bigint-stat
branch
from
9642218
to
3caab98
Jun 5, 2018
This comment has been minimized.
This comment has been minimized.
|
Green on my Windows laptop now. @bnoordhuis Would you mind taking a look at the last commit? I think it should be OK to special case for Windows like that. Another CI: https://ci.nodejs.org/job/node-test-pull-request/15266/ |
joyeecheung
reviewed
Jun 5, 2018
| @@ -155,6 +155,10 @@ function Stats( | |||
| } | |||
|
|
|||
| Stats.prototype._checkModeProperty = function(property) { | |||
| if (isWindows && (property === S_IFIFO || property === S_IFBLK || | |||
| property === S_IFSOCK)) { | |||
This comment has been minimized.
This comment has been minimized.
joyeecheung
Jun 5, 2018
Author
Member
These three are in fact all undefined on Windows, but I figured it looks more readable if I list them like that.
bnoordhuis
approved these changes
Jun 5, 2018
| return node::FillStatsArray(env->fs_stats_field_array(), s, offset); | ||
| const uv_stat_t* s, | ||
| bool use_bigint = false, | ||
| int offset = 0) { |
This comment has been minimized.
This comment has been minimized.
| @@ -57,6 +57,7 @@ class StatWatcher : public AsyncWrap { | |||
| bool IsActive(); | |||
|
|
|||
| uv_fs_poll_t* watcher_; | |||
| bool use_bigint_; | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Test failures seem to be unrelated: Failures in job https://ci.nodejs.org/job/node-test-commit/18998/ alpine-latest-x64See failures
fedora-latest-x64See failures
centos7-arm64-gcc6See failures
debian7-docker-armv7: Unknown |
This comment has been minimized.
This comment has been minimized.
|
Addressed nits. New CI: https://ci.nodejs.org/job/node-test-pull-request/15277/ |
This comment has been minimized.
This comment has been minimized.
|
CI is green. Pinging @nodejs/fs again for more reviews. |
This comment has been minimized.
This comment has been minimized.
|
I plan to land this later today and try backporting it after #21172 lands. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Failures seem to be unrelated: Failures in job https://ci.nodejs.org/job/node-test-commit/19053/ centos7-64-gcc6See failures
ubuntu1604_sharedlibs_openssl110_x64See failures
|
joyeecheung commentedApr 23, 2018
•
edited
Add the
bigint: trueoption to all thefs.*statmethods andfs.watchFile.I chose to expose the BigInt variant via
bigint: truein the option object because right now there are no support of a Date class with higher precision - the old Date is Number-based and can lose precision when being constructed out of a 64bit ms value. The plan is that when JS does get a better Date e.g. Temporal (see tc39/proposal-bigint#136), we will be able to supporttemporal: true.The
--harmony-bigintflag is necessary until v8 6.7 lands.Fixes: #12115
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes