mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Revert "fs: add v8 fast api to closeSync"
This reverts commit ed6f45bef8.
PR-URL: https://github.com/nodejs/node/pull/53904
Refs: https://github.com/yarnpkg/berry/issues/6398
Refs: https://github.com/npm/cli/issues/7657
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
17
src/env.cc
17
src/env.cc
@@ -1841,23 +1841,12 @@ void Environment::AddUnmanagedFd(int fd) {
|
||||
}
|
||||
}
|
||||
|
||||
void Environment::RemoveUnmanagedFd(int fd, bool schedule_native_immediate) {
|
||||
void Environment::RemoveUnmanagedFd(int fd) {
|
||||
if (!tracks_unmanaged_fds()) return;
|
||||
size_t removed_count = unmanaged_fds_.erase(fd);
|
||||
if (removed_count == 0) {
|
||||
if (schedule_native_immediate) {
|
||||
SetImmediateThreadsafe([&](Environment* env) {
|
||||
ProcessEmitWarning(this,
|
||||
"File descriptor %d closed but not opened in "
|
||||
"unmanaged mode",
|
||||
fd);
|
||||
});
|
||||
} else {
|
||||
ProcessEmitWarning(
|
||||
this,
|
||||
"File descriptor %d closed but not opened in unmanaged mode",
|
||||
fd);
|
||||
}
|
||||
ProcessEmitWarning(
|
||||
this, "File descriptor %d closed but not opened in unmanaged mode", fd);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1027,7 +1027,7 @@ class Environment : public MemoryRetainer {
|
||||
std::unique_ptr<v8::BackingStore> release_managed_buffer(const uv_buf_t& buf);
|
||||
|
||||
void AddUnmanagedFd(int fd);
|
||||
void RemoveUnmanagedFd(int fd, bool schedule_native_immediate = false);
|
||||
void RemoveUnmanagedFd(int fd);
|
||||
|
||||
template <typename T>
|
||||
void ForEachRealm(T&& iterator) const;
|
||||
|
||||
@@ -47,9 +47,6 @@ using CFunctionCallbackWithUint8ArrayUint32Int64Bool =
|
||||
uint32_t,
|
||||
int64_t,
|
||||
bool);
|
||||
using CFunctionWithObjectInt32Fallback = void (*)(v8::Local<v8::Object>,
|
||||
int32_t input,
|
||||
v8::FastApiCallbackOptions&);
|
||||
using CFunctionWithUint32 = uint32_t (*)(v8::Local<v8::Value>,
|
||||
const uint32_t input);
|
||||
using CFunctionWithDoubleReturnDouble = double (*)(v8::Local<v8::Value>,
|
||||
@@ -78,7 +75,6 @@ class ExternalReferenceRegistry {
|
||||
V(CFunctionCallbackWithTwoUint8Arrays) \
|
||||
V(CFunctionCallbackWithTwoUint8ArraysFallback) \
|
||||
V(CFunctionCallbackWithUint8ArrayUint32Int64Bool) \
|
||||
V(CFunctionWithObjectInt32Fallback) \
|
||||
V(CFunctionWithUint32) \
|
||||
V(CFunctionWithDoubleReturnDouble) \
|
||||
V(CFunctionWithInt64Fallback) \
|
||||
|
||||
@@ -60,7 +60,6 @@ namespace fs {
|
||||
|
||||
using v8::Array;
|
||||
using v8::BigInt;
|
||||
using v8::CFunction;
|
||||
using v8::Context;
|
||||
using v8::EscapableHandleScope;
|
||||
using v8::FastApiCallbackOptions;
|
||||
@@ -305,7 +304,7 @@ FileHandle::TransferData::~TransferData() {
|
||||
|
||||
BaseObjectPtr<BaseObject> FileHandle::TransferData::Deserialize(
|
||||
Environment* env,
|
||||
Local<v8::Context> context,
|
||||
v8::Local<v8::Context> context,
|
||||
std::unique_ptr<worker::TransferData> self) {
|
||||
BindingData* bd = Realm::GetBindingData<BindingData>(context);
|
||||
if (bd == nullptr) return {};
|
||||
@@ -967,7 +966,7 @@ void Access(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
}
|
||||
|
||||
static void Close(const FunctionCallbackInfo<Value>& args) {
|
||||
void Close(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
|
||||
const int argc = args.Length();
|
||||
@@ -993,30 +992,6 @@ static void Close(const FunctionCallbackInfo<Value>& args) {
|
||||
}
|
||||
}
|
||||
|
||||
static void FastClose(Local<Object> recv,
|
||||
int32_t fd,
|
||||
// NOLINTNEXTLINE(runtime/references) This is V8 api.
|
||||
v8::FastApiCallbackOptions& options) {
|
||||
Environment* env = Environment::GetCurrent(recv->GetCreationContextChecked());
|
||||
|
||||
uv_fs_t req;
|
||||
FS_SYNC_TRACE_BEGIN(close);
|
||||
int err = uv_fs_close(nullptr, &req, fd, nullptr) < 0;
|
||||
FS_SYNC_TRACE_END(close);
|
||||
uv_fs_req_cleanup(&req);
|
||||
|
||||
if (err < 0) {
|
||||
options.fallback = true;
|
||||
} else {
|
||||
// Note: Only remove unmanaged fds if the close was successful.
|
||||
// RemoveUnmanagedFd() can call ProcessEmitWarning() which calls back into
|
||||
// JS process.emitWarning() and violates the fast API protocol.
|
||||
env->RemoveUnmanagedFd(fd, true /* schedule native immediate */);
|
||||
}
|
||||
}
|
||||
|
||||
CFunction fast_close_ = CFunction::Make(FastClose);
|
||||
|
||||
static void ExistsSync(const FunctionCallbackInfo<Value>& args) {
|
||||
Environment* env = Environment::GetCurrent(args);
|
||||
Isolate* isolate = env->isolate();
|
||||
@@ -3432,7 +3407,7 @@ static void CreatePerIsolateProperties(IsolateData* isolate_data,
|
||||
"getFormatOfExtensionlessFile",
|
||||
GetFormatOfExtensionlessFile);
|
||||
SetMethod(isolate, target, "access", Access);
|
||||
SetFastMethod(isolate, target, "close", Close, &fast_close_);
|
||||
SetMethod(isolate, target, "close", Close);
|
||||
SetMethod(isolate, target, "existsSync", ExistsSync);
|
||||
SetMethod(isolate, target, "open", Open);
|
||||
SetMethod(isolate, target, "openFileHandle", OpenFileHandle);
|
||||
@@ -3558,8 +3533,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
|
||||
|
||||
registry->Register(GetFormatOfExtensionlessFile);
|
||||
registry->Register(Close);
|
||||
registry->Register(FastClose);
|
||||
registry->Register(fast_close_.GetTypeInfo());
|
||||
registry->Register(ExistsSync);
|
||||
registry->Register(Open);
|
||||
registry->Register(OpenFileHandle);
|
||||
|
||||
Reference in New Issue
Block a user