Skip to content

Commit

Permalink
actually fix the tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pipobscure committed Jan 9, 2024
1 parent df3d80f commit e834c70
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 8 deletions.
24 changes: 24 additions & 0 deletions src/json_parser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,30 @@ bool JSONParser::Parse(const std::string& content) {
return true;
}

bool JSONParser::HasField(std::string_view field) {
Isolate* isolate = isolate_.get();
v8::Isolate::Scope isolate_scope(isolate);
v8::HandleScope handle_scope(isolate);

Local<Context> context = context_.Get(isolate);
Context::Scope context_scope(context);

Local<Object> content_object = content_.Get(isolate);
Local<Value> value;
bool has_field;
// It's not a real script, so don't print the source line.
errors::PrinterTryCatch bootstrapCatch(
isolate, errors::PrinterTryCatch::kDontPrintSourceLine);
Local<Value> field_local;
if (!ToV8Value(context, field, isolate).ToLocal(&field_local)) {
return false;
}
if (!content_object->Has(context, field_local).To(&has_field)) {
return false;
}
return has_field;
}

std::optional<std::string> JSONParser::GetTopLevelStringField(
std::string_view field) {
Isolate* isolate = isolate_.get();
Expand Down
1 change: 1 addition & 0 deletions src/json_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class JSONParser {
JSONParser();
~JSONParser() = default;
bool Parse(const std::string& content);
bool HasField(std::string_view field);
std::optional<std::string> GetTopLevelStringField(std::string_view field);
std::optional<bool> GetTopLevelBoolField(std::string_view field);
std::optional<std::unordered_map<std::string, std::string>>
Expand Down
17 changes: 12 additions & 5 deletions src/node_sea.cc
Original file line number Diff line number Diff line change
Expand Up @@ -400,11 +400,18 @@ std::optional<SeaConfig> ParseSingleExecutableConfig(
result.flags |= SeaFlags::kUseCodeCache;
}

std::optional<std::unordered_map<std::string, std::string>> assets_opt =
parser.GetTopLevelDictOfStrings("assets");
if (assets_opt.has_value() && !assets_opt.value().empty()) {
result.flags |= SeaFlags::kIncludeAssets;
result.assets = std::move(assets_opt.value());
if (parser.HasField("assets")) {
std::optional<std::unordered_map<std::string, std::string>> assets_opt =
parser.GetTopLevelDictOfStrings("assets");
if (!assets_opt.has_value()) {
FPrintF(stderr,
"\"assets\" field of %s is not a map of strings\n",
config_path);
return std::nullopt;
} else if (!assets_opt.value().empty()) {
result.flags |= SeaFlags::kIncludeAssets;
result.assets = std::move(assets_opt.value());
}
}

return result;
Expand Down
7 changes: 4 additions & 3 deletions test/common/sea.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,18 @@ function injectAndCodeSign(targetExecutable, resource) {
}
if (signtoolFound) {
let certificatesFound = false;
let stderr;
let stderr, child;
try {
({ stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], {}));
({ child, stderr } = spawnSyncAndExitWithoutError('signtool', [ 'sign', '/fd', 'SHA256', targetExecutable ], { status: undefined }));
if (child.status !== 0) throw new Error(`- process terminated with status ${child.status}, expected 0`);
certificatesFound = true;
} catch (err) {
if (!/SignTool Error: No certificates were found that met all the given criteria/.test(stderr)) {
throw err;
}
}
if (certificatesFound) {
spawnSyncAndExitWithoutError('signtool', 'verify', '/pa', 'SHA256', targetExecutable, {});
spawnSyncAndExitWithoutError('signtool', [ 'verify', '/pa', 'SHA256', targetExecutable ], {});
}
}
}
Expand Down

0 comments on commit e834c70

Please sign in to comment.