-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Add a doNodeOp helper for common code pattern. NFC #23305
base: main
Are you sure you want to change the base?
Conversation
We frequently check if a node op is present, if not raise a specific error, if it is present call it. This factors out this common pattern.
if (!node) { | ||
throw new FS.ErrnoError({{{ cDefs.ENOENT }}}); | ||
} |
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 don't think lookupPath
returns an undefined
node ever, it throws ENOENT itself so this check is not needed.
if (!node.node_ops.setattr) { | ||
throw new FS.ErrnoError({{{ cDefs.EPERM }}}); | ||
} |
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.
This changes which error we throw if there are multiple problems.
@@ -1044,7 +1033,7 @@ FS.staticInit(); | |||
utime(path, atime, mtime) { | |||
var lookup = FS.lookupPath(path, { follow: true }); | |||
var node = lookup.node; | |||
node.node_ops.setattr(node, { |
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.
Previously there was no error handling for setattr
being missing, so if we called utime
on a read only node it would crash.
This is an automatic change generated by tools/maint/rebaseline_tests.py. The following (18) test expectation files were updated by running the tests with `--rebaseline`: ``` other/codesize/test_codesize_cxx_ctors1.gzsize: 8365 => 8379 [+14 bytes / +0.17%] other/codesize/test_codesize_cxx_ctors1.jssize: 20373 => 20384 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_ctors2.gzsize: 8347 => 8365 [+18 bytes / +0.22%] other/codesize/test_codesize_cxx_ctors2.jssize: 20341 => 20352 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_except.gzsize: 9369 => 9376 [+7 bytes / +0.07%] other/codesize/test_codesize_cxx_except.jssize: 24141 => 24152 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_except_wasm.gzsize: 8328 => 8340 [+12 bytes / +0.14%] other/codesize/test_codesize_cxx_except_wasm.jssize: 20267 => 20278 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_except_wasm_exnref.gzsize: 8328 => 8340 [+12 bytes / +0.14%] other/codesize/test_codesize_cxx_except_wasm_exnref.jssize: 20267 => 20278 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_lto.gzsize: 8360 => 8372 [+12 bytes / +0.14%] other/codesize/test_codesize_cxx_lto.jssize: 20397 => 20408 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_mangle.gzsize: 9374 => 9381 [+7 bytes / +0.07%] other/codesize/test_codesize_cxx_mangle.jssize: 24142 => 24153 [+11 bytes / +0.05%] other/codesize/test_codesize_cxx_noexcept.gzsize: 8365 => 8379 [+14 bytes / +0.17%] other/codesize/test_codesize_cxx_noexcept.jssize: 20373 => 20384 [+11 bytes / +0.05%] other/codesize/test_codesize_files_js_fs.gzsize: 7655 => 7672 [+17 bytes / +0.22%] other/codesize/test_codesize_files_js_fs.jssize: 18867 => 18879 [+12 bytes / +0.06%] Average change: +0.10% (+0.05% - +0.22%) ```
I'm surprised that this increased code size by a few bytes... |
throw new FS.ErrnoError({{{ cDefs.ENOTDIR }}}); | ||
} | ||
return node.node_ops.readdir(node); | ||
return FS.doNodeOp(node, "readdir", {{{ cDefs.ENOTDIR }}}); |
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.
When I first say this change I assumed Node
here meant Node JS.. but I just the term just very overloaded.
I worry a little that using strings here will cause closure to break, or at least fail to minify these attribute names.
How about this return FS.doNodeOp(node.node_ops.readdir, {{{ cDefs.ENOTDIR }}});
.. thus avoid the string lookup and passing instead the result of the lookup?
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.
Or maybe we can leave the call at the callsite and just make check function that doesn't need to take the ...
operator (which I believe generates JS garbage (i.e. a new array)).
FS.checkExists(node.readdir, {{{ cDefs.ENOTDIR }}});
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.
Well then we'd have to pass both node
and node.node_ops.readdir
.
We frequently check if a node op is present, if not raise a specific error, if it is present call it. This factors out this common pattern.