Commit 1efe967b authored by Marja Hölttä's avatar Marja Hölttä Committed by V8 LUCI CQ

[web snapshot] Support web snapshot magic when the source string is two byte

Bug: v8:11525
Change-Id: I28548c4eddcc7764be950950e16ac30b12ac8cdd
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3297890Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78061}
parent f2ceaf90
...@@ -2804,7 +2804,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl( ...@@ -2804,7 +2804,8 @@ MaybeHandle<SharedFunctionInfo> GetSharedFunctionInfoForScriptImpl(
if (V8_UNLIKELY( if (V8_UNLIKELY(
i::FLAG_experimental_web_snapshots && i::FLAG_experimental_web_snapshots &&
(source->IsExternalOneByteString() || source->IsSeqOneByteString()) && (source->IsExternalOneByteString() || source->IsSeqOneByteString() ||
source->IsExternalTwoByteString() || source->IsSeqTwoByteString()) &&
source_length > 4)) { source_length > 4)) {
// Experimental: Treat the script as a web snapshot if it starts with the // Experimental: Treat the script as a web snapshot if it starts with the
// magic byte sequence. TODO(v8:11525): Remove this once proper embedder // magic byte sequence. TODO(v8:11525): Remove this once proper embedder
......
...@@ -973,6 +973,39 @@ bool WebSnapshotDeserializer::UseWebSnapshot( ...@@ -973,6 +973,39 @@ bool WebSnapshotDeserializer::UseWebSnapshot(
deserializer_.reset( deserializer_.reset(
new ValueDeserializer(isolate_, data_copy.get(), length)); new ValueDeserializer(isolate_, data_copy.get(), length));
return Deserialize(); return Deserialize();
} else if (source->IsExternalTwoByteString()) {
// TODO(v8:11525): Implement end-to-end snapshot processing which gets rid
// of the need to copy the data here.
const v8::String::ExternalStringResource* resource =
ExternalTwoByteString::cast(*source).resource();
auto length = resource->length();
std::unique_ptr<uint8_t[]> data_copy(new uint8_t[length]);
{
DisallowGarbageCollection no_gc;
const uint16_t* data = resource->data();
uint8_t* data_copy_ptr = data_copy.get();
for (size_t i = 0; i < length; ++i) {
data_copy_ptr[i] = static_cast<uint8_t>(data[i]);
}
}
deserializer_.reset(
new ValueDeserializer(isolate_, data_copy.get(), length));
return Deserialize();
} else if (source->IsSeqTwoByteString()) {
SeqTwoByteString source_as_seq = SeqTwoByteString::cast(*source);
auto length = source_as_seq.length();
std::unique_ptr<uint8_t[]> data_copy(new uint8_t[length]);
{
DisallowGarbageCollection no_gc;
uint16_t* data = source_as_seq.GetChars(no_gc);
uint8_t* data_copy_ptr = data_copy.get();
for (int i = 0; i < length; ++i) {
data_copy_ptr[i] = static_cast<uint8_t>(data[i]);
}
}
deserializer_.reset(
new ValueDeserializer(isolate_, data_copy.get(), length));
return Deserialize();
} }
UNREACHABLE(); UNREACHABLE();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment