Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common.gypi
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.28',
'v8_embedder_string': '-node.29',

##### V8 defaults for Node.js #####

Expand Down
4 changes: 4 additions & 0 deletions deps/v8/src/codegen/ppc/macro-assembler-ppc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4271,6 +4271,7 @@ void MacroAssembler::I64x2Mul(Simd128Register dst, Simd128Register src1,
if (CpuFeatures::IsSupported(PPC_10_PLUS)) {
vmulld(dst, src1, src2);
} else {
DCHECK(scratch1 != r0);
Register scratch_1 = scratch1;
Register scratch_2 = scratch2;
for (int i = 0; i < 2; i++) {
Expand Down Expand Up @@ -4623,6 +4624,7 @@ void MacroAssembler::I8x16BitMask(Register dst, Simd128Register src,
if (CpuFeatures::IsSupported(PPC_10_PLUS)) {
vextractbm(dst, src);
} else {
DCHECK(scratch1 != r0);
mov(scratch1, Operand(0x8101820283038));
mov(scratch2, Operand(0x4048505860687078));
mtvsrdd(scratch3, scratch1, scratch2);
Expand Down Expand Up @@ -4675,6 +4677,7 @@ void MacroAssembler::I8x16Shuffle(Simd128Register dst, Simd128Register src1,
Simd128Register src2, uint64_t high,
uint64_t low, Register scratch1,
Register scratch2, Simd128Register scratch3) {
DCHECK(scratch2 != r0);
mov(scratch1, Operand(low));
mov(scratch2, Operand(high));
mtvsrdd(scratch3, scratch2, scratch1);
Expand Down Expand Up @@ -4963,6 +4966,7 @@ void MacroAssembler::S128Not(Simd128Register dst, Simd128Register src) {

void MacroAssembler::S128Const(Simd128Register dst, uint64_t high, uint64_t low,
Register scratch1, Register scratch2) {
DCHECK(scratch2 != r0);
mov(scratch1, Operand(low));
mov(scratch2, Operand(high));
mtvsrdd(dst, scratch2, scratch1);
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/compiler/backend/ppc/code-generator-ppc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2737,7 +2737,7 @@ CodeGenerator::CodeGenResult CodeGenerator::AssembleArchInstruction(
break;
}
case kPPC_I8x16BitMask: {
__ I8x16BitMask(i.OutputRegister(), i.InputSimd128Register(0), r0, ip,
__ I8x16BitMask(i.OutputRegister(), i.InputSimd128Register(0), ip, r0,
kScratchSimd128Reg);
break;
}
Expand Down
2 changes: 1 addition & 1 deletion deps/v8/src/wasm/baseline/ppc/liftoff-assembler-ppc-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -2719,7 +2719,7 @@ void LiftoffAssembler::emit_v128_anytrue(LiftoffRegister dst,

void LiftoffAssembler::emit_i8x16_bitmask(LiftoffRegister dst,
LiftoffRegister src) {
I8x16BitMask(dst.gp(), src.fp().toSimd(), r0, ip, kScratchSimd128Reg);
I8x16BitMask(dst.gp(), src.fp().toSimd(), ip, r0, kScratchSimd128Reg);
}

void LiftoffAssembler::emit_s128_const(LiftoffRegister dst,
Expand Down
52 changes: 8 additions & 44 deletions src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3175,42 +3175,6 @@ static void GetFormatOfExtensionlessFile(
return args.GetReturnValue().Set(EXTENSIONLESS_FORMAT_JAVASCRIPT);
}

#ifdef _WIN32
#define BufferValueToPath(str) \
std::filesystem::path(ConvertToWideString(str.ToString(), CP_UTF8))

std::string ConvertWideToUTF8(const std::wstring& wstr) {
if (wstr.empty()) return std::string();

int size_needed = WideCharToMultiByte(CP_UTF8,
0,
&wstr[0],
static_cast<int>(wstr.size()),
nullptr,
0,
nullptr,
nullptr);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8,
0,
&wstr[0],
static_cast<int>(wstr.size()),
&strTo[0],
size_needed,
nullptr,
nullptr);
return strTo;
}

#define PathToString(path) ConvertWideToUTF8(path.wstring());

#else // _WIN32

#define BufferValueToPath(str) std::filesystem::path(str.ToStringView());
#define PathToString(path) path.native();

#endif // _WIN32

static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
Environment* env = Environment::GetCurrent(args);
Isolate* isolate = env->isolate();
Expand All @@ -3223,15 +3187,15 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemRead, src.ToStringView());

auto src_path = BufferValueToPath(src);
auto src_path = src.ToPath();

BufferValue dest(isolate, args[1]);
CHECK_NOT_NULL(*dest);
ToNamespacedPath(env, &dest);
THROW_IF_INSUFFICIENT_PERMISSIONS(
env, permission::PermissionScope::kFileSystemWrite, dest.ToStringView());

auto dest_path = BufferValueToPath(dest);
auto dest_path = dest.ToPath();
bool dereference = args[2]->IsTrue();
bool recursive = args[3]->IsTrue();

Expand Down Expand Up @@ -3260,8 +3224,8 @@ static void CpSyncCheckPaths(const FunctionCallbackInfo<Value>& args) {
(src_status.type() == std::filesystem::file_type::directory) ||
(dereference && src_status.type() == std::filesystem::file_type::symlink);

auto src_path_str = PathToString(src_path);
auto dest_path_str = PathToString(dest_path);
auto src_path_str = ConvertPathToUTF8(src_path);
auto dest_path_str = ConvertPathToUTF8(dest_path);

if (!error_code) {
// Check if src and dest are identical.
Expand Down Expand Up @@ -3356,7 +3320,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
uv_fs_t req;
auto cleanup = OnScopeLeave([&req]() { uv_fs_req_cleanup(&req); });

auto src_path_str = PathToString(src);
auto src_path_str = ConvertPathToUTF8(src);
int result = uv_fs_stat(nullptr, &req, src_path_str.c_str(), nullptr);
if (is_uv_error(result)) {
env->ThrowUVException(result, "stat", nullptr, src_path_str.c_str());
Expand All @@ -3367,7 +3331,7 @@ static bool CopyUtimes(const std::filesystem::path& src,
const double source_atime = s->st_atim.tv_sec + s->st_atim.tv_nsec / 1e9;
const double source_mtime = s->st_mtim.tv_sec + s->st_mtim.tv_nsec / 1e9;

auto dest_file_path_str = PathToString(dest);
auto dest_file_path_str = ConvertPathToUTF8(dest);
int utime_result = uv_fs_utime(nullptr,
&req,
dest_file_path_str.c_str(),
Expand Down Expand Up @@ -3502,7 +3466,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
std::error_code error;
for (auto dir_entry : std::filesystem::directory_iterator(src)) {
auto dest_file_path = dest / dir_entry.path().filename();
auto dest_str = PathToString(dest);
auto dest_str = ConvertPathToUTF8(dest);

if (dir_entry.is_symlink()) {
if (verbatim_symlinks) {
Expand Down Expand Up @@ -3565,7 +3529,7 @@ static void CpSyncCopyDir(const FunctionCallbackInfo<Value>& args) {
}
} else if (std::filesystem::is_regular_file(dest_file_path)) {
if (!dereference || (!force && error_on_exist)) {
auto dest_file_path_str = PathToString(dest_file_path);
auto dest_file_path_str = ConvertPathToUTF8(dest_file_path);
env->ThrowStdErrException(
std::make_error_code(std::errc::file_exists),
"cp",
Expand Down
32 changes: 13 additions & 19 deletions src/node_modules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,22 +296,24 @@ const BindingData::PackageConfig* BindingData::TraverseParent(

// Stop the search when the process doesn't have permissions
// to walk upwards
if (is_permissions_enabled &&
!env->permission()->is_granted(
env,
permission::PermissionScope::kFileSystemRead,
current_path.generic_string())) [[unlikely]] {
return nullptr;
if (is_permissions_enabled) {
if (!env->permission()->is_granted(
env,
permission::PermissionScope::kFileSystemRead,
ConvertGenericPathToUTF8(current_path))) [[unlikely]] {
return nullptr;
}
}

// Check if the path ends with `/node_modules`
if (current_path.generic_string().ends_with("/node_modules")) {
if (current_path.filename() == "node_modules") {
return nullptr;
}

auto package_json_path = current_path / "package.json";

auto package_json =
GetPackageJSON(realm, package_json_path.string(), nullptr);
GetPackageJSON(realm, ConvertPathToUTF8(package_json_path), nullptr);
if (package_json != nullptr) {
return package_json;
}
Expand All @@ -333,20 +335,12 @@ void BindingData::GetNearestParentPackageJSONType(

ToNamespacedPath(realm->env(), &path_value);

std::string path_value_str = path_value.ToString();
auto path = path_value.ToPath();

if (slashCheck) {
path_value_str.push_back(kPathSeparator);
path /= "";
}

std::filesystem::path path;

#ifdef _WIN32
std::wstring wide_path = ConvertToWideString(path_value_str, GetACP());
path = std::filesystem::path(wide_path);
#else
path = std::filesystem::path(path_value_str);
#endif

auto package_json = TraverseParent(realm, path);

if (package_json == nullptr) {
Expand Down
60 changes: 56 additions & 4 deletions src/util-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -718,19 +718,71 @@ inline bool IsWindowsBatchFile(const char* filename) {
return !extension.empty() && (extension == "cmd" || extension == "bat");
}

inline std::wstring ConvertToWideString(const std::string& str,
UINT code_page) {
inline std::wstring ConvertUTF8ToWideString(const std::string& str) {
int size_needed = MultiByteToWideChar(
code_page, 0, &str[0], static_cast<int>(str.size()), nullptr, 0);
CP_UTF8, 0, &str[0], static_cast<int>(str.size()), nullptr, 0);
std::wstring wstrTo(size_needed, 0);
MultiByteToWideChar(code_page,
MultiByteToWideChar(CP_UTF8,
0,
&str[0],
static_cast<int>(str.size()),
&wstrTo[0],
size_needed);
return wstrTo;
}

std::string ConvertWideStringToUTF8(const std::wstring& wstr) {
if (wstr.empty()) return std::string();

int size_needed = WideCharToMultiByte(CP_UTF8,
0,
&wstr[0],
static_cast<int>(wstr.size()),
nullptr,
0,
nullptr,
nullptr);
std::string strTo(size_needed, 0);
WideCharToMultiByte(CP_UTF8,
0,
&wstr[0],
static_cast<int>(wstr.size()),
&strTo[0],
size_needed,
nullptr,
nullptr);
return strTo;
}

template <typename T, size_t kStackStorageSize>
std::filesystem::path MaybeStackBuffer<T, kStackStorageSize>::ToPath() const {
std::wstring wide_path = ConvertUTF8ToWideString(ToString());
return std::filesystem::path(wide_path);
}

std::string ConvertPathToUTF8(const std::filesystem::path& path) {
return ConvertWideStringToUTF8(path.wstring());
}

std::string ConvertGenericPathToUTF8(const std::filesystem::path& path) {
return ConvertWideStringToUTF8(path.generic_wstring());
}

#else // _WIN32

template <typename T, size_t kStackStorageSize>
std::filesystem::path MaybeStackBuffer<T, kStackStorageSize>::ToPath() const {
return std::filesystem::path(ToStringView());
}

std::string ConvertPathToUTF8(const std::filesystem::path& path) {
return path.native();
}

std::string ConvertGenericPathToUTF8(const std::filesystem::path& path) {
return path.generic_string();
}

#endif // _WIN32

inline v8::MaybeLocal<v8::Object> NewDictionaryInstance(
Expand Down
10 changes: 9 additions & 1 deletion src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,8 @@ class MaybeStackBuffer {
inline std::basic_string_view<T> ToStringView() const {
return {out(), length()};
}
// This can only be used if the buffer contains path data in UTF8
inline std::filesystem::path ToPath() const;

private:
size_t length_;
Expand Down Expand Up @@ -1038,9 +1040,15 @@ class JSONOutputStream final : public v8::OutputStream {
// Returns true if OS==Windows and filename ends in .bat or .cmd,
// case insensitive.
inline bool IsWindowsBatchFile(const char* filename);
inline std::wstring ConvertToWideString(const std::string& str, UINT code_page);
inline std::wstring ConvertUTF8ToWideString(const std::string& str);
inline std::string ConvertWideStringToUTF8(const std::wstring& wstr);

#endif // _WIN32

inline std::filesystem::path ConvertUTF8ToPath(const std::string& str);
inline std::string ConvertPathToUTF8(const std::filesystem::path& path);
inline std::string ConvertGenericPathToUTF8(const std::filesystem::path& path);

// A helper to create a new instance of the dictionary template.
// Unlike v8::DictionaryTemplate::NewInstance, this method will
// check that all properties have been set (are not empty MaybeLocals)
Expand Down
Loading