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

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`.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Fedor Indutny <indutny@signal.org>
This commit is contained in:
trop[bot] 2025-10-03 19:03:18 +02:00 committed by GitHub
commit f6238586d4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

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,