Skip to content

Commit e2deeed

Browse files
avivkellerrichardlau
authored andcommitted
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 6bcaaa6 commit e2deeed

File tree

4 files changed

+7
-49
lines changed

4 files changed

+7
-49
lines changed

src/env.cc

+3-14
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

+1-1
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

-4
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

+3-30
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ namespace fs {
5454

5555
using v8::Array;
5656
using v8::BigInt;
57-
using v8::CFunction;
5857
using v8::Context;
5958
using v8::EscapableHandleScope;
6059
using v8::FastApiCallbackOptions;
@@ -299,7 +298,7 @@ FileHandle::TransferData::~TransferData() {
299298

300299
BaseObjectPtr<BaseObject> FileHandle::TransferData::Deserialize(
301300
Environment* env,
302-
Local<v8::Context> context,
301+
v8::Local<v8::Context> context,
303302
std::unique_ptr<worker::TransferData> self) {
304303
BindingData* bd = Realm::GetBindingData<BindingData>(context);
305304
if (bd == nullptr) return {};
@@ -961,7 +960,7 @@ void Access(const FunctionCallbackInfo<Value>& args) {
961960
}
962961
}
963962

964-
static void Close(const FunctionCallbackInfo<Value>& args) {
963+
void Close(const FunctionCallbackInfo<Value>& args) {
965964
Environment* env = Environment::GetCurrent(args);
966965

967966
const int argc = args.Length();
@@ -987,30 +986,6 @@ static void Close(const FunctionCallbackInfo<Value>& args) {
987986
}
988987
}
989988

990-
static void FastClose(Local<Object> recv,
991-
int32_t fd,
992-
// NOLINTNEXTLINE(runtime/references) This is V8 api.
993-
v8::FastApiCallbackOptions& options) {
994-
Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked());
995-
996-
uv_fs_t req;
997-
FS_SYNC_TRACE_BEGIN(close);
998-
int err = uv_fs_close(nullptr, &req, fd, nullptr) < 0;
999-
FS_SYNC_TRACE_END(close);
1000-
uv_fs_req_cleanup(&req);
1001-
1002-
if (err < 0) {
1003-
options.fallback = true;
1004-
} else {
1005-
// Note: Only remove unmanaged fds if the close was successful.
1006-
// RemoveUnmanagedFd() can call ProcessEmitWarning() which calls back into
1007-
// JS process.emitWarning() and violates the fast API protocol.
1008-
env->RemoveUnmanagedFd(fd, true /* schedule native immediate */);
1009-
}
1010-
}
1011-
1012-
CFunction fast_close_ = CFunction::Make(FastClose);
1013-
1014989
static void ExistsSync(const FunctionCallbackInfo<Value>& args) {
1015990
Environment* env = Environment::GetCurrent(args);
1016991
Isolate* isolate = env->isolate();
@@ -3330,7 +3305,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
33303305
"getFormatOfExtensionlessFile",
33313306
GetFormatOfExtensionlessFile);
33323307
SetMethod(isolate, target, "access", Access);
3333-
SetFastMethod(isolate, target, "close", Close, &fast_close_);
3308+
SetMethod(isolate, target, "close", Close);
33343309
SetMethod(isolate, target, "existsSync", ExistsSync);
33353310
SetMethod(isolate, target, "open", Open);
33363311
SetMethod(isolate, target, "openFileHandle", OpenFileHandle);
@@ -3455,8 +3430,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
34553430

34563431
registry->Register(GetFormatOfExtensionlessFile);
34573432
registry->Register(Close);
3458-
registry->Register(FastClose);
3459-
registry->Register(fast_close_.GetTypeInfo());
34603433
registry->Register(ExistsSync);
34613434
registry->Register(Open);
34623435
registry->Register(OpenFileHandle);

0 commit comments

Comments
 (0)