diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2023-04-20 05:28:35 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-04-20 03:28:35 +0000 |
commit | b68cedd4d85157914944b1672310c6023dc8635d (patch) | |
tree | 9f1bb60936886ea1bc56457fe5c45b5a85f61ee9 /lib/fs.js | |
parent | df15a4732c73556669d58c2fdf1eb80ad395aab4 (diff) | |
download | node-new-b68cedd4d85157914944b1672310c6023dc8635d.tar.gz |
src: make AliasedBuffers in the binding data weak
The binding data holds references to the AliasedBuffers directly
from their wrappers which already ensures that the AliasedBuffers
won't be accessed when the wrappers are GC'ed. So we can just
make the global references to the AliasedBuffers weak. This way
we can simply deserialize the typed arrays when deserialize the
binding data and avoid the extra Object::Set() calls. It also
eliminates the caveat in the JS land where aliased buffers must
be dynamically read from the binding.
PR-URL: https://github.com/nodejs/node/pull/47354
Refs: https://github.com/nodejs/node/issues/47353
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Diffstat (limited to 'lib/fs.js')
-rw-r--r-- | lib/fs.js | 16 |
1 files changed, 8 insertions, 8 deletions
@@ -59,9 +59,6 @@ const { const pathModule = require('path'); const { isArrayBufferView } = require('internal/util/types'); -// We need to get the statValues from the binding at the callsite since -// it's re-initialized after deserialization. - const binding = internalBinding('fs'); const { createBlobFromFilePath } = require('internal/blob'); @@ -78,7 +75,10 @@ const { uvException, } = require('internal/errors'); -const { FSReqCallback } = binding; +const { + FSReqCallback, + statValues, +} = binding; const { toPathIfFileURL } = require('internal/url'); const { customPromisifyArgs: kCustomPromisifyArgsSymbol, @@ -2569,8 +2569,8 @@ function realpathSync(p, options) { // Continue if not a symlink, break if a pipe/socket if (knownHard.has(base) || cache?.get(base) === base) { - if (isFileType(binding.statValues, S_IFIFO) || - isFileType(binding.statValues, S_IFSOCK)) { + if (isFileType(statValues, S_IFIFO) || + isFileType(statValues, S_IFSOCK)) { break; } continue; @@ -2727,8 +2727,8 @@ function realpath(p, options, callback) { // Continue if not a symlink, break if a pipe/socket if (knownHard.has(base)) { - if (isFileType(binding.statValues, S_IFIFO) || - isFileType(binding.statValues, S_IFSOCK)) { + if (isFileType(statValues, S_IFIFO) || + isFileType(statValues, S_IFSOCK)) { return callback(null, encodeRealpathResult(p, options)); } return process.nextTick(LOOP); |