Skip to content

Commit 361a643

Browse files
joyeecheungdanielleadams
authored andcommitted
deps: V8: backport f3cad8cec656
Original commit message: [serializer] allow SnapshotCreator to destruct without a blob Previously SnapshotCreator demanded a blob to be created before it can be destructed in debug build, this patch removes the DCHECK so that the embedder can choose not to create the blob when e.g. the snapshot building isn't successful due to errors. Change-Id: I72939be1e0d79b257b9761f48a72e45325a1f6d8 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3716682 Reviewed-by: Camillo Bruni <[email protected]> Commit-Queue: Joyee Cheung <[email protected]> Cr-Commit-Position: refs/heads/main@{#81644} Refs: v8/v8@f3cad8c PR-URL: #43531 Refs: #35711 Reviewed-By: Chengzhong Wu <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 5db0c8f commit 361a643

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

deps/v8/src/api/api.cc

+6-3
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ SnapshotCreator::SnapshotCreator(const intptr_t* external_references,
483483

484484
SnapshotCreator::~SnapshotCreator() {
485485
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
486-
DCHECK(data->created_);
487486
Isolate* isolate = data->isolate_;
488487
isolate->Exit();
489488
isolate->Dispose();
@@ -590,8 +589,12 @@ StartupData SnapshotCreator::CreateBlob(
590589
SnapshotCreator::FunctionCodeHandling function_code_handling) {
591590
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
592591
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
593-
DCHECK(!data->created_);
594-
DCHECK(!data->default_context_.IsEmpty());
592+
Utils::ApiCheck(!data->created_, "v8::SnapshotCreator::CreateBlob",
593+
"CreateBlob() cannot be called more than once on the same "
594+
"SnapshotCreator.");
595+
Utils::ApiCheck(
596+
!data->default_context_.IsEmpty(), "v8::SnapshotCreator::CreateBlob",
597+
"CreateBlob() cannot be called before the default context is set.");
595598

596599
const int num_additional_contexts = static_cast<int>(data->contexts_.Size());
597600
const int num_contexts = num_additional_contexts + 1; // The default context.

deps/v8/test/cctest/test-serialize.cc

+25
Original file line numberDiff line numberDiff line change
@@ -2840,6 +2840,31 @@ TEST(Regress503552) {
28402840
delete cache_data;
28412841
}
28422842

2843+
UNINITIALIZED_TEST(SnapshotCreatorBlobNotCreated) {
2844+
DisableAlwaysOpt();
2845+
DisableEmbeddedBlobRefcounting();
2846+
{
2847+
v8::SnapshotCreator creator;
2848+
v8::Isolate* isolate = creator.GetIsolate();
2849+
{
2850+
v8::HandleScope handle_scope(isolate);
2851+
v8::Local<v8::Context> context = v8::Context::New(isolate);
2852+
v8::Context::Scope context_scope(context);
2853+
v8::TryCatch try_catch(isolate);
2854+
v8::Local<v8::String> code = v8_str("throw new Error('test');");
2855+
CHECK(v8::Script::Compile(context, code)
2856+
.ToLocalChecked()
2857+
->Run(context)
2858+
.IsEmpty());
2859+
CHECK(try_catch.HasCaught());
2860+
}
2861+
// SnapshotCreator should be destroyed just fine even when no
2862+
// blob is created.
2863+
}
2864+
2865+
FreeCurrentEmbeddedBlob();
2866+
}
2867+
28432868
UNINITIALIZED_TEST(SnapshotCreatorMultipleContexts) {
28442869
DisableAlwaysOpt();
28452870
DisableEmbeddedBlobRefcounting();

0 commit comments

Comments
 (0)