-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
fs: support BigInt in fs.*stat and fs.watchFile #20220
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
vsemozhetbyt
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we mean primitives and not the classes/object wrappers, should these be bigint and number?
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto, `bigint`?
tools/doc/type-parser.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options -> `options`?
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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`.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto re default value place and format.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`bigint` as a primitive type?
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
options -> `options`?
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ditto re default value place and format.
doc/api/fs.md
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`bigint` as a primitive type?
test/parallel/test-fs-stat-bigint.js
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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());There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also a common function to throw in case of unhandled rejections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went with common.crashOnUnhandledRejection() because it's simple
|
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 |
|
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, |
|
@bnoordhuis |
|
Still saying |
Add the `bigint: true` option to all the `fs.*stat` methods and `fs.watchFile`.
|
https://ci.nodejs.org/job/node-test-pull-request/15260/ Oops, forgot to push |
|
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 |
|
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/ |
|
|
||
| Stats.prototype._checkModeProperty = function(property) { | ||
| if (isWindows && (property === S_IFIFO || property === S_IFBLK || | ||
| property === S_IFSOCK)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These three are in fact all undefined on Windows, but I figured it looks more readable if I list them like that.
src/node_internals.h
Outdated
| return node::FillStatsArray(env->fs_stats_field_array(), s, offset); | ||
| const uv_stat_t* s, | ||
| bool use_bigint = false, | ||
| int offset = 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alignment is off.
src/node_stat_watcher.h
Outdated
| bool IsActive(); | ||
|
|
||
| uv_fs_poll_t* watcher_; | ||
| bool use_bigint_; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const bool?
|
Test failures seem to be unrelated: Failures in job https://ci.nodejs.org/job/node-test-commit/18998/ alpine-latest-x64See failuresfedora-latest-x64See failurescentos7-arm64-gcc6See failuresdebian7-docker-armv7: Unknown |
|
Addressed nits. New CI: https://ci.nodejs.org/job/node-test-pull-request/15277/ |
|
CI is green. Pinging @nodejs/fs again for more reviews. |
|
I plan to land this later today and try backporting it after #21172 lands. |
|
Failures seem to be unrelated: Failures in job https://ci.nodejs.org/job/node-test-commit/19053/ centos7-64-gcc6See failuresubuntu1604_sharedlibs_openssl110_x64See failures |
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