Skip to content

Commit

Permalink
deps: V8: backport f3cad8cec656
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
joyeecheung authored and danielleadams committed Jul 26, 2022
1 parent 5db0c8f commit 361a643
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
9 changes: 6 additions & 3 deletions deps/v8/src/api/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,6 @@ SnapshotCreator::SnapshotCreator(const intptr_t* external_references,

SnapshotCreator::~SnapshotCreator() {
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
DCHECK(data->created_);
Isolate* isolate = data->isolate_;
isolate->Exit();
isolate->Dispose();
Expand Down Expand Up @@ -590,8 +589,12 @@ StartupData SnapshotCreator::CreateBlob(
SnapshotCreator::FunctionCodeHandling function_code_handling) {
SnapshotCreatorData* data = SnapshotCreatorData::cast(data_);
i::Isolate* isolate = reinterpret_cast<i::Isolate*>(data->isolate_);
DCHECK(!data->created_);
DCHECK(!data->default_context_.IsEmpty());
Utils::ApiCheck(!data->created_, "v8::SnapshotCreator::CreateBlob",
"CreateBlob() cannot be called more than once on the same "
"SnapshotCreator.");
Utils::ApiCheck(
!data->default_context_.IsEmpty(), "v8::SnapshotCreator::CreateBlob",
"CreateBlob() cannot be called before the default context is set.");

const int num_additional_contexts = static_cast<int>(data->contexts_.Size());
const int num_contexts = num_additional_contexts + 1; // The default context.
Expand Down
25 changes: 25 additions & 0 deletions deps/v8/test/cctest/test-serialize.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2840,6 +2840,31 @@ TEST(Regress503552) {
delete cache_data;
}

UNINITIALIZED_TEST(SnapshotCreatorBlobNotCreated) {
DisableAlwaysOpt();
DisableEmbeddedBlobRefcounting();
{
v8::SnapshotCreator creator;
v8::Isolate* isolate = creator.GetIsolate();
{
v8::HandleScope handle_scope(isolate);
v8::Local<v8::Context> context = v8::Context::New(isolate);
v8::Context::Scope context_scope(context);
v8::TryCatch try_catch(isolate);
v8::Local<v8::String> code = v8_str("throw new Error('test');");
CHECK(v8::Script::Compile(context, code)
.ToLocalChecked()
->Run(context)
.IsEmpty());
CHECK(try_catch.HasCaught());
}
// SnapshotCreator should be destroyed just fine even when no
// blob is created.
}

FreeCurrentEmbeddedBlob();
}

UNINITIALIZED_TEST(SnapshotCreatorMultipleContexts) {
DisableAlwaysOpt();
DisableEmbeddedBlobRefcounting();
Expand Down

0 comments on commit 361a643

Please sign in to comment.