fix: runtime JS error that crashes GetPackageJSON (#48293)

We overriden the `GetPackageJSON` in Node.js to let us read files
straight from the ASAR file instead of disk. The override works by
providing a JS method with the limitation that it should not throw a
runtime error. However, this invariant was accidentally violated by
`asar.splitPath` that sometimes contrary to its' TypeScript definition
returned `false`.
This commit is contained in:
Fedor Indutny
2025-09-30 09:32:13 -07:00
committed by GitHub
parent a95180e080
commit 6f9cd718c4

View File

@@ -191,13 +191,15 @@ class Archive : public node::ObjectWrap {
static void SplitPath(const v8::FunctionCallbackInfo<v8::Value>& args) {
auto* isolate = args.GetIsolate();
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
args.GetReturnValue().Set(dict.GetHandle());
base::FilePath path;
if (!gin::ConvertFromV8(isolate, args[0], &path)) {
args.GetReturnValue().Set(v8::False(isolate));
dict.Set("isAsar", false);
return;
}
auto dict = gin_helper::Dictionary::CreateEmpty(isolate);
base::FilePath asar_path, file_path;
if (asar::GetAsarArchivePath(path, &asar_path, &file_path, true)) {
dict.Set("isAsar", true);
@@ -206,7 +208,6 @@ static void SplitPath(const v8::FunctionCallbackInfo<v8::Value>& args) {
} else {
dict.Set("isAsar", false);
}
args.GetReturnValue().Set(dict.GetHandle());
}
void Initialize(v8::Local<v8::Object> exports,