From ccddea063b568d768b19865446d1f3812baf060c Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 8 Dec 2022 19:07:00 +0100 Subject: [PATCH] [api] mark readonly usage of StartupData as `const` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This doesn’t have much practical effect, since the actual byte contents referred to by `StartupData` are already marked `const`, but adding the qualifier communicates more clearly to users that V8 does not perform modifications on the object. Practically speaking, this also allows for cases in which the startup data is included as readonly data in the current executable without requiring a `const_cast`. Refs: https://github.com/nodejs/node/pull/45786#discussion_r1043489245 Change-Id: I53075ebb493c3617e470decb601b803f5294848d Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4089203 Reviewed-by: Michael Lippautz Commit-Queue: Michael Lippautz Cr-Commit-Position: refs/heads/main@{#84764} --- include/v8-isolate.h | 2 +- include/v8-snapshot.h | 4 ++-- src/api/api.cc | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/include/v8-isolate.h b/include/v8-isolate.h index e9f531973b..9659300751 100644 --- a/include/v8-isolate.h +++ b/include/v8-isolate.h @@ -233,7 +233,7 @@ class V8_EXPORT Isolate { * Explicitly specify a startup snapshot blob. The embedder owns the blob. * The embedder *must* ensure that the snapshot is from a trusted source. */ - StartupData* snapshot_blob = nullptr; + const StartupData* snapshot_blob = nullptr; /** * Enables the host application to provide a mechanism for recording diff --git a/include/v8-snapshot.h b/include/v8-snapshot.h index 2400357cf6..b15a2b1922 100644 --- a/include/v8-snapshot.h +++ b/include/v8-snapshot.h @@ -91,7 +91,7 @@ class V8_EXPORT SnapshotCreator { */ SnapshotCreator(Isolate* isolate, const intptr_t* external_references = nullptr, - StartupData* existing_blob = nullptr); + const StartupData* existing_blob = nullptr); /** * Create and enter an isolate, and set it up for serialization. @@ -102,7 +102,7 @@ class V8_EXPORT SnapshotCreator { * that must be equivalent to CreateParams::external_references. */ SnapshotCreator(const intptr_t* external_references = nullptr, - StartupData* existing_blob = nullptr); + const StartupData* existing_blob = nullptr); /** * Destroy the snapshot creator, and exit and dispose of the Isolate diff --git a/src/api/api.cc b/src/api/api.cc index 09217e9730..3b53d5db76 100644 --- a/src/api/api.cc +++ b/src/api/api.cc @@ -546,7 +546,7 @@ struct SnapshotCreatorData { SnapshotCreator::SnapshotCreator(Isolate* v8_isolate, const intptr_t* external_references, - StartupData* existing_snapshot) { + const StartupData* existing_snapshot) { SnapshotCreatorData* data = new SnapshotCreatorData(v8_isolate); i::Isolate* i_isolate = reinterpret_cast(v8_isolate); i_isolate->set_array_buffer_allocator(&data->allocator_); @@ -568,7 +568,7 @@ SnapshotCreator::SnapshotCreator(Isolate* v8_isolate, } SnapshotCreator::SnapshotCreator(const intptr_t* external_references, - StartupData* existing_snapshot) + const StartupData* existing_snapshot) : SnapshotCreator(Isolate::Allocate(), external_references, existing_snapshot) {}