Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bootstrap: handle snapshot errors gracefully #43531

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
fixup! fixup! bootstrap: handle snapshot errors gracefully
  • Loading branch information
joyeecheung committed Jul 14, 2022
commit b3fd174d4e46913cc6baf6a6f329cd07bcf820ef
6 changes: 2 additions & 4 deletions src/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -996,11 +996,11 @@ struct SnapshotData {
static const size_t kNodeBaseContextIndex = 0;
static const size_t kNodeMainContextIndex = kNodeBaseContextIndex + 1;

DataOwnership data_ownership;
DataOwnership data_ownership = DataOwnership::kOwned;

// The result of v8::SnapshotCreator::CreateBlob() during the snapshot
// building process.
v8::StartupData v8_snapshot_blob_data;
v8::StartupData v8_snapshot_blob_data{nullptr, 0};

std::vector<size_t> isolate_data_indices;
// TODO(joyeecheung): there should be a vector of env_info once we snapshot
Expand All @@ -1012,15 +1012,13 @@ struct SnapshotData {
// v8::ScriptCompiler::CachedData is not copyable.
std::vector<native_module::CodeCacheInfo> code_cache;

static std::unique_ptr<SnapshotData> New();
~SnapshotData();

SnapshotData(const SnapshotData&) = delete;
SnapshotData& operator=(const SnapshotData&) = delete;
SnapshotData(SnapshotData&&) = delete;
SnapshotData& operator=(SnapshotData&&) = delete;

// Only invoked by New().
SnapshotData() = default;
};

Expand Down
13 changes: 3 additions & 10 deletions src/node_snapshotable.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,6 @@ using v8::String;
using v8::TryCatch;
using v8::Value;

std::unique_ptr<SnapshotData> SnapshotData::New() {
std::unique_ptr<SnapshotData> result = std::make_unique<SnapshotData>();
result->data_ownership = DataOwnership::kOwned;
result->v8_snapshot_blob_data.data = nullptr;
return result;
}

SnapshotData::~SnapshotData() {
if (data_ownership == DataOwnership::kOwned &&
v8_snapshot_blob_data.data != nullptr) {
Expand Down Expand Up @@ -349,12 +342,12 @@ int SnapshotBuilder::Generate(SnapshotData* out,
int SnapshotBuilder::Generate(std::ostream& out,
const std::vector<std::string> args,
const std::vector<std::string> exec_args) {
std::unique_ptr<SnapshotData> data = SnapshotData::New();
int exit_code = Generate(data.get(), args, exec_args);
SnapshotData data;
int exit_code = Generate(&data, args, exec_args);
if (exit_code != 0) {
return exit_code;
}
FormatBlob(out, data.get());
FormatBlob(out, &data);
return exit_code;
}

Expand Down