Skip to content

Commit c0c7e86

Browse files
authored
Revert "fs: add v8 fast api to closeSync"
This reverts commit ed6f45b. PR-URL: #53904 Refs: yarnpkg/berry#6398 Refs: npm/cli#7657 Reviewed-By: Richard Lau <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent 05b7bf0 commit c0c7e86

File tree

4 files changed

+7
-49
lines changed

4 files changed

+7
-49
lines changed

src/env.cc

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,23 +1841,12 @@ void Environment::AddUnmanagedFd(int fd) {
18411841
}
18421842
}
18431843

1844-
void Environment::RemoveUnmanagedFd(int fd, bool schedule_native_immediate) {
1844+
void Environment::RemoveUnmanagedFd(int fd) {
18451845
if (!tracks_unmanaged_fds()) return;
18461846
size_t removed_count = unmanaged_fds_.erase(fd);
18471847
if (removed_count == 0) {
1848-
if (schedule_native_immediate) {
1849-
SetImmediateThreadsafe([&](Environment* env) {
1850-
ProcessEmitWarning(this,
1851-
"File descriptor %d closed but not opened in "
1852-
"unmanaged mode",
1853-
fd);
1854-
});
1855-
} else {
1856-
ProcessEmitWarning(
1857-
this,
1858-
"File descriptor %d closed but not opened in unmanaged mode",
1859-
fd);
1860-
}
1848+
ProcessEmitWarning(
1849+
this, "File descriptor %d closed but not opened in unmanaged mode", fd);
18611850
}
18621851
}
18631852

src/env.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1027,7 +1027,7 @@ class Environment : public MemoryRetainer {
10271027
std::unique_ptr<v8::BackingStore> release_managed_buffer(const uv_buf_t& buf);
10281028

10291029
void AddUnmanagedFd(int fd);
1030-
void RemoveUnmanagedFd(int fd, bool schedule_native_immediate = false);
1030+
void RemoveUnmanagedFd(int fd);
10311031

10321032
template <typename T>
10331033
void ForEachRealm(T&& iterator) const;

src/node_external_reference.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,6 @@ using CFunctionCallbackWithUint8ArrayUint32Int64Bool =
4747
uint32_t,
4848
int64_t,
4949
bool);
50-
using CFunctionWithObjectInt32Fallback = void (*)(v8::Local<v8::Object>,
51-
int32_t input,
52-
v8::FastApiCallbackOptions&);
5350
using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>,
5451
const uint32_t input);
5552
using CFunctionWithDoubleReturnDouble = double (*)(v8::Local<v8::Value>,
@@ -78,7 +75,6 @@ class ExternalReferenceRegistry {
7875
V(CFunctionCallbackWithTwoUint8Arrays) \
7976
V(CFunctionCallbackWithTwoUint8ArraysFallback) \
8077
V(CFunctionCallbackWithUint8ArrayUint32Int64Bool) \
81-
V(CFunctionWithObjectInt32Fallback) \
8278
V(CFunctionWithUint32) \
8379
V(CFunctionWithDoubleReturnDouble) \
8480
V(CFunctionWithInt64Fallback) \

src/node_file.cc

Lines changed: 3 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ namespace fs {
6060

6161
using v8::Array;
6262
using v8::BigInt;
63-
using v8::CFunction;
6463
using v8::Context;
6564
using v8::EscapableHandleScope;
6665
using v8::FastApiCallbackOptions;
@@ -305,7 +304,7 @@ FileHandle::TransferData::~TransferData() {
305304

306305
BaseObjectPtr<BaseObject> FileHandle::TransferData::Deserialize(
307306
Environment* env,
308-
Local<v8::Context> context,
307+
v8::Local<v8::Context> context,
309308
std::unique_ptr<worker::TransferData> self) {
310309
BindingData* bd = Realm::GetBindingData<BindingData>(context);
311310
if (bd == nullptr) return {};
@@ -967,7 +966,7 @@ void Access(const FunctionCallbackInfo<Value>& args) {
967966
}
968967
}
969968

970-
static void Close(const FunctionCallbackInfo<Value>& args) {
969+
void Close(const FunctionCallbackInfo<Value>& args) {
971970
Environment* env = Environment::GetCurrent(args);
972971

973972
const int argc = args.Length();
@@ -993,30 +992,6 @@ static void Close(const FunctionCallbackInfo<Value>& args) {
993992
}
994993
}
995994

996-
static void FastClose(Local<Object> recv,
997-
int32_t fd,
998-
// NOLINTNEXTLINE(runtime/references) This is V8 api.
999-
v8::FastApiCallbackOptions& options) {
1000-
Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked());
1001-
1002-
uv_fs_t req;
1003-
FS_SYNC_TRACE_BEGIN(close);
1004-
int err = uv_fs_close(nullptr, &req, fd, nullptr) < 0;
1005-
FS_SYNC_TRACE_END(close);
1006-
uv_fs_req_cleanup(&req);
1007-
1008-
if (err < 0) {
1009-
options.fallback = true;
1010-
} else {
1011-
// Note: Only remove unmanaged fds if the close was successful.
1012-
// RemoveUnmanagedFd() can call ProcessEmitWarning() which calls back into
1013-
// JS process.emitWarning() and violates the fast API protocol.
1014-
env->RemoveUnmanagedFd(fd, true /* schedule native immediate */);
1015-
}
1016-
}
1017-
1018-
CFunction fast_close_ = CFunction::Make(FastClose);
1019-
1020995
static void ExistsSync(const FunctionCallbackInfo<Value>& args) {
1021996
Environment* env = Environment::GetCurrent(args);
1022997
Isolate* isolate = env->isolate();
@@ -3432,7 +3407,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
34323407
"getFormatOfExtensionlessFile",
34333408
GetFormatOfExtensionlessFile);
34343409
SetMethod(isolate, target, "access", Access);
3435-
SetFastMethod(isolate, target, "close", Close, &fast_close_);
3410+
SetMethod(isolate, target, "close", Close);
34363411
SetMethod(isolate, target, "existsSync", ExistsSync);
34373412
SetMethod(isolate, target, "open", Open);
34383413
SetMethod(isolate, target, "openFileHandle", OpenFileHandle);
@@ -3558,8 +3533,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
35583533

35593534
registry->Register(GetFormatOfExtensionlessFile);
35603535
registry->Register(Close);
3561-
registry->Register(FastClose);
3562-
registry->Register(fast_close_.GetTypeInfo());
35633536
registry->Register(ExistsSync);
35643537
registry->Register(Open);
35653538
registry->Register(OpenFileHandle);

0 commit comments

Comments
 (0)